Type.h revision e6f18c3e6a28229b5871007858b8c30882494b09
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
17d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer#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"
21d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer#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"
2550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h"
269fe8c74a93ac8e92512615c5f83e7a328b3b0544David Blaikie#include "llvm/Support/ErrorHandling.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"
327ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis#include "llvm/ADT/Twine.h"
339594675cc1eb52a054de13c4a21e466643847480Chris Lattner#include "clang/Basic/LLVM.h"
347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor
356b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCallnamespace clang {
366b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  enum {
37f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    TypeAlignment = 1 << TypeAlignmentInBits
396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  };
40aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class Type;
41aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class ExtQuals;
42aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  class QualType;
436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall}
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm {
464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  template <typename T>
47daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner  class PointerLikeTypeTraits;
48bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  template<>
49bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  class PointerLikeTypeTraits< ::clang::Type*> {
50bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  public:
51bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
52bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    static inline ::clang::Type *getFromVoidPointer(void *P) {
53bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner      return static_cast< ::clang::Type*>(P);
54bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner    }
556b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
56bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner  };
570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  template<>
580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  public:
600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      return static_cast< ::clang::ExtQuals*>(P);
630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
646b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
66aed1df80bf64228e1429c1edc408397f9174847cChris Lattner
67aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  template <>
68aed1df80bf64228e1429c1edc408397f9174847cChris Lattner  struct isPodLike<clang::QualType> { static const bool value = true; };
694e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}
704e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
73162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  class TypedefNameDecl;
7455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  class TemplateDecl;
7572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  class TemplateTypeParmDecl;
76aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor  class NonTypeTemplateParmDecl;
777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  class TemplateTemplateParmDecl;
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
8049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis  class CXXRecordDecl;
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
8221d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
83e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  class FunctionDecl;
84a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
85a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
86a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
87ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  class UnresolvedUsingTypenameDecl;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
89b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  class Stmt;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
9192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
9240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  class TemplateArgument;
93833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  class TemplateArgumentLoc;
94d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  class TemplateArgumentListInfo;
95465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class ElaboratedType;
963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQuals;
973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQualsTypeCommonBase;
983b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar  struct PrintingPolicy;
9972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor
100ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  template <typename> class CanQual;
101ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
102ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
10372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  // Provide forward declarations for all of the *Type classes
10472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type;
10572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
106f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
1070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Qualifiers - The collection of all-type qualifiers we support.
1080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// Clang supports five independent qualifiers:
1090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * C99: const, volatile, and restrict
1100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Embedded C (TR18037): address spaces
1110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong)
1120953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass Qualifiers {
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
1180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    CVRMask = Const | Volatile | Restrict
1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum GC {
122d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    GCNone = 0,
123d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Weak,
124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian    Strong
125d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian  };
126efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall
127f85e193739c953358c865005855253af4f68a497John McCall  enum ObjCLifetime {
128f85e193739c953358c865005855253af4f68a497John McCall    /// There is no lifetime qualification on this type.
129f85e193739c953358c865005855253af4f68a497John McCall    OCL_None,
130f85e193739c953358c865005855253af4f68a497John McCall
131f85e193739c953358c865005855253af4f68a497John McCall    /// This object can be modified without requiring retains or
132f85e193739c953358c865005855253af4f68a497John McCall    /// releases.
133f85e193739c953358c865005855253af4f68a497John McCall    OCL_ExplicitNone,
134f85e193739c953358c865005855253af4f68a497John McCall
135f85e193739c953358c865005855253af4f68a497John McCall    /// Assigning into this object requires the old value to be
136f85e193739c953358c865005855253af4f68a497John McCall    /// released and the new value to be retained.  The timing of the
137f85e193739c953358c865005855253af4f68a497John McCall    /// release of the old value is inexact: it may be moved to
138f85e193739c953358c865005855253af4f68a497John McCall    /// immediately after the last known point where the value is
139f85e193739c953358c865005855253af4f68a497John McCall    /// live.
140f85e193739c953358c865005855253af4f68a497John McCall    OCL_Strong,
141f85e193739c953358c865005855253af4f68a497John McCall
142f85e193739c953358c865005855253af4f68a497John McCall    /// Reading or writing from this object requires a barrier call.
143f85e193739c953358c865005855253af4f68a497John McCall    OCL_Weak,
144f85e193739c953358c865005855253af4f68a497John McCall
145f85e193739c953358c865005855253af4f68a497John McCall    /// Assigning into this object requires a lifetime extension.
146f85e193739c953358c865005855253af4f68a497John McCall    OCL_Autoreleasing
147f85e193739c953358c865005855253af4f68a497John McCall  };
148f85e193739c953358c865005855253af4f68a497John McCall
1490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  enum {
1500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The maximum supported address space number.
1510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// 24 bits should be enough for anyone.
1520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    MaxAddressSpace = 0xffffffu,
1530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The width of the "fast" qualifier mask.
155f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
1560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    /// The fast qualifier mask.
1580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    FastMask = (1 << FastWidth) - 1
1590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  };
1600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers() : Mask(0) {}
1620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
163e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  /// \brief Returns the common set of qualifiers while removing them from
164e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  /// the given sets.
165e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) {
166e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    // If both are only CVR-qualified, bit operations are sufficient.
167e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
168e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Qualifiers Q;
169e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.Mask = L.Mask & R.Mask;
170e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.Mask &= ~Q.Mask;
171e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.Mask &= ~Q.Mask;
172e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      return Q;
173e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
174e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
175e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    Qualifiers Q;
176e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
177e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    Q.addCVRQualifiers(CommonCRV);
178e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    L.removeCVRQualifiers(CommonCRV);
179e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    R.removeCVRQualifiers(CommonCRV);
180e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
181e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
182e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.setObjCGCAttr(L.getObjCGCAttr());
183e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.removeObjCGCAttr();
184e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.removeObjCGCAttr();
185e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
186e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
187e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (L.getObjCLifetime() == R.getObjCLifetime()) {
188e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.setObjCLifetime(L.getObjCLifetime());
189e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.removeObjCLifetime();
190e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.removeObjCLifetime();
191e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
192e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
193e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (L.getAddressSpace() == R.getAddressSpace()) {
194e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.setAddressSpace(L.getAddressSpace());
195e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.removeAddressSpace();
196e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.removeAddressSpace();
197e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
198e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    return Q;
199e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  }
200e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
2370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
2380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
2400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
2410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
2420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
2440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
2450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
2470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
2480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
2490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
2510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
2530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
2570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
2580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
2600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2742234873111009eb8655d63362cedc422eb9fc517John McCall  Qualifiers withoutObjCGCAttr() const {
2752234873111009eb8655d63362cedc422eb9fc517John McCall    Qualifiers qs = *this;
2762234873111009eb8655d63362cedc422eb9fc517John McCall    qs.removeObjCGCAttr();
2772234873111009eb8655d63362cedc422eb9fc517John McCall    return qs;
2782234873111009eb8655d63362cedc422eb9fc517John McCall  }
279200fa53fd420aa8369586f569dbece04930ad6a3John McCall  Qualifiers withoutObjCLifetime() const {
280f85e193739c953358c865005855253af4f68a497John McCall    Qualifiers qs = *this;
281f85e193739c953358c865005855253af4f68a497John McCall    qs.removeObjCLifetime();
282f85e193739c953358c865005855253af4f68a497John McCall    return qs;
283f85e193739c953358c865005855253af4f68a497John McCall  }
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
285f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
286f85e193739c953358c865005855253af4f68a497John McCall  ObjCLifetime getObjCLifetime() const {
287f85e193739c953358c865005855253af4f68a497John McCall    return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
288f85e193739c953358c865005855253af4f68a497John McCall  }
289f85e193739c953358c865005855253af4f68a497John McCall  void setObjCLifetime(ObjCLifetime type) {
290f85e193739c953358c865005855253af4f68a497John McCall    Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
291f85e193739c953358c865005855253af4f68a497John McCall  }
292f85e193739c953358c865005855253af4f68a497John McCall  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
293f85e193739c953358c865005855253af4f68a497John McCall  void addObjCLifetime(ObjCLifetime type) {
294f85e193739c953358c865005855253af4f68a497John McCall    assert(type);
295200fa53fd420aa8369586f569dbece04930ad6a3John McCall    assert(!hasObjCLifetime());
296200fa53fd420aa8369586f569dbece04930ad6a3John McCall    Mask |= (type << LifetimeShift);
297f85e193739c953358c865005855253af4f68a497John McCall  }
298f85e193739c953358c865005855253af4f68a497John McCall
299f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is neither None or ExplicitNone.
300f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
301f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
302f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime > OCL_ExplicitNone);
303f85e193739c953358c865005855253af4f68a497John McCall  }
304f85e193739c953358c865005855253af4f68a497John McCall
305f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is either strong or weak.
306f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
307f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
308f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime == OCL_Strong || lifetime == OCL_Weak);
309f85e193739c953358c865005855253af4f68a497John McCall  }
310ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
3310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
3370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
3380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
3400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
3410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
3420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
3450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
3460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
3470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
3480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
3490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
3500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
3510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
3540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
3550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
3560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
3580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
3590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
3600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
3610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
3620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
3630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
3640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
3650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
3660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
3670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
3680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
369f85e193739c953358c865005855253af4f68a497John McCall      if (Q.hasObjCLifetime())
370f85e193739c953358c865005855253af4f68a497John McCall        addObjCLifetime(Q.getObjCLifetime());
3710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
3720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
374e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  /// \brief Remove the qualifiers from the given set from this set.
375e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  void removeQualifiers(Qualifiers Q) {
376e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    // If the other set doesn't have any non-boolean qualifiers, just
377e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    // bit-and the inverse in.
378e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (!(Q.Mask & ~CVRMask))
379e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Mask &= ~Q.Mask;
380e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    else {
381e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Mask &= ~(Q.Mask & CVRMask);
382e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      if (getObjCGCAttr() == Q.getObjCGCAttr())
383e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu        removeObjCGCAttr();
384e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      if (getObjCLifetime() == Q.getObjCLifetime())
385e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu        removeObjCLifetime();
386e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      if (getAddressSpace() == Q.getAddressSpace())
387e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu        removeAddressSpace();
388e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
389e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  }
390e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
39162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Add the qualifiers from the given set to this set, given that
39262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// they don't conflict.
39362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  void addConsistentQualifiers(Qualifiers qs) {
39462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getAddressSpace() == qs.getAddressSpace() ||
39562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasAddressSpace() || !qs.hasAddressSpace());
39662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
39762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
398f85e193739c953358c865005855253af4f68a497John McCall    assert(getObjCLifetime() == qs.getObjCLifetime() ||
399f85e193739c953358c865005855253af4f68a497John McCall           !hasObjCLifetime() || !qs.hasObjCLifetime());
40062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    Mask |= qs.Mask;
40162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
40262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
40362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Determines if these qualifiers compatibly include another set.
40462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Generally this answers the question of whether an object with the other
40562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers can be safely used as an object with these qualifiers.
40662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  bool compatiblyIncludes(Qualifiers other) const {
407ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return
408377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // Address spaces must match exactly.
409377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      getAddressSpace() == other.getAddressSpace() &&
410377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // ObjC GC qualifiers can match, be added, or be removed, but can't be
411377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // changed.
412377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (getObjCGCAttr() == other.getObjCGCAttr() ||
413377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor       !hasObjCGCAttr() || !other.hasObjCGCAttr()) &&
414f85e193739c953358c865005855253af4f68a497John McCall      // ObjC lifetime qualifiers must match exactly.
415f85e193739c953358c865005855253af4f68a497John McCall      getObjCLifetime() == other.getObjCLifetime() &&
416377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // CVR qualifiers may subset.
417377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
41862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
41962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
420f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determines if these qualifiers compatibly include another set of
421f85e193739c953358c865005855253af4f68a497John McCall  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
422f85e193739c953358c865005855253af4f68a497John McCall  ///
423f85e193739c953358c865005855253af4f68a497John McCall  /// One set of Objective-C lifetime qualifiers compatibly includes the other
424ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// if the lifetime qualifiers match, or if both are non-__weak and the
425f85e193739c953358c865005855253af4f68a497John McCall  /// including set also contains the 'const' qualifier.
426f85e193739c953358c865005855253af4f68a497John McCall  bool compatiblyIncludesObjCLifetime(Qualifiers other) const {
427f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == other.getObjCLifetime())
428f85e193739c953358c865005855253af4f68a497John McCall      return true;
429ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
430f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
431f85e193739c953358c865005855253af4f68a497John McCall      return false;
432ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
433f85e193739c953358c865005855253af4f68a497John McCall    return hasConst();
434f85e193739c953358c865005855253af4f68a497John McCall  }
435ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
436769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// \brief Determine whether this set of qualifiers is a strict superset of
437769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// another set of qualifiers, not considering qualifier compatibility.
438769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  bool isStrictSupersetOf(Qualifiers Other) const;
439ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
4410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
4420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
4440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
4460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
4470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
4480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
4510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
4520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
4530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
4540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
4550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
456ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4573cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
458e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    removeQualifiers(R);
4593cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
4603cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
4610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4623cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
4633cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
4643cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
4653cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
4663cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
467ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
4697ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  std::string getAsString(const PrintingPolicy &Policy) const;
4707ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
4717ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
4727ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void print(raw_ostream &OS, const PrintingPolicy &Policy,
4737ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis             bool appendSpaceIfNonEmpty = false) const;
4740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
4760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
4770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4790953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
481f85e193739c953358c865005855253af4f68a497John McCall  // bits:     |0 1 2|3 .. 4|5  ..  7|8   ...   31|
482f85e193739c953358c865005855253af4f68a497John McCall  //           |C R V|GCAttr|Lifetime|AddressSpace|
4830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
4840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
487f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeMask = 0xE0;
488f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeShift = 5;
489f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
490f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceShift = 8;
4910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
4920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
493ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
494ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
495ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
496ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
497ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
498f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
49952fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
500414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_X86Pascal,   // __attribute__((pascal))
501414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS,       // __attribute__((pcs("aapcs")))
502414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS_VFP    // __attribute__((pcs("aapcs-vfp")))
503ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
504ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
505200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// A std::pair-like structure for storing a qualified type split
506200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// into its local qualifiers and its locally-unqualified type.
507200fa53fd420aa8369586f569dbece04930ad6a3John McCallstruct SplitQualType {
508200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// The locally-unqualified type.
509200fa53fd420aa8369586f569dbece04930ad6a3John McCall  const Type *Ty;
510200fa53fd420aa8369586f569dbece04930ad6a3John McCall
511200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// The local qualifiers.
512200fa53fd420aa8369586f569dbece04930ad6a3John McCall  Qualifiers Quals;
513200fa53fd420aa8369586f569dbece04930ad6a3John McCall
514200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType() : Ty(0), Quals() {}
515200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
516200fa53fd420aa8369586f569dbece04930ad6a3John McCall
517200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType getSingleStepDesugaredType() const; // end of this file
518200fa53fd420aa8369586f569dbece04930ad6a3John McCall
519200fa53fd420aa8369586f569dbece04930ad6a3John McCall  // Make llvm::tie work.
520200fa53fd420aa8369586f569dbece04930ad6a3John McCall  operator std::pair<const Type *,Qualifiers>() const {
521200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return std::pair<const Type *,Qualifiers>(Ty, Quals);
522200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
523200fa53fd420aa8369586f569dbece04930ad6a3John McCall
524200fa53fd420aa8369586f569dbece04930ad6a3John McCall  friend bool operator==(SplitQualType a, SplitQualType b) {
525200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return a.Ty == b.Ty && a.Quals == b.Quals;
526200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
527200fa53fd420aa8369586f569dbece04930ad6a3John McCall  friend bool operator!=(SplitQualType a, SplitQualType b) {
528200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return a.Ty != b.Ty || a.Quals != b.Quals;
529200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
530200fa53fd420aa8369586f569dbece04930ad6a3John McCall};
5310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
5330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
5340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
5350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
5360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
5370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
5380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
5390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
5410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
5420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
5430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
5440953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
5450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
5460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
5470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
5480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
5500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
5510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
5540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
5550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQualsTypeCommonBase *getCommonPtr() const {
5583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!isNull() && "Cannot retrieve a NULL type pointer");
5593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    uintptr_t CommonPtrVal
5603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
5613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
5623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
5633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
5643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
5650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
5660953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
5675cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
5681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5695cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
5700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
5710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
5720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
5730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
574a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
5781ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
5791ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
5801ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
5813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtr() const;
582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtrOrNull() const;
5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5854d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain  /// Retrieves a pointer to the name of the base type.
5864d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain  const IdentifierInfo *getBaseTypeIdentifier() const;
5874d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain
58849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
58949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
5903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  SplitQualType split() const;
59149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
5925cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
593f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  static QualType getFromOpaquePtr(const void *Ptr) {
5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
595f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
599f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type &operator*() const {
6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
603f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *operator->() const {
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
607467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
60854e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
609467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
6120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether this particular QualType instance has the
616a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
617a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
618a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
619a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
6200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
621ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
622a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
623fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
625ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether this particular QualType instance has the
626a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
627a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
628a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
629a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
630a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
631ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
632a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
633fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
634ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
635ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether this particular QualType instance has the
636a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
637a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
638a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
639f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
642a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
643fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
645a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
646ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// qualifiers, without looking through any typedefs that might add
647a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
648a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
649a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
6500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
652a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
653fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
654ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
655a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
656a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
657a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
658a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
659a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
6600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
662a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
663a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
664a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
6653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getLocalQualifiers() const;
6660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
667a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
668fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
670ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
671a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
672a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
673a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
674f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
676b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
677ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
678a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
679fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
680e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
681bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
682bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
683bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
6841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
685f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
686f85e193739c953358c865005855253af4f68a497John McCall  bool isPODType(ASTContext &Context) const;
687f85e193739c953358c865005855253af4f68a497John McCall
688152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// isCXX98PODType() - Return true if this is a POD type according to the
689152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// rules of the C++98 standard, regardless of the current compilation's
690152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// language.
691152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  bool isCXX98PODType(ASTContext &Context) const;
692152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer
693f85e193739c953358c865005855253af4f68a497John McCall  /// isCXX11PODType() - Return true if this is a POD type according to the
694f85e193739c953358c865005855253af4f68a497John McCall  /// more relaxed rules of the C++11 standard, regardless of the current
695f85e193739c953358c865005855253af4f68a497John McCall  /// compilation's language.
696f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
697f85e193739c953358c865005855253af4f68a497John McCall  bool isCXX11PODType(ASTContext &Context) const;
698ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
699f85e193739c953358c865005855253af4f68a497John McCall  /// isTrivialType - Return true if this is a trivial type
700f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
701ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isTrivialType(ASTContext &Context) const;
702f85e193739c953358c865005855253af4f68a497John McCall
703f85e193739c953358c865005855253af4f68a497John McCall  /// isTriviallyCopyableType - Return true if this is a trivially
704f85e193739c953358c865005855253af4f68a497John McCall  /// copyable type (C++0x [basic.types]p9)
705f85e193739c953358c865005855253af4f68a497John McCall  bool isTriviallyCopyableType(ASTContext &Context) const;
706f85e193739c953358c865005855253af4f68a497John McCall
7070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
7080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
7090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// addConst - add the specified type qualifier to this QualType.
7110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
7120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
7130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
7150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
7160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
718ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// addVolatile - add the specified type qualifier to this QualType.
719308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  void addVolatile() {
720308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    addFastQualifiers(Qualifiers::Volatile);
721308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
722308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  QualType withVolatile() const {
723308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    return withFastQualifiers(Qualifiers::Volatile);
724308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
72518932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek
72618932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  /// Add the restrict qualifier to this QualType.
72718932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  void addRestrict() {
72818932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek    addFastQualifiers(Qualifiers::Restrict);
72918932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  }
73018932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  QualType withRestrict() const {
73118932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek    return withFastQualifiers(Qualifiers::Restrict);
73218932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  }
733308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt
734a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  QualType withCVRQualifiers(unsigned CVR) const {
735a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall    return withFastQualifiers(CVR);
736a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  }
737a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall
7380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
7390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
7400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
7410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
7420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
74449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
74549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
74649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
74749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
7480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
74949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
75049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
7510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
7520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
7530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
7560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
7570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
7580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
7590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
7600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
7610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7621c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
7630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
7640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
76549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
76649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
7690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
77049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
7710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
77249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
7730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
774c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
775971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
7763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType getCanonicalType() const;
7773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
778a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
779a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
780a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
781a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
7821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
78362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Retrieve the unqualified variant of the given type,
78462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// removing as little sugar as possible.
78562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
78662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// This routine looks through various kinds of sugar to find the
78762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// least-desugared type that is unqualified. For example, given:
78862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
78962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \code
79062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef int Integer;
79162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef const Integer CInteger;
79262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef CInteger DifferenceType;
79362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \endcode
79462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
79562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
79662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
79762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
79862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
79962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
80062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
80162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline QualType getUnqualifiedType() const;
80262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
80362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
80462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// given type, removing as little sugar as possible.
80562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
80662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Like getUnqualifiedType(), but also returns the set of
80762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers that were built up.
80862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
80962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
81062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
81162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
81262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline SplitQualType getSplitUnqualifiedType() const;
813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
81461d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is more qualified than the other
81561d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
816e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
81761d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
81861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is at least as qualified as the other
81961d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
820e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
821ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
822e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8246398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
8256398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
826ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ///
8276398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
8286398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
829ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// an lvalue. It removes a top-level reference (since there are no
8305291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
8315291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
8326398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
833ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8342fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
8352fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
8362fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
8372fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
8382fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
8392fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
8400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
8410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
8424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getDesugaredType(const ASTContext &Context) const {
84349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
84449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
84549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
84649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
84749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
848bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
84998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
850f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// \brief Return the specified type with one level of "sugar" removed from
851ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// the type.
852f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  ///
853f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// This routine takes off the first typedef, typeof, etc. If the outer level
854f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// of the type is already concrete, it returns it unmodified.
855200fa53fd420aa8369586f569dbece04930ad6a3John McCall  QualType getSingleStepDesugaredType(const ASTContext &Context) const {
856200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getSingleStepDesugaredTypeImpl(*this, Context);
857200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
858ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
859075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
860075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
861075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
862723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
863723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
864723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
865075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
866075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
86950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
87050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
87250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
87350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
87549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
87649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
87749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
87849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
879200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getAsString(split.Ty, split.Quals);
88049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
88149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
882d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
8837ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  std::string getAsString(const PrintingPolicy &Policy) const;
8847ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
8857ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void print(raw_ostream &OS, const PrintingPolicy &Policy,
8867ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis             const Twine &PlaceHolder = Twine()) const {
8877ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    print(split(), OS, Policy, PlaceHolder);
8887ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  }
8897ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void print(SplitQualType split, raw_ostream &OS,
8907ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                    const PrintingPolicy &policy, const Twine &PlaceHolder) {
8917ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    return print(split.Ty, split.Quals, OS, policy, PlaceHolder);
8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8937ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void print(const Type *ty, Qualifiers qs,
8947ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                    raw_ostream &OS, const PrintingPolicy &policy,
8957ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                    const Twine &PlaceHolder);
8967ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
897e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
89849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
89949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
90049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
90149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
90249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
903200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getAsStringInternal(split.Ty, split.Quals, out, policy);
90449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
90549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
90649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
90749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9097ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  class StreamedQualTypeHelper {
9107ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    const QualType &T;
9117ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    const PrintingPolicy &Policy;
9127ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    const Twine &PlaceHolder;
9137ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  public:
9147ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy,
9157ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                           const Twine &PlaceHolder)
9167ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis      : T(T), Policy(Policy), PlaceHolder(PlaceHolder) { }
9177ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
9187ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    friend raw_ostream &operator<<(raw_ostream &OS,
9197ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                   const StreamedQualTypeHelper &SQT) {
9207ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis      SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder);
9217ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis      return OS;
9227ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    }
9237ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  };
9247ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
9257ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  StreamedQualTypeHelper stream(const PrintingPolicy &Policy,
9267ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                const Twine &PlaceHolder = Twine()) const {
9277ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    return StreamedQualTypeHelper(*this, Policy, PlaceHolder);
9287ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  }
9297ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
930c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
931c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9333f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
9343f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
9353f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
937ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
938ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
9391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
940f85e193739c953358c865005855253af4f68a497John McCall  /// getObjCGCAttr - Returns gc attribute of this type.
9410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
942f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
943f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
944f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
9450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
946f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
947f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
948f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
949f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
9500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
951f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
9522455636163fdd18581d7fdae816433f886d88213Mike Stump
953f85e193739c953358c865005855253af4f68a497John McCall  /// getObjCLifetime - Returns lifetime attribute of this type.
954f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCLifetime() const {
955f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().getObjCLifetime();
956f85e193739c953358c865005855253af4f68a497John McCall  }
957f85e193739c953358c865005855253af4f68a497John McCall
958f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
959f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().hasNonTrivialObjCLifetime();
960f85e193739c953358c865005855253af4f68a497John McCall  }
961f85e193739c953358c865005855253af4f68a497John McCall
962f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
963f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().hasStrongOrWeakObjCLifetime();
964f85e193739c953358c865005855253af4f68a497John McCall  }
965f85e193739c953358c865005855253af4f68a497John McCall
9660d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  enum DestructionKind {
9670d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_none,
968f85e193739c953358c865005855253af4f68a497John McCall    DK_cxx_destructor,
969f85e193739c953358c865005855253af4f68a497John McCall    DK_objc_strong_lifetime,
970f85e193739c953358c865005855253af4f68a497John McCall    DK_objc_weak_lifetime
9710d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  };
9720d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
9730d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// isDestructedType - nonzero if objects of this type require
9740d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// non-trivial work to clean up after.  Non-zero because it's
9750d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// conceivable that qualifiers (objc_gc(weak)?) could make
9760d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// something require destruction.
9770d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  DestructionKind isDestructedType() const {
9780d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    return isDestructedTypeImpl(*this);
9790d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  }
9800d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
981ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether expressions of the given type are forbidden
9822b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// from being lvalues in C.
9832b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///
9842b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// The expression types that are forbidden to be lvalues are:
9852b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   - 'void', but not qualified void
9862b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   - function types
9872b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///
9882b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// The exact rule here is C99 6.3.2.1:
9892b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   An lvalue is an expression with an object type or an incomplete
9902b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   type other than void.
9912b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  bool isCForbiddenLValueType() const;
9922b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
99385ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl  /// \brief Determine whether this type has trivial copy/move-assignment
99485ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl  ///        semantics.
99585ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl  bool hasTrivialAssignment(ASTContext &Context, bool Copying) const;
996ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
997bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
998bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
999bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
1000bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
1001bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
10024ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static QualType getDesugaredType(QualType T, const ASTContext &Context);
100349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
100462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1005200fa53fd420aa8369586f569dbece04930ad6a3John McCall  static QualType getSingleStepDesugaredTypeImpl(QualType type,
1006200fa53fd420aa8369586f569dbece04930ad6a3John McCall                                                 const ASTContext &C);
1007075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
10080d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  static DestructionKind isDestructedTypeImpl(QualType type);
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
1017f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  typedef const ::clang::Type *SimpleType;
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
10194472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10254e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
10264e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
1027daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
10284e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
10294e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
10304e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
10314e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
10324e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
10334e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
10344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
10350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
10360eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
10374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
10381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
103973af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1043ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Base class that is common to both the \c ExtQuals and \c Type
10443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the
10453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two.
10463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
10473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase {
10483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
10493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : BaseType(baseType), CanonicalType(canon) {}
10503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
10523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// a self-referential pointer (for \c Type).
10533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ///
1054ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This pointer allows an efficient mapping from a QualType to its
10553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// underlying type pointer.
10563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *const BaseType;
10573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The canonical type of this type.  A QualType.
10593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType CanonicalType;
10603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class QualType;
10623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class Type;
10633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class ExtQuals;
10643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
1065ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a
10673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want
10683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type.  Therefore we have this
10693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to
10703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers.
10713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
1072ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
10733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether
10743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
10753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare.
10763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
10773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // NOTE: changing the fast qualifiers should be straightforward as
10783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // long as you don't make 'const' non-fast.
10793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 1. Qualifiers:
10803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
10813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       Fast qualifiers must occupy the low-order bits.
10823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update Qualifiers::FastWidth and FastMask.
10833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 2. QualType:
10843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
10853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
10863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       this header.
10873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 3. ASTContext:
10883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update get{Volatile,Restrict}Type.
10893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Quals - the immutable set of qualifiers applied by this
10913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// node;  always contains extended qualifiers.
10923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
10933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals *this_() { return this; }
10953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
1097ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
10983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(baseType,
10993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon),
11003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      Quals(quals)
11013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  {
11023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(Quals.hasNonFastQualifiers()
11033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with no fast qualifiers");
11043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers()
11053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with fast qualifiers");
11063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
11073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
11083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getQualifiers() const { return Quals; }
11093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
11103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
11113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
11123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1113f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1114f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCLifetime() const {
1115f85e193739c953358c865005855253af4f68a497John McCall    return Quals.getObjCLifetime();
1116f85e193739c953358c865005855253af4f68a497John McCall  }
1117f85e193739c953358c865005855253af4f68a497John McCall
11183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
11193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
11203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
11213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getBaseType() const { return BaseType; }
11223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
11233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
11243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
11253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Profile(ID, getBaseType(), Quals);
11263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
11273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
11283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      const Type *BaseType,
11293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      Qualifiers Quals) {
11303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
11313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    ID.AddPointer(BaseType);
11323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals.Profile(ID);
11333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
11343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
11353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1136ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief The kind of C++0x ref-qualifier associated with a function type,
1137ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// which determines whether a member function's "this" object can be an
1138c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither.
1139c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind {
1140c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief No ref-qualifier was provided.
1141c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_None = 0,
1142c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An lvalue ref-qualifier was provided (\c &).
1143c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_LValue,
1144c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An rvalue ref-qualifier was provided (\c &&).
1145c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_RValue
1146c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor};
1147ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
11525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
115972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
116272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11731ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
117672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
117727935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
117872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
117972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
118072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
11821bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1184c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
1185c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
1186c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
1187b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
1188b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
1189b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
1190b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
119127935ee59c30b0d8b610ab676aab8e65350af932John McCall
1192b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1193b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
1194b870b88df784c2940efce448ebfaf54dece14666John McCall
1195b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
1196bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
1197ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1198ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    /// \brief Whether this type somehow involves a template parameter, even
1199561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    /// if the resolution of the type does not depend on a template parameter.
1200561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
1201ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1202b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1203bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
1204d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1205d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
1206d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
1207d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1208ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12091fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
12101fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
12111fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
12121fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
1213ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1214093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    /// \brief True if the visibility was set explicitly in the source code.
1215093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    mutable unsigned CachedExplicitVisibility : 1;
1216093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola
1217b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
1218b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
121907a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1220ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    /// \brief Whether this type involves and local or unnamed types.
1221bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
1222ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1223b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
1224bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
1225b870b88df784c2940efce448ebfaf54dece14666John McCall
12261fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
12271fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
12281fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
12291fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
12301fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
12311fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
12321fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
1233093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    bool isVisibilityExplicit() const {
1234093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola      assert(isCacheValid() && "getting linkage from invalid cache");
1235093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola      return CachedExplicitVisibility;
1236093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    }
12371fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
12381fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
12391fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
12401fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
12411fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
12421fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
12431fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
12441fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
1245b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1246093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola  enum { NumTypeBits = 19 };
1247b870b88df784c2940efce448ebfaf54dece14666John McCall
1248b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
1249b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
1250b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
1251b870b88df784c2940efce448ebfaf54dece14666John McCall
1252b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
1253b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
1254b870b88df784c2940efce448ebfaf54dece14666John McCall
1255b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1256b870b88df784c2940efce448ebfaf54dece14666John McCall
1257b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
1258b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
1259b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
1260b870b88df784c2940efce448ebfaf54dece14666John McCall
1261b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
1262b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
1263b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
1264b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
1265b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1266b870b88df784c2940efce448ebfaf54dece14666John McCall
1267b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
1268b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
1269b870b88df784c2940efce448ebfaf54dece14666John McCall
1270b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1271b870b88df784c2940efce448ebfaf54dece14666John McCall
1272b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
1273b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
1274b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1275b870b88df784c2940efce448ebfaf54dece14666John McCall
1276b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
1277b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
1278b870b88df784c2940efce448ebfaf54dece14666John McCall
1279b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1280b870b88df784c2940efce448ebfaf54dece14666John McCall
1281b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
1282b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
12837e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    unsigned ExtInfo : 8;
1284b870b88df784c2940efce448ebfaf54dece14666John McCall
1285b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1286b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
1287b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
1288b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1289b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
1290b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
1291b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
1292ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1293c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// \brief The ref-qualifier associated with a \c FunctionProtoType.
1294c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    ///
1295c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// This is a value of type \c RefQualifierKind.
1296c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    unsigned RefQualifier : 2;
1297b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1298b870b88df784c2940efce448ebfaf54dece14666John McCall
1299b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
1300b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
1301b870b88df784c2940efce448ebfaf54dece14666John McCall
1302b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1303b870b88df784c2940efce448ebfaf54dece14666John McCall
1304b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
1305b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
1306b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
1307b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1308b870b88df784c2940efce448ebfaf54dece14666John McCall
1309b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
1310b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
1311b870b88df784c2940efce448ebfaf54dece14666John McCall
1312b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1313b870b88df784c2940efce448ebfaf54dece14666John McCall
1314b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
1315b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
1316b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
1317b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
1318b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1319b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
1320b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
1321b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1322b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
1323b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1324b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
1325bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
1326b870b88df784c2940efce448ebfaf54dece14666John McCall
1327b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
1328b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
1329bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
1330b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1331b870b88df784c2940efce448ebfaf54dece14666John McCall
133277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
133377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
133477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
133577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
133677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
133777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
133877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
133977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
134077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
1341b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
1342b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
134307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1344b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
134571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
1346e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
1347e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
1348cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
1349b870b88df784c2940efce448ebfaf54dece14666John McCall
1350b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
1351cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
1352b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1353b870b88df784c2940efce448ebfaf54dece14666John McCall
13549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  class AttributedTypeBitfields {
13559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    friend class AttributedType;
13569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
13579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned : NumTypeBits;
13589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
13599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// AttrKind - an AttributedType::Kind
13609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned AttrKind : 32 - NumTypeBits;
13619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
13629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
1363b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
1364b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
1365b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
13669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBitfields AttributedTypeBits;
1367b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
1368b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1369b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1370b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
137177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1372b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1373b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1374b870b88df784c2940efce448ebfaf54dece14666John McCall
1375b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
13763c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
1377ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setFromAST(bool V = true) const {
1378b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
137907a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
138007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1381b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
13821fb0caaa7bef765b85972274e3b434af2572c141John McCall
13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1384124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1385124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
1386ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Type(TypeClass tc, QualType canon, bool Dependent,
1387561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor       bool InstantiationDependent, bool VariablyModified,
1388d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
13893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(this,
13903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon) {
1391b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1392b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1393561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1394b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1395d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
13961fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1397093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    TypeBits.CachedExplicitVisibility = false;
1398b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1399b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1400b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1401b870b88df784c2940efce448ebfaf54dece14666John McCall  }
14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
14031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1404ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setDependent(bool D = true) {
1405ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    TypeBits.Dependent = D;
1406561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    if (D)
1407561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor      TypeBits.InstantiationDependent = true;
1408561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1409ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setInstantiationDependent(bool D = true) {
1410561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    TypeBits.InstantiationDependent = D; }
1411ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM;
1412561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1413d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1414d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1415d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1416d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
14178b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1418b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
14191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14203c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1421b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
142207a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1423d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1424d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1425d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1426d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1427d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1428d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1429d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1430d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1431d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1432d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1433d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1434d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1435d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1436d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1437ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Note that this routine does not specify which
1438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool containsUnexpandedParameterPack() const {
1439d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1440d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1441d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
14423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Determines if this type would be canonical if it had no further
14433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualification.
1444467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
14453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return CanonicalType == QualType(this, 0);
1446467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1448200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// Pull a single level of sugar off of this locally-unqualified type.
1449200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1450200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1451200fa53fd420aa8369586f569dbece04930ad6a3John McCall  QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
1452200fa53fd420aa8369586f569dbece04930ad6a3John McCall
14531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
14591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
1460d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  ///
1461d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  /// \brief Def If non-NULL, and the type refers to some kind of declaration
1462d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  /// that can be completed (such as a C struct, C++ class, or Objective-C
1463d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  /// class), will be set to the declaration.
1464d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  bool isIncompleteType(NamedDecl **Def = 0) const;
1465d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1466d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1467d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1468d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1469d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1470d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
1471ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14722fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  /// \brief Determine whether this type is an object type.
14732fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  bool isObjectType() const {
14742fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    // C++ [basic.types]p8:
1475ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    //   An object type is a (possibly cv-qualified) type that is not a
14762fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   function type, not a reference type, and not a void type.
14772fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    return !isReferenceType() && !isFunctionType() && !isVoidType();
14782fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  }
147964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1480ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1481ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1482ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1483ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
1484636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// \brief Test if this type is a standard-layout type.
1485636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// (C++0x [basic.type]p9)
1486636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  bool isStandardLayoutType() const;
1487636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth
14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1489ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1490e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
14919b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
14929b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
14939b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1494e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1495e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14972a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
14982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
14992a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
15002a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
15012a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
1502a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  const BuiltinType *getAsPlaceholderType() const;
15032a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1504864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// isSpecificPlaceholderType - Test for a specific placeholder type.
1505864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  bool isSpecificPlaceholderType(unsigned K) const;
1506864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
150732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// isNonOverloadPlaceholderType - Test for a placeholder type
150832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// other than Overload;  see BuiltinType::isNonOverloadPlaceholderType.
150932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  bool isNonOverloadPlaceholderType() const;
151032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall
151196d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
151296d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
15135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
151413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
151513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
151613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
151777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
15185cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isChar16Type() const;
15195cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isChar32Type() const;
152020093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
15219d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
1522ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15232ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
15242ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
15251274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
15261274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
15271274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
1528ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
15305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
153102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
153202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
15335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1534f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
15355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
1536aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  bool isHalfType() const;         // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
15375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
15385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1539c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1540c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1541c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1542d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
1543aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isFundamentalType() const;
1544aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isCompoundType() const;
15451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1546c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1547ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1548c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1549183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1550183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1551befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
155258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
15535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
15547154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1555a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
15567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
15577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1558bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1559f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1560f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1561db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1562c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1563c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1564c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1565c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1566898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1567c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
15691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
15706666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  bool isInterfaceType() const;
1571fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
15724cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1573368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1574368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1575213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1576f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCObjectPointerType() const;         // pointer to ObjC object
1577f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCRetainableType() const;            // ObjC object or block pointer
1578f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCLifetimeType() const;              // (array of)* retainable type
1579f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCIndirectLifetimeType() const;      // (pointer to)* lifetime type
1580f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCNSObjectType() const;              // __attribute__((NSObject))
158114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
158214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1583c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1584368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1585368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1586470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1587569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
158814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
158914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
159013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1591de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
1592f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCARCBridgableType() const;
1593f85e193739c953358c865005855253af4f68a497John McCall  bool isCARCBridgableType() const;
159472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
15956e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1596ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer  bool isAtomicType() const;                    // C11 _Atomic()
1597898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1598f85e193739c953358c865005855253af4f68a497John McCall  /// Determines if this type, which must satisfy
1599f85e193739c953358c865005855253af4f68a497John McCall  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
1600f85e193739c953358c865005855253af4f68a497John McCall  /// than implicitly __strong.
1601f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCARCImplicitlyUnretainedType() const;
1602f85e193739c953358c865005855253af4f68a497John McCall
1603f85e193739c953358c865005855253af4f68a497John McCall  /// Return the implicit lifetime for this type, which must not be dependent.
1604f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
1605f85e193739c953358c865005855253af4f68a497John McCall
1606daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
16071d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall    STK_CPointer,
16081d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall    STK_BlockPointer,
16091d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall    STK_ObjCObjectPointer,
1610daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1611daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1612daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1613daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1614daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1615daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1616daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1617daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1618daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1619daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1620898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1622898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1623b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
1624ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1625561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \brief Determine whether this type is an instantiation-dependent type,
1626561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// meaning that the type involves a template parameter (even if the
1627561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// definition does not actually depend on the type substituted for that
1628561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// template parameter).
1629ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isInstantiationDependentType() const {
1630ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return TypeBits.InstantiationDependent;
1631561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1632ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
163335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1634b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
16353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
16363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief Whether this type involves a variable-length array type
16373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with a definite size.
16383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasSizedVLAType() const;
1639ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1640db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1641db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1642ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1643063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
164472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
16454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
16464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
1647bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth
1648bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth  bool canDecayToPointerType() const;
1649ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16508958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
16518958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
16528958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
16536e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
16548958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
16558958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1656820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1657820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1659820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1660f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1661f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1662f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1663f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1664f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1665f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1666f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1667f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1668f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1669f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1670f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1671f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
16728eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
16738eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
16748eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1675f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1676c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1677f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1678f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1679769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1680898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1681c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
16824cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
168314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
168414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
168514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
168614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1687759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
1688c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1689a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1691c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1692ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// because the type is a RecordType or because it is the injected-class-name
1693c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1694c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
169534b41d939a1328f484511c6002ba2456db879a29Richard Smith
169634b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Get the AutoType whose type will be deduced for a variable with
169734b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// an initializer of this type. This looks through declarators like pointer
169834b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// types, but not through decltype or typedefs.
169934b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType *getContainedAutoType() const;
1700ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1701d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template getAs<specific type>'.  Look through sugar for
1702222bc3c25b12fc0cf55175975dc4c25d7e1fac78James Dennett  /// an instance of \<specific type>.   This scheme will eventually
1703d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// replace the specific getAsXXXX methods above.
1704d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1705d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// There are some specializations of this member template listed
1706d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// immediately following this class.
17071a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// A variant of getAs<> for array types which silently discards
17103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualifiers from the outermost type.
17113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ArrayType *getAsArrayTypeUnsafe() const;
17123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1713d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template castAs<specific type>.  Look through sugar for
171486290333420dea36e41afb664884fc45ac7677a8James Dennett  /// the underlying instance of \<specific type>.
1715d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1716d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// This method has the same relationship to getAs<T> as cast<T> has
1717d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// to dyn_cast<T>; which is to say, the underlying type *must*
1718d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// have the intended type, and this method will never return null.
1719d0370f59e79702ac908c81bf556519f91e9ca297John McCall  template <typename T> const T *castAs() const;
1720d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1721d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// A variant of castAs<> for array type which silently discards
1722d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// qualifiers from the outermost type.
1723d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const ArrayType *castAsArrayTypeUnsafe() const;
1724d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1725d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// getBaseElementTypeUnsafe - Get the base element type of this
1726d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// type, potentially discarding type qualifiers.  This method
1727d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// should never be used when type qualifiers are meaningful.
1728d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *getBaseElementTypeUnsafe() const;
1729d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1730c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1731c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1732c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1733c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1735f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1736f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
173714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
17381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1739bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1740bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1741bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1742bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
17445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
17455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
17465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1748d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
17495f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// or an enum decl which has a signed representation.
17505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
17515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
17545f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// or an enum decl which has an unsigned representation.
17555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1756d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
1757ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Determines whether this is an integer type that is signed or an
1758575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// enumeration types whose underlying type is a signed integer type.
1759575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  bool isSignedIntegerOrEnumerationType() const;
1760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1761ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Determines whether this is an integer type that is unsigned or an
1762575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// enumeration types whose underlying type is a unsigned integer type.
1763575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  bool isUnsignedIntegerOrEnumerationType() const;
1764575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor
17655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
17669bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
17679bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
17683c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1769c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
177022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
177122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
177222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
177322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
17740b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
177560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
17761fb0caaa7bef765b85972274e3b434af2572c141John McCall
17771fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
17781fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
17791fb0caaa7bef765b85972274e3b434af2572c141John McCall
1780093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola  /// \brief Return true if the visibility was explicitly set is the code.
1781093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola  bool isVisibilityExplicit() const;
1782093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola
17831fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
17841fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
1785ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
178660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
178760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
1788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
178960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
17900b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1791ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1792ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1793ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1794ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1795b5f2c419842d016892b9c976d4d6e91880e0e43aArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
1796f85e193739c953358c865005855253af4f68a497John McCall
17975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1798be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1799c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1800a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
18015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18032df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis/// \brief This will check for a TypedefType by removing any existing sugar
18042df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidis/// until it reaches a TypedefType or a non-sugared type.
18052df1a5819fd98708ff3b4772f3477f6c1a8da59aArgyrios Kyrtzidistemplate <> const TypedefType *Type::getAs() const;
1806183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1807183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1808183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1809183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1810183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1811183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
18120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1813d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \
1814d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \
1815d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<Class##Type>(CanonicalType); \
1816183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1817183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1818183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1819183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
18215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
18225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
18235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
1825e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define BUILTIN_TYPE(Id, SingletonId) Id,
1826e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define LAST_BUILTIN_TYPE(Id) LastKind = Id
1827e0a22d06888c13989b3f72db319f1d498bf69153John McCall#include "clang/AST/BuiltinTypes.def"
18285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
182971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
18305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
183235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1833561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/(K == Dependent),
1834d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1835d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1836b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
183771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1839b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
184027a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis  StringRef getName(const PrintingPolicy &Policy) const;
184127a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis  const char *getNameAsCString(const PrintingPolicy &Policy) const {
184227a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    // The StringRef is null-terminated.
184327a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    StringRef str = getName(Policy);
184427a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    assert(!str.empty() && str.data()[str.size()] == '\0');
184527a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    return str.data();
184627a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis  }
18471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1848bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1849bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1850bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1851680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
185271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1853680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1854680523a91dd3351389667c8de17121ba7ae82673John McCall
1855680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
185671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1857680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1858680523a91dd3351389667c8de17121ba7ae82673John McCall
1859680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
186071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1861680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1862680523a91dd3351389667c8de17121ba7ae82673John McCall
1863680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
1864aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov    return getKind() >= Half && getKind() <= LongDouble;
1865680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1866680523a91dd3351389667c8de17121ba7ae82673John McCall
186785def357129b6cdfd69a66ad0e6994506418a2a9John McCall  /// Determines whether the given kind corresponds to a placeholder type.
186885def357129b6cdfd69a66ad0e6994506418a2a9John McCall  static bool isPlaceholderTypeKind(Kind K) {
186985def357129b6cdfd69a66ad0e6994506418a2a9John McCall    return K >= Overload;
187085def357129b6cdfd69a66ad0e6994506418a2a9John McCall  }
187185def357129b6cdfd69a66ad0e6994506418a2a9John McCall
1872864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// Determines whether this type is a placeholder type, i.e. a type
1873864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// which cannot appear in arbitrary positions in a fully-formed
1874864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// expression.
18752a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
187685def357129b6cdfd69a66ad0e6994506418a2a9John McCall    return isPlaceholderTypeKind(getKind());
18772a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
18782a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
187932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// Determines whether this type is a placeholder type other than
188032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// Overload.  Most placeholder types require only syntactic
188132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// information about their context in order to be resolved (e.g.
188232509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// whether it is a call expression), which means they can (and
188332509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// should) be resolved in an earlier "phase" of analysis.
188432509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// Overload expressions sometimes pick up further information
188532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// from their context, like whether the context expects a
188632509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// specific function-pointer type, and so frequently need
188732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// special treatment.
188832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  bool isNonOverloadPlaceholderType() const {
188932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall    return getKind() > Overload;
189032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  }
189132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall
18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
18935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
18945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
18975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
18985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
18995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
19005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
19015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
190235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1903561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Element->isInstantiationDependentType(),
1904d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1905d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1906898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
19075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
190960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
19105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1913bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1914bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1915bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
19175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
19185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
19245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
19255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1927075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1928075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1929075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1930075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1931075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1932075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1933075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1934561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         InnerType->isInstantiationDependentType(),
1935d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1936d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1937075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1938075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1939075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1940075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1941075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1942075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1943075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1944075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1945075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1946075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1947075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1948075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1949075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1950075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1951075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1952075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1953075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1954075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1955075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1956075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1957075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1958075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
195968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1960bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
196168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1962bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
19635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
196535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1966561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Pointee->isInstantiationDependentType(),
1967d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1968ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         Pointee->containsUnexpandedParameterPack()),
196935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
19705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
197260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
19735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
197568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
197668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1977bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1978bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1979bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
19815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
19825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
19845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
19855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
19895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
19925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
19935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
19945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
19955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
19965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
19975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
199835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1999561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Pointee->isInstantiationDependentType(),
2000d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
2001d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
2002898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
20035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
20045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2005ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
20065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
20071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
20095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
20105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
2011bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2012bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2013bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20145618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
20155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
20165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
20175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
20185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
20195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
20201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
20211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
20235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
20245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
20255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
20265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
20277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
20285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
202968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
203068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
203168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
20327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
203354e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
203454e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
203535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
2036561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Referencee->isInstantiationDependentType(),
2037d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
2038ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         Referencee->containsUnexpandedParameterPack()),
2039ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    PointeeType(Referencee)
2040d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
2041b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2042b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
20435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2044ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
20455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2046b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
2047b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
2048ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
204954e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
205054e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
205154e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
205254e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
205371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
2054d0370f59e79702ac908c81bf556519f91e9ca297John McCall      T = T->PointeeType->castAs<ReferenceType>();
205554e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
205654e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
205768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
205971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
206154e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
206254e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
206354e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
20645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
206554e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
20665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
20697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
20707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
20717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
20737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
20747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
20757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
20767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
20777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
207854e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
207954e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
208054e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
208154e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
20827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
20837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
2084bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2085bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2086bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
20887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
20897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
20917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
20927c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
20937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
20947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
20957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
20967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
209754e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
20987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
21007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
2101bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2102bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2103bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
21047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
21057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
21067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
21077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
2108f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
2109f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2110f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
2111f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
2112f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
2113f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
2114f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
2115f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
2116f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
2117f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2118f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
2119f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
212035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
2121ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         (Cls->isInstantiationDependentType() ||
2122561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          Pointee->isInstantiationDependentType()),
2123d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
2124ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         (Cls->containsUnexpandedParameterPack() ||
2125d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
2126f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
2127f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2128f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
2129ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2130f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
2131f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
2132f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
21330bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
21340bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
21350bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
21360bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
21370bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
21380bab0cdab751248ca389a5592bcb70eac5d39260John McCall
21390bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
21400bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
21410bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
21420bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
21430bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
21440bab0cdab751248ca389a5592bcb70eac5d39260John McCall
2145f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
2146f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2147bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2148bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2149bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2150f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
2151f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
2152f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2153f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2154f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
2155f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
2156f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
2157f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2158f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2159f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
2160f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
2161f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2162f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
21635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
21665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
21672e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
21685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
2170898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
2171898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
2172898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
21735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
21745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
21755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
21765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2177fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
2178fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
21791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2180fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
2181898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
2182898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
2183898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
2184898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
2185898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
2186c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
2187d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
2188d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
218935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2190561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           et->isInstantiationDependentType() || tc == DependentSizedArray,
2191d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
2192d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
219371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
2194b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
2195b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
219671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2197898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2198fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
219960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
2200fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
2201fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
2202ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
2203b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2204ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
22050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
220671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
220771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
220871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
2209b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
22100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2212fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
2213fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
2214c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
2215898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
2216898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
2217fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2218fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
2219fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
2220fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
22217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
22227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
22237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
22247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
22252e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
2226fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22280be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2229c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
2230d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
2231d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
22327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
22337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
22347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
22357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2236ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2237d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
2238fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2239fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
2240c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
2241bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2242bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2243bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2244ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
22452767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
22462767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
22472767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
22482767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
22492767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
2250ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
22512767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
22522767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
22532767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
2254ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2255fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
22570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
2258fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2259fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
22600be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
22610be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
2262fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
2263fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
22640be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
22650be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2266fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
22677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
226846a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
2269fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2270fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
2271fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
2272fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
2273da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
2274da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
2275da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
2276c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
22777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2278c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
22797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
2280ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : ArrayType(IncompleteArray, et, can, sm, tq,
2281d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
2282c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
2283c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
2284bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2285bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2286bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
2289c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2290c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
22911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2292c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
22931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2294c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
22950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
22960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
2297c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
22981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22990be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
23000be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
2301c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
23020be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
23030be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2304c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2305c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
2306c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
2307da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
2308da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
2309da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
2310da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2311da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2312da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
2313da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
2314da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
2315da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2316da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
2317da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
2318da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
2319da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
2320da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
2321da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
23222e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
23231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
23241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
2325b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
23267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
23277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
23287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2329c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
23307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
23317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
2332ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : ArrayType(VariableArray, et, can, sm, tq,
2333d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
23347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
23355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
23364b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
23375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
23381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2339b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
2340b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
2341b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
2342b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
23437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
23447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
23457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2347bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2348bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2349bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
23511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
23525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2353fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
23541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
235592866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
23561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23572bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
2358b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Cannot unique VariableArrayTypes.");
23592bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
23605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2362898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
2363898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
2364cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2365cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
23661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
2367898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
2368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
2369898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
2370cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
2371cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2372898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
2373898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
2374898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
2375898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
23764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
23771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2378cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
2379898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
2380cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
2381cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
2382cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
2383898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
2384cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
23857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
23867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
23871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
238904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
2390d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
2391d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2392898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
2393898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2394898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2396898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
2397898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
2398898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
2399898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
24007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
24017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
24027e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2404bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2405bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2406bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
24071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
2409898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2410898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
24111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2412898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
24131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2415898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
24161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
24170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
2418898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
24191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
24211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
242204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
2423898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
2424898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2425f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
24269cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
24279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
24289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
24299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
24309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
24319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
24329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
24332ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
24344ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
24359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
24369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
24379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
24389cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2441d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
2442d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
24439cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
24449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
24459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
24462ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
24479cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
24489cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
24499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
2450bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2451bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2452bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
24531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
24559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
24561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
24572ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
24582ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
24592ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
24602ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
24632ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
24649cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
24651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
246773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
24681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
246982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
247082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
247173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
24725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2473788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2474e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2475e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2476e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2477e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2478e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2479491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2480491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2481788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
248273322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
24835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
24845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
24851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
248682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2487d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
2488ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
24891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2490d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2491d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
24925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
2493ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
24945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2497b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
24985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2499bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2500bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2501bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2502e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2503e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
250471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2505788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
25065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
250771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2508e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
25095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
25101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
251182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2512e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
25135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
25145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
251573322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2516e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
251773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
25180b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
25191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
25215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
25225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
25235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
25245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2525213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2526213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2527213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2528fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2529fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2530213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2531213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2532e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
253373322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
253473322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
253588dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
253688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
253788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
253888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
253988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
254088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
254188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
254288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2543e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2544353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
254588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2546353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2547353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2548353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2549353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2550353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2551353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2552353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2553353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2554353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2555353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2556353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2557131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2558353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2559131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2560353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2561131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2562353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2563131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2564353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2565131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2566353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2567131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2568353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
256988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2570e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
25711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2572b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2573b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2574353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2575b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
25761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
257788dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2578b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
257971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
258088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2581e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2582bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2583bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2584bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
258773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2588213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
258973322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
259073322924127c873c13101b705dd823f5539ffa5fSteve Naroff
25915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
259272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
25935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
25945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
25955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
25965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2597264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2598264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2599373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// ExtInfo - A class which abstracts out some details necessary for
2600373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// making a call.
2601373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2602373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// It is not actually used directly for storing this information in
2603373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// a FunctionType, although FunctionType does currently use the
2604373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// same bit-pattern.
2605373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2606075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2607075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2608075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2609425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2610425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2611425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2612425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2613425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2614425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2615425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2616425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
26173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2618425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2619264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
26207e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    // Feel free to rearrange or add bits, but if you go over 8,
2621373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // you'll need to adjust both the Bits field below and
2622373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Type::FunctionTypeBitfields.
2623373920bd733b1d28fe7bf209945a62eb9248d948John McCall
26247e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //   |  CC  |noreturn|produces|regparm|
26257e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //   |0 .. 2|   3    |    4   | 5 .. 7|
26267e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //
26277e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    // regparm is either 0 (no regparm attribute) or the regparm value+1.
2628b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2629b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2630f85e193739c953358c865005855253af4f68a497John McCall    enum { ProducesResultMask = 0x10 };
2631f85e193739c953358c865005855253af4f68a497John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask),
26327e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor           RegParmOffset = 5 }; // Assumed to be the last field
2633b870b88df784c2940efce448ebfaf54dece14666John McCall
2634f85e193739c953358c865005855253af4f68a497John McCall    uint16_t Bits;
263571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2636f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
263771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
263871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
263971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2640264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2641264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
26423c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
2643f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
2644f85e193739c953358c865005855253af4f68a497John McCall            bool producesResult) {
26457e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
2646b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2647b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2648f85e193739c953358c865005855253af4f68a497John McCall             (producesResult ? ProducesResultMask : 0) |
26497e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor             (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0);
265071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2651264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2652264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2653264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
265471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2655264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2656b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2657f85e193739c953358c865005855253af4f68a497John McCall    bool getProducesResult() const { return Bits & ProducesResultMask; }
26587e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
2659ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    unsigned getRegParm() const {
26607e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      unsigned RegParm = Bits >> RegParmOffset;
26617e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      if (RegParm > 0)
26627e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor        --RegParm;
26637e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      return RegParm;
26647e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    }
2665b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2666264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
266771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
266871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2669264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
267071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
267171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2672264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2673264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2674264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2675264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2676264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2677264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
267871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
267971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
268071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
268171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2682425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2683425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2684f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo withProducesResult(bool producesResult) const {
2685f85e193739c953358c865005855253af4f68a497John McCall      if (producesResult)
2686f85e193739c953358c865005855253af4f68a497John McCall        return ExtInfo(Bits | ProducesResultMask);
2687f85e193739c953358c865005855253af4f68a497John McCall      else
2688f85e193739c953358c865005855253af4f68a497John McCall        return ExtInfo(Bits & ~ProducesResultMask);
2689f85e193739c953358c865005855253af4f68a497John McCall    }
2690f85e193739c953358c865005855253af4f68a497John McCall
2691425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
26927e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      assert(RegParm < 7 && "Invalid regparm value");
2693f85e193739c953358c865005855253af4f68a497John McCall      return ExtInfo((Bits & ~RegParmMask) |
26947e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor                     ((RegParm + 1) << RegParmOffset));
2695264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2696264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2697264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2698b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2699264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2700264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2701e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    void Profile(llvm::FoldingSetNodeID &ID) const {
270271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
270371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2704264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2705264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
27065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2707eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  FunctionType(TypeClass tc, QualType res,
2708c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               unsigned typeQuals, RefQualifierKind RefQualifier,
2709c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               QualType Canonical, bool Dependent,
2710561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool InstantiationDependent,
2711ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2712d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2713ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
2714ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           ContainsUnexpandedParameterPack),
2715d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2716b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2717b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
2718c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier);
271971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2720b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
2721ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2722c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2723c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
2724c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2725c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
27265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
2729a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman
2730a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
2731b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2732b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2733b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2734b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
27354ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie  bool isConst() const { return getTypeQuals() & Qualifiers::Const; }
27364ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie  bool isVolatile() const { return getTypeQuals() & Qualifiers::Volatile; }
27374ef832ffc1147ce2f9777f9fad650cb3139a1d00David Blaikie  bool isRestrict() const { return getTypeQuals() & Qualifiers::Restrict; }
27385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
27395291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
27405291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
2741ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  QualType getCallResultType(ASTContext &Context) const {
27426398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
27435291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
27445291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2745686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  static StringRef getNameForCallConv(CallingConv CC);
274604a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
27475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
27485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
27495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
27505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
27525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
27535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
275472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
27555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
275672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
275771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
2758eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith    : FunctionType(FunctionNoProto, Result, 0, RQ_None, Canonical,
2759561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                   /*Dependent=*/false, /*InstantiationDependent=*/false,
2760ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                   Result->isVariablyModifiedType(),
2761d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2762d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
27635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
2764ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
27655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
27665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2768bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2769bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2770bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
27715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2772264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
27735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27742455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
277571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
277671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
27775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
27785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
27815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
27825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
278372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
27845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
27855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
278672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
27875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2788465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2789465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2790465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
279172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2792e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic:
2793e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// ExtProtoInfo - Extra information about a function prototype.
2794e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  struct ExtProtoInfo {
2795e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo() :
2796361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer      Variadic(false), HasTrailingReturn(false), TypeQuals(0),
2797361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer      ExceptionSpecType(EST_None), RefQualifier(RQ_None),
279813bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      NumExceptions(0), Exceptions(0), NoexceptExpr(0),
279913bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      ExceptionSpecDecl(0), ExceptionSpecTemplate(0),
2800e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith      ConsumedArguments(0) {}
2801e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2802e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionType::ExtInfo ExtInfo;
28030e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer    bool Variadic : 1;
28040e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer    bool HasTrailingReturn : 1;
2805e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned char TypeQuals;
2806361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer    ExceptionSpecificationType ExceptionSpecType;
2807361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer    RefQualifierKind RefQualifier;
2808e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned NumExceptions;
2809e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    const QualType *Exceptions;
28108b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    Expr *NoexceptExpr;
2811e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith    FunctionDecl *ExceptionSpecDecl;
281213bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    FunctionDecl *ExceptionSpecTemplate;
2813f85e193739c953358c865005855253af4f68a497John McCall    const bool *ConsumedArguments;
2814e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  };
2815e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2816e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate:
2817d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2818d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2819ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2820d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2821d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2822d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2823d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2824d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2825d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2826d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2827d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2828e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
28298026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                    QualType canonical, const ExtProtoInfo &epi);
2830465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
28315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2832eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  unsigned NumArgs : 17;
2833465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2834465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
283560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned NumExceptions : 9;
2836465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
283760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// ExceptionSpecType - The type of exception specification this function has.
283860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned ExceptionSpecType : 3;
2839465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2840f85e193739c953358c865005855253af4f68a497John McCall  /// HasAnyConsumedArgs - Whether this function has any consumed arguments.
2841f85e193739c953358c865005855253af4f68a497John McCall  unsigned HasAnyConsumedArgs : 1;
2842f85e193739c953358c865005855253af4f68a497John McCall
2843eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  /// Variadic - Whether the function is variadic.
2844eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  unsigned Variadic : 1;
2845eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith
2846eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  /// HasTrailingReturn - Whether this function has a trailing return type.
2847eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  unsigned HasTrailingReturn : 1;
2848eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith
28496a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // ArgInfo - There is an variable size array after the class in memory that
28506a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // holds the argument types.
2851b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
28526a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // Exceptions - There is another variable size array after ArgInfo that
28536a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // holds the exception types.
2854b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
28556a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
28566a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // to the expression in the noexcept() specifier.
2857b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
285813bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // ExceptionSpecDecl, ExceptionSpecTemplate - Instead of Exceptions, there may
285913bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // be a pair of FunctionDecl* pointing to the function which should be used to
286013bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // instantiate this function type's exception specification, and the function
286113bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // from which it should be instantiated.
2862e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith
28636a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // ConsumedArgs - A variable size array, following Exceptions
28646a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // and of length NumArgs, holding flags indicating which arguments
28656a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // are consumed.  This only appears if HasAnyConsumedArgs is true.
2866b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
28675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
28684b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
2869f85e193739c953358c865005855253af4f68a497John McCall  const bool *getConsumedArgsBuffer() const {
2870f85e193739c953358c865005855253af4f68a497John McCall    assert(hasAnyConsumedArgs());
2871f85e193739c953358c865005855253af4f68a497John McCall
2872f85e193739c953358c865005855253af4f68a497John McCall    // Find the end of the exceptions.
2873f85e193739c953358c865005855253af4f68a497John McCall    Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end());
2874f85e193739c953358c865005855253af4f68a497John McCall    if (getExceptionSpecType() != EST_ComputedNoexcept)
2875f85e193739c953358c865005855253af4f68a497John McCall      eh_end += NumExceptions;
2876f85e193739c953358c865005855253af4f68a497John McCall    else
2877f85e193739c953358c865005855253af4f68a497John McCall      eh_end += 1; // NoexceptExpr
2878f85e193739c953358c865005855253af4f68a497John McCall
2879f85e193739c953358c865005855253af4f68a497John McCall    return reinterpret_cast<const bool*>(eh_end);
2880f85e193739c953358c865005855253af4f68a497John McCall  }
2881f85e193739c953358c865005855253af4f68a497John McCall
28825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
28835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
28845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
28855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2886942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
28875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2888465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2889e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  ExtProtoInfo getExtProtoInfo() const {
2890e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo EPI;
2891e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.ExtInfo = getExtInfo();
2892e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Variadic = isVariadic();
2893eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith    EPI.HasTrailingReturn = hasTrailingReturn();
289460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    EPI.ExceptionSpecType = getExceptionSpecType();
2895e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2896c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    EPI.RefQualifier = getRefQualifier();
289760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EPI.ExceptionSpecType == EST_Dynamic) {
289860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NumExceptions = NumExceptions;
289960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.Exceptions = exception_begin();
290060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
290160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NoexceptExpr = getNoexceptExpr();
2902e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith    } else if (EPI.ExceptionSpecType == EST_Uninstantiated) {
2903e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith      EPI.ExceptionSpecDecl = getExceptionSpecDecl();
290413bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      EPI.ExceptionSpecTemplate = getExceptionSpecTemplate();
2905b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith    } else if (EPI.ExceptionSpecType == EST_Unevaluated) {
2906b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith      EPI.ExceptionSpecDecl = getExceptionSpecDecl();
290760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    }
2908f85e193739c953358c865005855253af4f68a497John McCall    if (hasAnyConsumedArgs())
2909f85e193739c953358c865005855253af4f68a497John McCall      EPI.ConsumedArguments = getConsumedArgsBuffer();
2910e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    return EPI;
2911e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  }
2912e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
291360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the kind of exception specification on this function.
291460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  ExceptionSpecificationType getExceptionSpecType() const {
291560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
291660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
291760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has any kind of exception spec.
291860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasExceptionSpec() const {
291960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return getExceptionSpecType() != EST_None;
292060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
292160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has a dynamic (throw) exception spec.
292260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasDynamicExceptionSpec() const {
292360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isDynamicExceptionSpec(getExceptionSpecType());
292460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
2925fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// \brief Return whether this function has a noexcept exception spec.
292660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasNoexceptExceptionSpec() const {
292760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isNoexceptExceptionSpec(getExceptionSpecType());
292860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
292960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Result type of getNoexceptSpec().
293060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  enum NoexceptResult {
293160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_NoNoexcept,  ///< There is no noexcept specifier.
293260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
293360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Dependent,   ///< The noexcept specifier is dependent.
293460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Throw,       ///< The noexcept specifier evaluates to false.
293560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Nothrow      ///< The noexcept specifier evaluates to true.
293660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  };
293760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the meaning of the noexcept spec on this function, if any.
29388026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  NoexceptResult getNoexceptSpec(ASTContext &Ctx) const;
2939465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2940465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2941465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2942465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2943465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
294460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  Expr *getNoexceptExpr() const {
294560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_ComputedNoexcept)
294660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return 0;
294760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    // NoexceptExpr sits where the arguments end.
294860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return *reinterpret_cast<Expr *const *>(arg_type_end());
2949d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
2950b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith  /// \brief If this function type has an exception specification which hasn't
2951b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith  /// been determined yet (either because it has not been evaluated or because
2952b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith  /// it has not been instantiated), this is the function whose exception
2953b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith  /// specification is represented by this type.
2954e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  FunctionDecl *getExceptionSpecDecl() const {
2955b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith    if (getExceptionSpecType() != EST_Uninstantiated &&
2956b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith        getExceptionSpecType() != EST_Unevaluated)
2957e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith      return 0;
295813bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[0];
295913bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  }
296013bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// \brief If this function type has an uninstantiated exception
296113bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// specification, this is the function whose exception specification
296213bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// should be instantiated to find the exception specification for
296313bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// this type.
296413bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  FunctionDecl *getExceptionSpecTemplate() const {
296513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    if (getExceptionSpecType() != EST_Uninstantiated)
296613bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      return 0;
296713bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[1];
2968e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  }
29698026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool isNothrow(ASTContext &Ctx) const {
297060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    ExceptionSpecificationType EST = getExceptionSpecType();
2971b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith    assert(EST != EST_Unevaluated && EST != EST_Uninstantiated);
297260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
297360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return true;
297460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST != EST_ComputedNoexcept)
297560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return false;
29768026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl    return getNoexceptSpec(Ctx) == NR_Nothrow;
2977c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  }
2978c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
2979eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  bool isVariadic() const { return Variadic; }
298060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
2981f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// \brief Determines whether this function prototype contains a
2982f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// parameter pack at the end.
2983f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  ///
2984f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// A function template whose last parameter is a parameter pack can be
2985f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// called with an arbitrary number of arguments, much like a variadic
2986eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  /// function.
2987f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  bool isTemplateVariadic() const;
2988ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2989eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  bool hasTrailingReturn() const { return HasTrailingReturn; }
2990eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith
2991971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
29921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2993ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2994c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief Retrieve the ref-qualifier associated with this function type.
2995c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2996c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return FunctionType::getRefQualifier();
2997c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2998ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
29995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
3000942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
3001942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
3002942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
3003942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
3004465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
3005465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
3006465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
3007465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
3008465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
3009465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
3010465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
301160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_Dynamic)
301260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return exception_begin();
3013465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
3014465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
3015465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
3016f85e193739c953358c865005855253af4f68a497John McCall  bool hasAnyConsumedArgs() const {
3017f85e193739c953358c865005855253af4f68a497John McCall    return HasAnyConsumedArgs;
3018f85e193739c953358c865005855253af4f68a497John McCall  }
3019f85e193739c953358c865005855253af4f68a497John McCall  bool isArgConsumed(unsigned I) const {
3020f85e193739c953358c865005855253af4f68a497John McCall    assert(I < getNumArgs() && "argument index out of range!");
3021f85e193739c953358c865005855253af4f68a497John McCall    if (hasAnyConsumedArgs())
3022f85e193739c953358c865005855253af4f68a497John McCall      return getConsumedArgsBuffer()[I];
3023f85e193739c953358c865005855253af4f68a497John McCall    return false;
3024f85e193739c953358c865005855253af4f68a497John McCall  }
3025f85e193739c953358c865005855253af4f68a497John McCall
3026bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3027bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3028bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
30297ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  // FIXME: Remove the string version.
303001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  void printExceptionSpecification(std::string &S,
303101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                                   PrintingPolicy Policy) const;
30327ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void printExceptionSpecification(raw_ostream &OS,
30337ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                   PrintingPolicy Policy) const;
303401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
30355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
30365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
30375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
303872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
3039465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
30408026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
30415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
3042942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
30438026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                      const ExtProtoInfo &EPI, const ASTContext &Context);
30445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
30455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
30465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3047ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
3048ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
3049ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
3050ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
3051ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
3052ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
3053ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
305419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
3055ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(UnresolvedUsing, QualType(), true, true, false,
3056d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
305719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
3058ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
3059ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
3060ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3061ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
3062ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3063ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
3064ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
3065ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3066ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
3067ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
3068ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3069ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
3070ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3071ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3072ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
3073ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3074ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
3075ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
3076ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
3077ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3078ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
3079ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3080ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
30815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
3082162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Decl;
3083c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
3084162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
3085ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(tc, can, can->isDependentType(),
3086561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           can->isInstantiationDependentType(),
3087ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           can->isVariablyModifiedType(),
3088d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3089162e1c1b487352434552147967c3dd296ebee2f7Richard Smith      Decl(const_cast<TypedefNameDecl*>(D)) {
30905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
30915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
30925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
30935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
30941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3095162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *getDecl() const { return Decl; }
30961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3097bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3098bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
3099bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
310072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
31015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
31025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
31035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
310472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
310572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
3106d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
31071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3108b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
3109dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
3110d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
3111d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
3112d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
31131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3114bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3115bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
3116bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3117bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
31186af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor  bool isSugared() const;
3119bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
312072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
312172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
3122d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
3123d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
3124c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
31251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
3126c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
3127c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
3128c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
3129c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
31301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
3131b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
31324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
31331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3134b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
31354ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
3136b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
31371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3138b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3139b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
3140b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
31411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3143b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
3144b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
31451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3146d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
3147d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
3148d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
31491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
3150ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(TypeOf, can, T->isDependentType(),
3151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           T->isInstantiationDependentType(),
3152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           T->isVariablyModifiedType(),
3153ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           T->containsUnexpandedParameterPack()),
315435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
3155d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
3156d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
3157d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
3158d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
3159d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
31601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3161bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3162bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
3163bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3164bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3165bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3166bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
316772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
3168d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
3169d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
31705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3171395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
3172395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
3173395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
3174563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
31751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31769d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
3177563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
3178395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
3179395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
3180395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
3181563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
3182563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
3183bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
31846af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor  QualType desugar() const;
3185bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3186bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
31876af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor  bool isSugared() const;
3188bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3189395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
3190395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
3191395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
31921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3193c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
3194c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
3195c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
3196c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
3197c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
3198c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
31999d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
32004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32029d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
32034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentDecltypeType(const ASTContext &Context, Expr *E);
32041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32059d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
32069d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
32079d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
32081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
32101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
32119d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
32121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3213ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// \brief A unary type transform, which is a type constructed from another
3214ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformType : public Type {
3215ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
3216ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  enum UTTKind {
3217ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    EnumUnderlyingType
3218ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  };
3219ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3220ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprivate:
3221ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// The untransformed type.
3222ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType BaseType;
3223ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// The transformed type if not dependent, otherwise the same as BaseType.
3224ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType UnderlyingType;
3225ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3226ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UTTKind UKind;
3227ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprotected:
3228ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
3229ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                     QualType CanonicalTy);
3230ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  friend class ASTContext;
3231ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
3232ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  bool isSugared() const { return !isDependentType(); }
3233ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType desugar() const { return UnderlyingType; }
3234ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3235ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType getUnderlyingType() const { return UnderlyingType; }
3236ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType getBaseType() const { return BaseType; }
3237ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3238ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UTTKind getUTTKind() const { return UKind; }
3239ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3240ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  static bool classof(const Type *T) {
3241ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    return T->getTypeClass() == UnaryTransform;
3242ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
3243ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  static bool classof(const UnaryTransformType *) { return true; }
3244ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt};
3245ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
32465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
3247ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
3248ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
3249ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
32502ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
325156ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor  friend class ASTReader;
325256ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor
32532ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
325419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
32552ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
32561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
3257ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
32581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32590b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
32601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
3261ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
32620b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
32631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
326472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
326572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
32665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
32675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
32685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
32695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
32705edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
32715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
327249aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
327319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
327419c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
327572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
327619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
32772ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
32785edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
32791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32805edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
32815edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
32825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
32831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
32855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
32875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
32885edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
3289bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3290bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3291bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
329295b68f94d28a4b94f4c3fb029b9f1690e1bb728bPeter Collingbourne  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
32935edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
32945edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
32955edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
32965edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
32975edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
32985edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
329919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
330019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
33012ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
33025edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
33031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
33045edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
33055edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
33065edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
33071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3308bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3309bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3310bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
331195b68f94d28a4b94f4c3fb029b9f1690e1bb728bPeter Collingbourne  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
33125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
33135edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
33145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
33159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type
33169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied.  The "modified type" is the
33179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied;
33189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type.
33199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the
33209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to.
33219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///
33229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type:
33239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///     int32_t __attribute__((vector_size(16)))
33249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the modified type is the TypedefType for int32_t
33259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the equivalent type is VectorType(16, int32_t)
33269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the canonical type is VectorType(16, int)
33279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode {
33289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
33299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // It is really silly to have yet another attribute-kind enum, but
33309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // clang::attr::Kind doesn't currently cover the pure type attrs.
33319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  enum Kind {
33329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Expression operand.
3333170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_address_space,
3334170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_regparm,
3335170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_vector_size,
3336170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_vector_type,
3337170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_polyvector_type,
33389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3339170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstExprOperandKind = attr_address_space,
3340170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    LastExprOperandKind = attr_neon_polyvector_type,
33419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Enumerated operand (string or keyword).
3343170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_objc_gc,
3344b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis    attr_objc_ownership,
3345414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    attr_pcs,
33469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3347170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstEnumOperandKind = attr_objc_gc,
3348414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    LastEnumOperandKind = attr_pcs,
33499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // No operand.
33513cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_noreturn,
33523cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_cdecl,
33533cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_fastcall,
33543cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_stdcall,
33553cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_thiscall,
33563cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_pascal
33579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
33589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate:
33609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType ModifiedType;
33619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType EquivalentType;
33629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  friend class ASTContext; // creates these
33649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType(QualType canon, Kind attrKind,
33669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                 QualType modified, QualType equivalent)
33679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    : Type(Attributed, canon, canon->isDependentType(),
3368561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           canon->isInstantiationDependentType(),
33699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->isVariablyModifiedType(),
33709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->containsUnexpandedParameterPack()),
33719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      ModifiedType(modified), EquivalentType(equivalent) {
33729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBits.AttrKind = attrKind;
33739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
33769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Kind getAttrKind() const {
33779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return static_cast<Kind>(AttributedTypeBits.AttrKind);
33789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getModifiedType() const { return ModifiedType; }
33819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getEquivalentType() const { return EquivalentType; }
33829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool isSugared() const { return true; }
33849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType desugar() const { return getEquivalentType(); }
33859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
33879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
33889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
33919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                      QualType modified, QualType equivalent) {
33929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddInteger(attrKind);
33939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(modified.getAsOpaquePtr());
33949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(equivalent.getAsOpaquePtr());
33959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const Type *T) {
33989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return T->getTypeClass() == Attributed;
33999d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
34009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const AttributedType *T) { return true; }
34019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
34029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3403fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
34044fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  // Helper data collector for canonical types.
34054fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  struct CanonicalTTPTInfo {
34064fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Depth : 15;
34074fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned ParameterPack : 1;
34084fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Index : 16;
34094fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
34104fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
34114fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  union {
34124fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the canonical type.
34134fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanonicalTTPTInfo CanTTPTInfo;
34144fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the non-canonical type.
34154fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    TemplateTypeParmDecl *TTPDecl;
34164fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
341772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
34184fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build a non-canonical type.
34194fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
342035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
3421561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
34224fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false,
34235d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth           Canon->containsUnexpandedParameterPack()),
34244fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth      TTPDecl(TTPDecl) { }
342572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
34264fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build the canonical type.
34271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
3428ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(TemplateTypeParm, QualType(this, 0),
3429561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*Dependent=*/true,
3430561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
34314fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false, PP) {
34324fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Depth = D;
34334fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Index = I;
34344fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.ParameterPack = PP;
34354fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
343672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3437fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
343872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
34394fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  const CanonicalTTPTInfo& getCanTTPTInfo() const {
34404fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    QualType Can = getCanonicalTypeInternal();
34415d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth    return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
34424fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
34434fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3444fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
34454fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
34464fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getIndex() const { return getCanTTPTInfo().Index; }
34474fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
34484fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
34494fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmDecl *getDecl() const {
34504fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    return isCanonicalUnqualified() ? 0 : TTPDecl;
34514fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
34524fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3453b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const;
34541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3455bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3456bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3457bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3458fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
34594fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
3460fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3461fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
34621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
34631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
34644fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth                      TemplateTypeParmDecl *TTPDecl) {
3465fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
3466fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
346776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
34684fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    ID.AddPointer(TTPDecl);
3469fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3470fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
34711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
34721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
347372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
347472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
347572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
3476fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
347749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
347849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
347949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
348049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
348149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
348249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
348349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
348449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
348549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
348649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
348749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
348849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
348935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
3490561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Canon->isInstantiationDependentType(),
3491d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
3492d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
349349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
349449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
349549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
349649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
349749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
349849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
349949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
350049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
350149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
350249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
350349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
350449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
350549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
350649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
350749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
350849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
350949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
351049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
351149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
351249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
351349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
351449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
351549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
351649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
351749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
351849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
351949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
352049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
352149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
352249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
352349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
352449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
352549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
352649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
352749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
3528c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template
3529c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack.
3530c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor///
3531c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3532c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template
3533ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// parameter lists, this type node is used to represent a template type
3534c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3535c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3536c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3537c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3538c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
3539c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index.
3540c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
3541c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The original type parameter.
3542c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *Replaced;
3543ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3544c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3545c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// parameter pack is instantiated with.
3546c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateArgument *Arguments;
3547ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3548c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3549c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  unsigned NumArguments;
3550ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3551ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3552c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                QualType Canon,
3553c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                const TemplateArgument &ArgPack);
3554ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3555c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  friend class ASTContext;
3556ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3557c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic:
3558b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
3559ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3560c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// Gets the template parameter that was substituted for.
3561c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *getReplacedParameter() const {
3562c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return Replaced;
3563c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3564ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3565c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  bool isSugared() const { return false; }
3566c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
3567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3568c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  TemplateArgument getArgumentPack() const;
3569ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3570c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID);
3571c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
3572c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateTypeParmType *Replaced,
3573c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateArgument &ArgPack);
3574ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3575c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const Type *T) {
3576c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return T->getTypeClass() == SubstTemplateTypeParmPack;
3577c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3578c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
3579c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
3580c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
358134b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type.
358234b41d939a1328f484511c6002ba2456db879a29Richard Smith///
358334b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within
358434b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type
358534b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical.
358634b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode {
358734b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType(QualType DeducedType)
358834b41d939a1328f484511c6002ba2456db879a29Richard Smith    : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType,
358934b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*Dependent=*/DeducedType.isNull(),
3590561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/DeducedType.isNull(),
359134b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*VariablyModified=*/false, /*ContainsParameterPack=*/false) {
359234b41d939a1328f484511c6002ba2456db879a29Richard Smith    assert((DeducedType.isNull() || !DeducedType->isDependentType()) &&
359334b41d939a1328f484511c6002ba2456db879a29Richard Smith           "deduced a dependent type for auto");
359434b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
359534b41d939a1328f484511c6002ba2456db879a29Richard Smith
359634b41d939a1328f484511c6002ba2456db879a29Richard Smith  friend class ASTContext;  // ASTContext creates these
359734b41d939a1328f484511c6002ba2456db879a29Richard Smith
359834b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic:
359934b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isSugared() const { return isDeduced(); }
360034b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType desugar() const { return getCanonicalTypeInternal(); }
360134b41d939a1328f484511c6002ba2456db879a29Richard Smith
360234b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType getDeducedType() const {
360334b41d939a1328f484511c6002ba2456db879a29Richard Smith    return isDeduced() ? getCanonicalTypeInternal() : QualType();
360434b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
360534b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isDeduced() const {
360634b41d939a1328f484511c6002ba2456db879a29Richard Smith    return !isDependentType();
360734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
360834b41d939a1328f484511c6002ba2456db879a29Richard Smith
360934b41d939a1328f484511c6002ba2456db879a29Richard Smith  void Profile(llvm::FoldingSetNodeID &ID) {
361034b41d939a1328f484511c6002ba2456db879a29Richard Smith    Profile(ID, getDeducedType());
361134b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
361234b41d939a1328f484511c6002ba2456db879a29Richard Smith
361334b41d939a1328f484511c6002ba2456db879a29Richard Smith  static void Profile(llvm::FoldingSetNodeID &ID,
361434b41d939a1328f484511c6002ba2456db879a29Richard Smith                      QualType Deduced) {
361534b41d939a1328f484511c6002ba2456db879a29Richard Smith    ID.AddPointer(Deduced.getAsOpaquePtr());
361634b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
361734b41d939a1328f484511c6002ba2456db879a29Richard Smith
361834b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const Type *T) {
361934b41d939a1328f484511c6002ba2456db879a29Richard Smith    return T->getTypeClass() == Auto;
362034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
362134b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const AutoType *T) { return true; }
362234b41d939a1328f484511c6002ba2456db879a29Richard Smith};
362334b41d939a1328f484511c6002ba2456db879a29Richard Smith
36241901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// \brief Represents a type template specialization; the template
36251901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// must be a class template, a type alias template, or a template
36261901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template parameter.  A template which cannot be resolved to one of
36271901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// these, e.g. because it is written with a dependent scope
36281901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specifier, is instead represented as a
36291901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// @c DependentTemplateSpecializationType.
363055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
36311901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// A non-dependent template specialization type is always "sugar",
36321901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// typically for a @c RecordType.  For example, a class template
36331901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specialization type of @c vector<int> will refer to a tag type for
36341901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// the instantiation @c std::vector<int, std::allocator<int>>
36357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
36361901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Template specializations are dependent if either the template or
36371901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// any of the template arguments are dependent, in which case the
36381901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// type may also be canonical.
36393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith///
36401901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Instances of this type are allocated with a trailing array of
36411901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// TemplateArguments, followed by a QualType representing the
36421901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// non-canonical aliased type when the template is a type alias
36431901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template.
36441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
364555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
36461901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// \brief The name of the template being specialized.  This is
36471901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// either a TemplateName::Template (in which case it is a
36481901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
3649146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TypeAliasTemplateDecl*), a
3650146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TemplateName::SubstTemplateTemplateParmPack, or a
3651146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TemplateName::SubstTemplateTemplateParm (in which case the
3652146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// replacement must, recursively, be one of these).
36537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
365455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
365540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
365640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
3657b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  unsigned NumArgs : 31;
365855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
3659b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \brief Whether this template specialization type is a substituted
3660b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// type alias.
3661b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  bool TypeAlias : 1;
3662b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor
3663ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
36647532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
36653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             unsigned NumArgs, QualType Canon,
36663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             QualType Aliased);
366755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
366855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
366955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
367055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
367140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
367240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
367340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
3674561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            unsigned NumArgs,
3675561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            bool &InstantiationDependent);
367640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
3677833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
3678561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            unsigned NumArgs,
3679561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            bool &InstantiationDependent);
3680833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3681561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
3682561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            bool &InstantiationDependent);
3683d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3684df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
3685df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
36867ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  // FIXME: remove the string ones.
3687df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
3688d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
3689dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               const PrintingPolicy &Policy,
3690dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               bool SkipBrackets = false);
3691df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
3692833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
3693833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
3694833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
3695833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3696d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
3697d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
3698d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
36997ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  /// \brief Print a template argument list, including the '<' and '>'
37007ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  /// enclosing the template arguments.
37017ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void PrintTemplateArgumentList(raw_ostream &OS,
37027ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const TemplateArgument *Args,
37037ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        unsigned NumArgs,
37047ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const PrintingPolicy &Policy,
37057ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        bool SkipBrackets = false);
37067ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
37077ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void PrintTemplateArgumentList(raw_ostream &OS,
37087ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const TemplateArgumentLoc *Args,
37097ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        unsigned NumArgs,
37107ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const PrintingPolicy &Policy);
37117ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
37127ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void PrintTemplateArgumentList(raw_ostream &OS,
37137ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const TemplateArgumentListInfo &,
37147ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const PrintingPolicy &Policy);
37157ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
371631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
371731f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
371831f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
371971d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
372031f17ecbef57b5679c017c375db330546b7b5145John McCall  }
372131f17ecbef57b5679c017c375db330546b7b5145John McCall
3722b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \brief Determine if this template specialization type is for a type alias
3723b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template that has been substituted.
3724b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  ///
3725b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// Nearly every template specialization type whose template is an alias
3726b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template will be substituted. However, this is not the case when
3727b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// the specialization contains a pack expansion but the template alias
3728b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// does not have a corresponding parameter pack, e.g.,
3729b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  ///
3730b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \code
3731b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template<typename T, typename U, typename V> struct S;
3732b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template<typename T, typename U> using A = S<T, int, U>;
3733b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template<typename... Ts> struct X {
3734b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  ///   typedef A<Ts...> type; // not a type alias
3735b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// };
3736b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \endcode
3737b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  bool isTypeAlias() const { return TypeAlias; }
3738b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor
37393e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// Get the aliased type, if this is a specialization of a type alias
37403e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// template.
37413e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  QualType getAliasedType() const {
37423e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    assert(isTypeAlias() && "not a type alias template specialization");
37433e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return *reinterpret_cast<const QualType*>(end());
37443e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
37453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
374640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
374740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
374840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
374933500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
375040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
37517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
37527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
375355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
375440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
37551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
375640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
375740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
375840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
375940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
376055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
376155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
376255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
3763809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// \pre @c isArgType(Arg)
376433500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
376555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
376631f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
37673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
376831f17ecbef57b5679c017c375db330546b7b5145John McCall  }
3769bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
3770bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
37714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
377271d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
37733e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isTypeAlias())
37743e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      getAliasedType().Profile(ID);
377555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
377655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
37777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
377831f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
377931f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
37804ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context);
378155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
37821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
37831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
378455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
37857532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
378655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
378755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
378831f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
378931f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
379031f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
379131f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
37923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
379331f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
379431f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
37953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
379631f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
379731f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
379831f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
379931f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
380031f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
380131f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
380231f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
380331f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
380431f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
38053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
38063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
38073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
380831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
380931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
381031f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
381131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
381231f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
381331f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
381431f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
381531f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
381631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
381731f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
38183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
38193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
3820c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
3821c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
382243921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
382331f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
382435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
3825561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
3826ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           /*VariablyModified=*/false,
3827d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
382831f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
38293cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
38303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
383131f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
38323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
38333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
38343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
383531f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
383631f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
383731f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
38383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
38393cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3840ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
38413cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
384231f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
384331f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
38443cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
38453cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
38463cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
38473cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
38483cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
38493cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
38503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3851465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
3852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
3853465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
3854465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
38556666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  /// \brief The "__interface" keyword.
38566666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  TTK_Interface,
3857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
3858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
3859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
3860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
3861465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
3862465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
3863465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3864465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
38654a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
38664a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
38674a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
38684a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
38694a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
38706666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  /// \brief The "__interface" keyword introduces the elaborated-type-specifier.
38716666ed4ed2e2bc13da5ac5d0a4947019137d45beJoao Matos  ETK_Interface,
38724a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
38734a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
3874465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
3875465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
38764a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
3877465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
3878465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
3879465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
3880465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
3881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
3882465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
38834a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
3884465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3885465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
3886465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
3887465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
3888465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
3889465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
3890465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
3891465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
3892ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                  QualType Canonical, bool Dependent,
3893ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                  bool InstantiationDependent, bool VariablyModified,
3894d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
3895ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3896d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
389777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
389877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
3899465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3900465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
3901465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
390277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
3903465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3904465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3905465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
3906465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
3907465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
3908465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3909465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
3910465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
3911465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3912465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
3913465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3914465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
3915465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
3916465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
3917465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
3919465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
3920465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3921465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
3922465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3923465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
3924465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3925465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
3926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3927465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
3928465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
3929465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3930465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3931465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
3932465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
3933465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3935465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
3936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
3937465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
3938e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
3939e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
3940465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
3941465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
3942465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
3943465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3944465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3945ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3946ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
3947e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3948e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
3949e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
3950e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3951465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3952465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
3953465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
395435495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
3955561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                      NamedType->isInstantiationDependentType(),
3956d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
3957d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
3958465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
3959465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
3960465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
3961465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
3962465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3963e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3964e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3965e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3966e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
396733500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
3968465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3969ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
3970ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3971e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3972e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
3973e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3974e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3975bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3976bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3977bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3978bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3979bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3980bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3981e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3982465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3983e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3984e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3985465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3986465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3987465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3988ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3989ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3990ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3991e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
39921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3993465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3994e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3995465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3996e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3997e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
39984a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
3999ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// dependent.
4000d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
4001ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// DependentNameType represents a class of dependent types that involve a
4002ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
40034a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
4004ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// typename-specifier), "class", "struct", "union", or "enum" (for a
40054a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
40064a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
4007465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
4008465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
4009d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
4010d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
4011d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
4012d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
401333500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
4014d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
4015ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
40164a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
401735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
4018561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                      /*InstantiationDependent=*/true,
4019d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
4020d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
4021465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
40221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
40234714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
4024d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
4025d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
4026d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
4027d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
4028d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
4029d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
4030d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
4031d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
40321734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
40331734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
40341734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
40351734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
40361734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
40371734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
40381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
403933500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
40401734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
4041d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
4042bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4043bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4044bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4045d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
4046465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
4047d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
4048d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
40494a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
405033500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
40514a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
4052d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
405333500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
4054d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
4055d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
40561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
40574714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
4058d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
40594714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
4060d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
4061d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
406233500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
406333500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
406433500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
406533500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
406633500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
406733500955d731c73717af52088b7fc0e7a85681e7John McCall
406833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
406933500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
407033500955d731c73717af52088b7fc0e7a85681e7John McCall
407133500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
407233500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
407333500955d731c73717af52088b7fc0e7a85681e7John McCall
407433500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
407533500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
407633500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
407733500955d731c73717af52088b7fc0e7a85681e7John McCall
407833500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
407933500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
408033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
408133500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
408233500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
408333500955d731c73717af52088b7fc0e7a85681e7John McCall  }
408433500955d731c73717af52088b7fc0e7a85681e7John McCall
4085ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
408633500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
408733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
408833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
408933500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
409033500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
409133500955d731c73717af52088b7fc0e7a85681e7John McCall
409233500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
409333500955d731c73717af52088b7fc0e7a85681e7John McCall
409433500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
409533500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
409633500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
409733500955d731c73717af52088b7fc0e7a85681e7John McCall
409833500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
409933500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
410033500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
410133500955d731c73717af52088b7fc0e7a85681e7John McCall  }
410233500955d731c73717af52088b7fc0e7a85681e7John McCall
410333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
410433500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
410533500955d731c73717af52088b7fc0e7a85681e7John McCall
410633500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
410733500955d731c73717af52088b7fc0e7a85681e7John McCall
410833500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
410933500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
411033500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
411133500955d731c73717af52088b7fc0e7a85681e7John McCall
411233500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
411333500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
411433500955d731c73717af52088b7fc0e7a85681e7John McCall
41154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
411633500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
411733500955d731c73717af52088b7fc0e7a85681e7John McCall  }
411833500955d731c73717af52088b7fc0e7a85681e7John McCall
411933500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
41204ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context,
412133500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
412233500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
412333500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
412433500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
412533500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
412633500955d731c73717af52088b7fc0e7a85681e7John McCall
412733500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
412833500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
412933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
413033500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
413133500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
4132ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
413333500955d731c73717af52088b7fc0e7a85681e7John McCall};
413433500955d731c73717af52088b7fc0e7a85681e7John McCall
41357536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types.
41367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
41377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack
41387536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more
41397536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion
41407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of
41417536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the
41427536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The
41437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded
41447536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs.
41457536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
41467536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code
41477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple;
41487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
4149ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// template<typename ...Types>
41507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references {
41517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///   typedef tuple<Types&...> type;
41527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// };
41537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode
41547536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
41557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a
41567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&.
41577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode {
41587536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief The pattern of the pack expansion.
41597536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType Pattern;
41607536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4161cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief The number of expansions that this pack expansion will
4162ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// generate when substituted (+1), or indicates that
4163cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  ///
4164ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This field will only have a non-zero value when some of the parameter
4165ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// packs that occur within the pattern have been substituted but others have
4166cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// not.
4167cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  unsigned NumExpansions;
4168ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4169cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  PackExpansionType(QualType Pattern, QualType Canon,
4170cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                    llvm::Optional<unsigned> NumExpansions)
4171aa488ea287c219565b5169d50142947d1b63a6caRichard Smith    : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(),
4172561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
41737536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*VariableModified=*/Pattern->isVariablyModifiedType(),
41747536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
4175ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      Pattern(Pattern),
4176cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
41777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
41787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  friend class ASTContext;  // ASTContext creates these
4179ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
41807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
41817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief Retrieve the pattern of this pack expansion, which is the
41827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// type that will be repeatedly instantiated when instantiating the
41837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// pack expansion itself.
41847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getPattern() const { return Pattern; }
41857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4186cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief Retrieve the number of expansions that this pack expansion will
4187cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate, if known.
4188cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
4189cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
4190cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      return NumExpansions - 1;
4191ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4192cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return llvm::Optional<unsigned>();
4193cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  }
4194ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
41957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  bool isSugared() const { return false; }
41967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
41977536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
41987536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
4199cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Profile(ID, getPattern(), getNumExpansions());
42007536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
42017536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4202cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
4203cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                      llvm::Optional<unsigned> NumExpansions) {
42047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    ID.AddPointer(Pattern.getAsOpaquePtr());
4205cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    ID.AddBoolean(NumExpansions);
4206cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
4207cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      ID.AddInteger(*NumExpansions);
42087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
42097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
42107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const Type *T) {
42117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return T->getTypeClass() == PackExpansion;
42127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
42137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const PackExpansionType *T) {
42147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return true;
4215ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
42167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
42177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
4219c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
4220c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
4221c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4222c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
422341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \code
422441c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@class C;
422541c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth///   \@protocol P;
422641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth/// \endcode
4227c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4228c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
4229c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
4230c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4231c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
4232c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4233e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
4234e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
4235e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
4236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4237e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
4238e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
4239e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
4240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
4241b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
4242b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
424371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
424471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
424571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
424671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
424771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
424871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
424971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
4250c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
4251c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
4252c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
4253c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4254c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
4255c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
4256c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4257c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4258c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
4259c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4260c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
4261ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCObjectType(QualType Canonical, QualType Base,
4262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
4263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
4265c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
4266561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false, false),
426771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
4268b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
426971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
4270c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
42713536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
4272e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
4273e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
4274e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
4275e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
4276e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
4277e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
4278c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
427971842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
4280c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
4281c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
4282c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4283c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
4284c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
4285c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4286c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
4287c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
4288c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
4289c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
4290c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
4291c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
4292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
4293c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
4294c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4295c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
4296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
4297c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4298c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
4299c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
4300c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
4301c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4302c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
4303c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4304c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
4305c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
4306c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4307c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
43081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4309c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
4310c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
4311b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
431214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4313c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
431473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
431573dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
431673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
431773dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
4318ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4319bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4320bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4321bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4322c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
4323c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
4324c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
4325c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4326c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
4327c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
4328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4329c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
4330c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
4331c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
4332c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
4333c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
4334c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
4335c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4336c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
4337c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
4338c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4339ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
4340c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
4341c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
4342c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
4343c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4344c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
4345c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
43461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
4347c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
4348ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                      ObjCProtocolDecl *const *protocols,
4349ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                      unsigned NumProtocols);
4350c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
43511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4352c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
4353c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
4354c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
4355c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4356c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4357c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
4358c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
4359c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
4360c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
4361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
4362e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
4363e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
4364e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
4365e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
4366e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
4367e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
4368e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
4369e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
4370c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
43718d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor  mutable ObjCInterfaceDecl *Decl;
4372c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4373c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
4374c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
4375c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
4376c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
437756ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor  friend class ASTReader;
43788d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor  friend class ObjCInterfaceDecl;
43791fb0caaa7bef765b85972274e3b434af2572c141John McCall
4380c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
4381e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
4382deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
4383c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4384c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
4385c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
43860b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
43871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
43881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
43893536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
4390a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
4391c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4392c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
4393c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
4394c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
4395c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
4396c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
4397c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
4398c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
4399c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
4400c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
4401c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
4402c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
44033536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
44043536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
4405c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
4406c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
4407c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
4408c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
4409c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
4410c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4411c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4412e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
4413e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
4414e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
4415e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
4416e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
4417e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
441814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
4419e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
4420e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
442114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
4422e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
44231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4424c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
4425561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false, false),
4426c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
442714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
44281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
442914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
4430e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
4431e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
443214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
443314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4434e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
4435e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
4436e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4437e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
4438e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
4439e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
444041c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \code
444141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  ///   \@class A; \@protocol P; \@protocol Q;
4442e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
4443e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
4444e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
4445e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
444641c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \endcode
4447e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
4448e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
4449e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
4450e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
4451e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
4452e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
4453e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
4454e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
4455e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
4456e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
4457e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
4458c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
4459d0370f59e79702ac908c81bf556519f91e9ca297John McCall    return PointeeType->castAs<ObjCObjectType>();
4460c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4461c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4462e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
446341c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// \@interface type, gets the type for that interface.  Any protocol
4464e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
4465e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4466e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
44671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
4468c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
446914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4470e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
447141c2bcff88a23a046ee8d71451bc03717a4248f6Chandler Carruth  /// getInterfaceDecl - If this pointer points to an Objective \@interface
4472e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
4473e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4474e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
447514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
4476e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
447714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4478e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4479e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
4480e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
448114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
4482c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
448314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4484e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4485e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
4486e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
448714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
4488c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
4489de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
4490ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4491e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
4492e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
44931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
4494c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
4495de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
4496e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4497e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
4498e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
4499470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
4500c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
450114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4502e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4503e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
4504e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
4505e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
4506c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
450714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
450871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
4509c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
451071842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4511c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
4512c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
451371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4514c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
451514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4516e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
4517e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
4518c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
4519c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
4520c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
452114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4522e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
4523e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
452473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
4525c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
452673dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
4527ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4528bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4529bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4530bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4531e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
4532e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
4533e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
4534c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4535c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
4536c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
45371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
45381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
453914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
454014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
454114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
45421bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
4543b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanclass AtomicType : public Type, public llvm::FoldingSetNode {
4544b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType ValueType;
4545b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4546b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  AtomicType(QualType ValTy, QualType Canonical)
4547b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    : Type(Atomic, Canonical, ValTy->isDependentType(),
4548b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman           ValTy->isInstantiationDependentType(),
4549b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman           ValTy->isVariablyModifiedType(),
4550b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman           ValTy->containsUnexpandedParameterPack()),
4551b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman      ValueType(ValTy) {}
4552b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  friend class ASTContext;  // ASTContext creates these.
4553b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4554b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  public:
4555b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// getValueType - Gets the type contained by this atomic type, i.e.
4556b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// the type returned by performing an atomic load of this atomic type.
4557b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType getValueType() const { return ValueType; }
4558b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4559b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  bool isSugared() const { return false; }
4560b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType desugar() const { return QualType(this, 0); }
4561b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4562b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
4563b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    Profile(ID, getValueType());
4564b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4565b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4566b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    ID.AddPointer(T.getAsOpaquePtr());
4567b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4568b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  static bool classof(const Type *T) {
4569b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return T->getTypeClass() == Atomic;
4570b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4571b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  static bool classof(const AtomicType *) { return true; }
4572b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman};
4573b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
45740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
45750953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
45760953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
457749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
45780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
45803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// unqualified type.  The qualifiers are assumed to be consistent
45813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with those already in the type.
45823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *strip(QualType type) {
45833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addFastQualifiers(type.getLocalFastQualifiers());
45843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    if (!type.hasLocalNonFastQualifiers())
45853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      return type.getTypePtrUnsafe();
4586ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
45873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    const ExtQuals *extQuals = type.getExtQualsUnsafe();
45883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addConsistentQualifiers(extQuals->getQualifiers());
45893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return extQuals->getBaseType();
45900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
45910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
45934ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, QualType QT) const;
45940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
45964ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, const Type* T) const;
45970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
45980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4600611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
46015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4602200fa53fd420aa8369586f569dbece04930ad6a3John McCallinline SplitQualType SplitQualType::getSingleStepDesugaredType() const {
4603200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType desugar =
4604200fa53fd420aa8369586f569dbece04930ad6a3John McCall    Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
4605200fa53fd420aa8369586f569dbece04930ad6a3John McCall  desugar.Quals.addConsistentQualifiers(Quals);
4606200fa53fd420aa8369586f569dbece04930ad6a3John McCall  return desugar;
4607200fa53fd420aa8369586f569dbece04930ad6a3John McCall}
4608200fa53fd420aa8369586f569dbece04930ad6a3John McCall
46093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const {
46103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getCommonPtr()->BaseType;
46113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const {
46143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return (isNull() ? 0 : getCommonPtr()->BaseType);
46153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const {
46183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!hasLocalNonFastQualifiers())
46193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return SplitQualType(getTypePtrUnsafe(),
46203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                         Qualifiers::fromFastMask(getLocalFastQualifiers()));
46213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQuals *eq = getExtQualsUnsafe();
46233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers qs = eq->getQualifiers();
46243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  qs.addFastQualifiers(getLocalFastQualifiers());
46253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return SplitQualType(eq->getBaseType(), qs);
46263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const {
46293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
46303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (hasLocalNonFastQualifiers())
46313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals = getExtQualsUnsafe()->getQualifiers();
46323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Quals.addFastQualifiers(getLocalFastQualifiers());
46333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return Quals;
46343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const {
46373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
46383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  quals.addFastQualifiers(getLocalFastQualifiers());
46393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return quals;
46403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const {
46433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
46443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  cvr |= getLocalCVRQualifiers();
46453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cvr;
46463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const {
46493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType canon = getCommonPtr()->CanonicalType;
46503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return canon.withFastQualifiers(getLocalFastQualifiers());
46513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
46523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4653467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
46543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getTypePtr()->isCanonicalUnqualified();
4655467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
4656467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
465754e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
46583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isCanonical()) return false;
4659a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
4660ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
466154e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
46623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (T->isVariablyModifiedType() && T->hasSizedVLAType())
46633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return false;
46643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return !isa<FunctionType>(T) && !isa<ArrayType>(T);
466654e14c4db764c0636160d26c5bbf491637c83a76John McCall}
466754e14c4db764c0636160d26c5bbf491637c83a76John McCall
4668fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
4669ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isLocalConstQualified() ||
46703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalConstQualified();
4671fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4672fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4673fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
4674ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isLocalRestrictQualified() ||
46753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalRestrictQualified();
4676fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4677fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4678fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4679fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
4680ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isLocalVolatileQualified() ||
46813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalVolatileQualified();
4682fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4683ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4684fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
4685fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
46863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.hasLocalQualifiers();
4687fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
468862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
468962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const {
469062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
469162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return QualType(getTypePtr(), 0);
469262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
4693200fa53fd420aa8369586f569dbece04930ad6a3John McCall  return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
469462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall}
469562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
469662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const {
469762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
469862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return split();
469962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
470062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getSplitUnqualifiedTypeImpl(*this);
4701fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4702ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
470349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
470449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
47050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
47060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
470749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
470849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
47090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
47100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
471149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
471249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
47130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
47140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
471549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
47166b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
4717c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
47180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
47190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
472049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
4721ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4722ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
4723ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
4724ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
47253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getAddressSpace();
4726ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4727611c1fff195d32df97706e0920c92468b2509900Chris Lattner
4728d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
47290953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
47303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getObjCGCAttr();
4731d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
47322455636163fdd18581d7fdae816433f886d88213Mike Stump
4733264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
4734264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
4735183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
4736264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
4737264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
4738264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
47392455636163fdd18581d7fdae816433f886d88213Mike Stump
4740264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
47412455636163fdd18581d7fdae816433f886d88213Mike Stump}
47421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4743264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
4744264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
4745ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
4746ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
4747e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
4748e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
4749e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
4750e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
4751e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
475262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const {
475362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers myQuals = getQualifiers();
475462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers otherQuals = other.getQualifiers();
475562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals));
4756e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4757e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4758e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
4759e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
4760e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
4761e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
476262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
476362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getQualifiers().compatiblyIncludes(other.getQualifiers());
4764e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4765e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4766e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
4767e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
4768e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
4769e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
4770e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
4771e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
4772e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
4773e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
4774e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
4775e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
47766217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
4777e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
4778e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
4779e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
4780e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4781e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
47822b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregorinline bool QualType::isCForbiddenLValueType() const {
47832b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
47842b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor          getTypePtr()->isFunctionType());
47852b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor}
47862b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
4787aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type.
4788aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4789aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental].
4790aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const {
4791aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isVoidType() ||
4792aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // FIXME: It's really annoying that we don't have an
4793aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // 'isArithmeticType()' which agrees with the standard definition.
4794aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         (isArithmeticType() && !isEnumeralType());
4795aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4796aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4797aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type.
4798aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4799aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound].
4800aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const {
4801aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  // C++0x [basic.compound]p1:
4802aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //   Compound types can be constructed in the following ways:
4803aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- arrays of objects of a given type [...];
4804aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isArrayType() ||
4805aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- functions, which have parameters of given types [...];
4806aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isFunctionType() ||
4807aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to void or objects or functions [...];
4808aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isPointerType() ||
4809aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- references to objects or functions of a given type. [...]
4810aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isReferenceType() ||
4811aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- classes containing a sequence of objects of various types, [...];
4812aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isRecordType() ||
4813ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //    -- unions, which are classes capable of containing objects of different
4814ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //               types at different times;
4815aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isUnionType() ||
4816aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- enumerations, which comprise a set of named constant values. [...];
4817aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isEnumeralType() ||
4818aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to non-static class members, [...].
4819aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isMemberPointerType();
4820aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4821aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4822611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
4823a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
4824611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4825611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
4826a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
4827611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
482858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
482958f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
483058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
48315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
4832a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
48335618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
4834bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
4835a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
4836bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
48377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
4838a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
48397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
48407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
4841a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
48427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
4843498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
4844d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const PointerType *T = getAs<PointerType>())
4845498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
4846498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
4847498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
4848498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
4849f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
4850a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
4851f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4852f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
48536217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
48540bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
4855f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
4856f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
4857f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4858db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
4859db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
48600bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
4861db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
4862db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
4863db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
4864611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
4865a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
4866611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4867c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
4868a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
4869c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4870c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
4871a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
4872c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4873c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
4874a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
4875c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4876898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
4877a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
4878898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
48793ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
48803ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
48813ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4882611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
4883a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
4884611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
48853ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
48863ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
48873ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4888f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
4889a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
4890f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
4891611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
4892a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
4893611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4894213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
4895a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
4896611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4897d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
4898a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
4899d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
4900c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
4901c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
4902368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
4903569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
4904ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isa<ObjCInterfaceType>(CanonicalType) ||
4905569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
4906569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
4907b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmaninline bool Type::isAtomicType() const {
4908b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  return isa<AtomicType>(CanonicalType);
4909b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}
4910569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
4911a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
4912183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4913d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
4914d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
4915d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
4916470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
4917183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4918470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
4919470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
4920470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
492114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
4922183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
492314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
492414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
492514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
492614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
4927183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
492814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
492914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
493014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
493113dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
49328d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
49338d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
493413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
493513dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
4936de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
493713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
4938de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
493972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
4940a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
494172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
494272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
4943e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
4944183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
4945e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
4946e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
4947e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
4948e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
4949e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
49502a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
4951a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
49522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
49532a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
49542a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
49552a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
4956a180f04c091bf3ede4fe292ba6a29d61da09e936John McCallinline const BuiltinType *Type::getAsPlaceholderType() const {
4957a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4958a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall    if (BT->isPlaceholderType())
4959a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall      return BT;
4960a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  return 0;
4961a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall}
4962a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall
4963864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const {
496485def357129b6cdfd69a66ad0e6994506418a2a9John McCall  assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
4965864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4966864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    return (BT->getKind() == (BuiltinType::Kind) K);
4967864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  return false;
4968864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall}
4969864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
497032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCallinline bool Type::isNonOverloadPlaceholderType() const {
497132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
497232509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall    return BT->isNonOverloadPlaceholderType();
497332509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  return false;
497432509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall}
497532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall
4976cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbarinline bool Type::isVoidType() const {
4977cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4978cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar    return BT->getKind() == BuiltinType::Void;
4979cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar  return false;
4980cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar}
4981cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar
4982f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isHalfType() const {
4983f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4984f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() == BuiltinType::Half;
4985f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  // FIXME: Should we allow complex __fp16? Probably not.
4986f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
4987f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4988f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4989f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isNullPtrType() const {
4990f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = getAs<BuiltinType>())
4991f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() == BuiltinType::NullPtr;
4992f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
4993f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4994f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4995f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarextern bool IsEnumDeclComplete(EnumDecl *);
499676e035a529775dc8fd31124f819745a33a085796Daniel Dunbarextern bool IsEnumDeclScoped(EnumDecl *);
499776e035a529775dc8fd31124f819745a33a085796Daniel Dunbar
499876e035a529775dc8fd31124f819745a33a085796Daniel Dunbarinline bool Type::isIntegerType() const {
499976e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
500076e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    return BT->getKind() >= BuiltinType::Bool &&
500176e035a529775dc8fd31124f819745a33a085796Daniel Dunbar           BT->getKind() <= BuiltinType::Int128;
500276e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
500376e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    // Incomplete enum types are not treated as integer types.
500476e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    // FIXME: In C++, enum types are never integer types.
500576e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    return IsEnumDeclComplete(ET->getDecl()) &&
500676e035a529775dc8fd31124f819745a33a085796Daniel Dunbar      !IsEnumDeclScoped(ET->getDecl());
500776e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  }
500876e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  return false;
500976e035a529775dc8fd31124f819745a33a085796Daniel Dunbar}
5010f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
5011f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isScalarType() const {
5012f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5013f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() > BuiltinType::Void &&
5014f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar           BT->getKind() <= BuiltinType::NullPtr;
5015f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
5016f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    // Enums are scalar types, but only if they are defined.  Incomplete enums
5017f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    // are not treated as scalar types.
5018f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return IsEnumDeclComplete(ET->getDecl());
5019f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return isa<PointerType>(CanonicalType) ||
5020f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<BlockPointerType>(CanonicalType) ||
5021f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<MemberPointerType>(CanonicalType) ||
5022f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<ComplexType>(CanonicalType) ||
5023f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<ObjCObjectPointerType>(CanonicalType);
5024f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
5025f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
5026f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isIntegralOrEnumerationType() const {
5027f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5028f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() >= BuiltinType::Bool &&
5029f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar           BT->getKind() <= BuiltinType::Int128;
5030f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
5031f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  // Check for a complete enum type; incomplete enum types are not properly an
5032f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  // enumeration type in the sense required here.
5033f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
5034f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return IsEnumDeclComplete(ET->getDecl());
5035f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
5036f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
5037f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
5038f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
5039f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isBooleanType() const {
5040f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
5041f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() == BuiltinType::Bool;
5042f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
5043f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
5044f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
5045063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
5046063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
5047063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
5048063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
5049904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
5050904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
5051bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth/// \brief Determines whether this type can decay to a pointer type.
5052bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruthinline bool Type::canDecayToPointerType() const {
5053bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth  return isFunctionType() || isArrayType();
5054bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth}
5055bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth
50568958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
50578958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
5058c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
50598958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
50608958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
5061820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
5062c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
5063820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
5064820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
5065d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const {
5066d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *type = this;
5067d0370f59e79702ac908c81bf556519f91e9ca297John McCall  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
5068d0370f59e79702ac908c81bf556519f91e9ca297John McCall    type = arrayType->getElementType().getTypePtr();
5069d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return type;
5070d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
5071d0370f59e79702ac908c81bf556519f91e9ca297John McCall
507222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
507322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
5074d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
5075d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                           QualType T) {
5076d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
5077d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                  DiagnosticsEngine::ak_qualtype);
5078d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  return DB;
5079d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer}
50801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
508147c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
508247c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
5083d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
5084d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                           QualType T) {
5085d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
5086d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                  DiagnosticsEngine::ak_qualtype);
5087d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  return PD;
5088d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer}
508947c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
509089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
509189c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
509289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
509389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
509489c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
509589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
5096ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
509789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
509889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
5099ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5100222bc3c25b12fc0cf55175975dc4c25d7e1fac78James Dennett// Member-template getAs<specific type>'.
51011a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
510289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
510389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
5104ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
51051a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
51061a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
51071a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
51081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51091a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
51100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
51111a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
51121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
51130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
51141a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
5115bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
51161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
511722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
51183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const {
51193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is directly an array type, return it.
51203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this))
51213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return arr;
51223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
51233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If the canonical form of this type isn't the right kind, reject it.
51243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isa<ArrayType>(CanonicalType))
51253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return 0;
51263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
51273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is a typedef for the type, strip the typedef off without
51283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // losing all typedef information.
51293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
51303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
51313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
5132d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const {
5133d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ArrayType_cannot_be_used_with_getAs<T> at;
5134d0370f59e79702ac908c81bf556519f91e9ca297John McCall  (void) at;
5135d0370f59e79702ac908c81bf556519f91e9ca297John McCall
5136d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<T>(CanonicalType));
5137d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const T *ty = dyn_cast<T>(this)) return ty;
5138d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<T>(getUnqualifiedDesugaredType());
5139d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
5140d0370f59e79702ac908c81bf556519f91e9ca297John McCall
5141d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const {
5142d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<ArrayType>(CanonicalType));
5143d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
5144d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
5145d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
5146d0370f59e79702ac908c81bf556519f91e9ca297John McCall
51475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
51485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
51495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
5150