Type.h revision 7ad5c996e9519ed4e9afd1f0166be1cd2be8415a
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
1630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromFastMask(unsigned Mask) {
1640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addFastQualifiers(Mask);
1660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromCVRMask(unsigned CVR) {
1700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.addCVRQualifiers(CVR);
1720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Deserialize qualifiers from an opaque representation.
1760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static Qualifiers fromOpaqueValue(unsigned opaque) {
1770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Qs;
1780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qs.Mask = opaque;
1790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Qs;
1800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Serialize these qualifiers into an opaque representation.
1830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAsOpaqueValue() const {
1840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Mask;
1850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasConst() const { return Mask & Const; }
1880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setConst(bool flag) {
1890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Const) | (flag ? Const : 0);
1900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeConst() { Mask &= ~Const; }
1920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() { Mask |= Const; }
1930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
1940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasVolatile() const { return Mask & Volatile; }
1950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setVolatile(bool flag) {
1960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
1970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
1980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeVolatile() { Mask &= ~Volatile; }
1990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addVolatile() { Mask |= Volatile; }
2000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasRestrict() const { return Mask & Restrict; }
2020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setRestrict(bool flag) {
2030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
2040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeRestrict() { Mask &= ~Restrict; }
2060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addRestrict() { Mask |= Restrict; }
2070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
2090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
2100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setCVRQualifiers(unsigned mask) {
2110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~CVRMask) | mask;
2130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers(unsigned mask) {
2150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeCVRQualifiers() {
2190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeCVRQualifiers(CVRMask);
2200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addCVRQualifiers(unsigned mask) {
2220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
2230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
2240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
2270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
2280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setObjCGCAttr(GC type) {
2290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
2300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
2320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addObjCGCAttr(GC type) {
2330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(type);
2340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setObjCGCAttr(type);
2350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2362234873111009eb8655d63362cedc422eb9fc517John McCall  Qualifiers withoutObjCGCAttr() const {
2372234873111009eb8655d63362cedc422eb9fc517John McCall    Qualifiers qs = *this;
2382234873111009eb8655d63362cedc422eb9fc517John McCall    qs.removeObjCGCAttr();
2392234873111009eb8655d63362cedc422eb9fc517John McCall    return qs;
2402234873111009eb8655d63362cedc422eb9fc517John McCall  }
241200fa53fd420aa8369586f569dbece04930ad6a3John McCall  Qualifiers withoutObjCLifetime() const {
242f85e193739c953358c865005855253af4f68a497John McCall    Qualifiers qs = *this;
243f85e193739c953358c865005855253af4f68a497John McCall    qs.removeObjCLifetime();
244f85e193739c953358c865005855253af4f68a497John McCall    return qs;
245f85e193739c953358c865005855253af4f68a497John McCall  }
2460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
247f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
248f85e193739c953358c865005855253af4f68a497John McCall  ObjCLifetime getObjCLifetime() const {
249f85e193739c953358c865005855253af4f68a497John McCall    return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
250f85e193739c953358c865005855253af4f68a497John McCall  }
251f85e193739c953358c865005855253af4f68a497John McCall  void setObjCLifetime(ObjCLifetime type) {
252f85e193739c953358c865005855253af4f68a497John McCall    Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
253f85e193739c953358c865005855253af4f68a497John McCall  }
254f85e193739c953358c865005855253af4f68a497John McCall  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
255f85e193739c953358c865005855253af4f68a497John McCall  void addObjCLifetime(ObjCLifetime type) {
256f85e193739c953358c865005855253af4f68a497John McCall    assert(type);
257200fa53fd420aa8369586f569dbece04930ad6a3John McCall    assert(!hasObjCLifetime());
258200fa53fd420aa8369586f569dbece04930ad6a3John McCall    Mask |= (type << LifetimeShift);
259f85e193739c953358c865005855253af4f68a497John McCall  }
260f85e193739c953358c865005855253af4f68a497John McCall
261f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is neither None or ExplicitNone.
262f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
263f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
264f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime > OCL_ExplicitNone);
265f85e193739c953358c865005855253af4f68a497John McCall  }
266f85e193739c953358c865005855253af4f68a497John McCall
267f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is either strong or weak.
268f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
269f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
270f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime == OCL_Strong || lifetime == OCL_Weak);
271f85e193739c953358c865005855253af4f68a497John McCall  }
272ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
2740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
2750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setAddressSpace(unsigned space) {
2760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space <= MaxAddressSpace);
2770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~AddressSpaceMask)
2780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall         | (((uint32_t) space) << AddressSpaceShift);
2790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeAddressSpace() { setAddressSpace(0); }
2810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addAddressSpace(unsigned space) {
2820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(space);
2830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    setAddressSpace(space);
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
2860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast qualifiers are those that can be allocated directly
2870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // on a QualType object.
2880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasFastQualifiers() const { return getFastQualifiers(); }
2890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  unsigned getFastQualifiers() const { return Mask & FastMask; }
2900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void setFastQualifiers(unsigned mask) {
2910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask = (Mask & ~FastMask) | mask;
2930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers(unsigned mask) {
2950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
2960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask &= ~mask;
2970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
2980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void removeFastQualifiers() {
2990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    removeFastQualifiers(FastMask);
3000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned mask) {
3020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
3030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Mask |= mask;
3040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasNonFastQualifiers - Return true if the set contains any
3070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// qualifiers which require an ExtQuals node to be allocated.
3080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
3090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getNonFastQualifiers() const {
3100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Qualifiers Quals = *this;
3110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setFastQualifiers(0);
3120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
3130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// hasQualifiers - Return true if the set contains any qualifiers.
3160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool hasQualifiers() const { return Mask; }
3170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool empty() const { return !Mask; }
3180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// \brief Add the qualifiers from the given set to this set.
3200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addQualifiers(Qualifiers Q) {
3210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // If the other set doesn't have any non-boolean qualifiers, just
3220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    // bit-or it in.
3230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    if (!(Q.Mask & ~CVRMask))
3240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= Q.Mask;
3250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    else {
3260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      Mask |= (Q.Mask & CVRMask);
3270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasAddressSpace())
3280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addAddressSpace(Q.getAddressSpace());
3290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall      if (Q.hasObjCGCAttr())
3300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall        addObjCGCAttr(Q.getObjCGCAttr());
331f85e193739c953358c865005855253af4f68a497John McCall      if (Q.hasObjCLifetime())
332f85e193739c953358c865005855253af4f68a497John McCall        addObjCLifetime(Q.getObjCLifetime());
3330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    }
3340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
33662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Add the qualifiers from the given set to this set, given that
33762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// they don't conflict.
33862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  void addConsistentQualifiers(Qualifiers qs) {
33962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getAddressSpace() == qs.getAddressSpace() ||
34062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasAddressSpace() || !qs.hasAddressSpace());
34162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
34262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
343f85e193739c953358c865005855253af4f68a497John McCall    assert(getObjCLifetime() == qs.getObjCLifetime() ||
344f85e193739c953358c865005855253af4f68a497John McCall           !hasObjCLifetime() || !qs.hasObjCLifetime());
34562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    Mask |= qs.Mask;
34662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
34762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
34862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Determines if these qualifiers compatibly include another set.
34962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Generally this answers the question of whether an object with the other
35062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers can be safely used as an object with these qualifiers.
35162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  bool compatiblyIncludes(Qualifiers other) const {
352ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return
353377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // Address spaces must match exactly.
354377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      getAddressSpace() == other.getAddressSpace() &&
355377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // ObjC GC qualifiers can match, be added, or be removed, but can't be
356377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // changed.
357377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (getObjCGCAttr() == other.getObjCGCAttr() ||
358377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor       !hasObjCGCAttr() || !other.hasObjCGCAttr()) &&
359f85e193739c953358c865005855253af4f68a497John McCall      // ObjC lifetime qualifiers must match exactly.
360f85e193739c953358c865005855253af4f68a497John McCall      getObjCLifetime() == other.getObjCLifetime() &&
361377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // CVR qualifiers may subset.
362377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
36362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
36462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
365f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determines if these qualifiers compatibly include another set of
366f85e193739c953358c865005855253af4f68a497John McCall  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
367f85e193739c953358c865005855253af4f68a497John McCall  ///
368f85e193739c953358c865005855253af4f68a497John McCall  /// One set of Objective-C lifetime qualifiers compatibly includes the other
369ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// if the lifetime qualifiers match, or if both are non-__weak and the
370f85e193739c953358c865005855253af4f68a497John McCall  /// including set also contains the 'const' qualifier.
371f85e193739c953358c865005855253af4f68a497John McCall  bool compatiblyIncludesObjCLifetime(Qualifiers other) const {
372f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == other.getObjCLifetime())
373f85e193739c953358c865005855253af4f68a497John McCall      return true;
374ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
375f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
376f85e193739c953358c865005855253af4f68a497John McCall      return false;
377ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
378f85e193739c953358c865005855253af4f68a497John McCall    return hasConst();
379f85e193739c953358c865005855253af4f68a497John McCall  }
380ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
381f85e193739c953358c865005855253af4f68a497John McCall  bool isSupersetOf(Qualifiers Other) const;
382f85e193739c953358c865005855253af4f68a497John McCall
383769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// \brief Determine whether this set of qualifiers is a strict superset of
384769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// another set of qualifiers, not considering qualifier compatibility.
385769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  bool isStrictSupersetOf(Qualifiers Other) const;
386ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
3880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
3890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  operator bool() const { return hasQualifiers(); }
3910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers &operator+=(Qualifiers R) {
3930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addQualifiers(R);
3940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return *this;
3950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
3960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
3970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Union two qualifier sets.  If an enumerated qualifier appears
3980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // in both sets, use the one from the right.
3990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
4000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    L += R;
4010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return L;
4020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
403ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4043cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  Qualifiers &operator-=(Qualifiers R) {
4053cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    Mask = Mask & ~(R.Mask);
4063cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return *this;
4073cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
4080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4093cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  /// \brief Compute the difference between two qualifier sets.
4103cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
4113cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    L -= R;
4123cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor    return L;
4133cdee121daa13403335094ce0e181b9911c2124cDouglas Gregor  }
414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::string getAsString() const;
4167ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  std::string getAsString(const PrintingPolicy &Policy) const;
4177ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
4187ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
4197ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void print(raw_ostream &OS, const PrintingPolicy &Policy,
4207ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis             bool appendSpaceIfNonEmpty = false) const;
4210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
4230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    ID.AddInteger(Mask);
4240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4260953e767ff7817f97b3ab20896b229891eeff45bJohn McCallprivate:
4270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
428f85e193739c953358c865005855253af4f68a497John McCall  // bits:     |0 1 2|3 .. 4|5  ..  7|8   ...   31|
429f85e193739c953358c865005855253af4f68a497John McCall  //           |C R V|GCAttr|Lifetime|AddressSpace|
4300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  uint32_t Mask;
4310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrMask = 0x18;
4330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  static const uint32_t GCAttrShift = 3;
434f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeMask = 0xE0;
435f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeShift = 5;
436f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
437f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceShift = 8;
4380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
4390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
440ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor/// CallingConv - Specifies the calling convention that a function uses.
441ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregorenum CallingConv {
442ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_Default,
443ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_C,           // __attribute__((cdecl))
444ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor  CC_X86StdCall,  // __attribute__((stdcall))
445f813a2c03fcb05381b3252010435f557eb6b3cdeDouglas Gregor  CC_X86FastCall, // __attribute__((fastcall))
44652fc314e1b5e1baee6305067cf831763d02bd243Dawn Perchik  CC_X86ThisCall, // __attribute__((thiscall))
447414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_X86Pascal,   // __attribute__((pascal))
448414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS,       // __attribute__((pcs("aapcs")))
449414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov  CC_AAPCS_VFP    // __attribute__((pcs("aapcs-vfp")))
450ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor};
451ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
452200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// A std::pair-like structure for storing a qualified type split
453200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// into its local qualifiers and its locally-unqualified type.
454200fa53fd420aa8369586f569dbece04930ad6a3John McCallstruct SplitQualType {
455200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// The locally-unqualified type.
456200fa53fd420aa8369586f569dbece04930ad6a3John McCall  const Type *Ty;
457200fa53fd420aa8369586f569dbece04930ad6a3John McCall
458200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// The local qualifiers.
459200fa53fd420aa8369586f569dbece04930ad6a3John McCall  Qualifiers Quals;
460200fa53fd420aa8369586f569dbece04930ad6a3John McCall
461200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType() : Ty(0), Quals() {}
462200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
463200fa53fd420aa8369586f569dbece04930ad6a3John McCall
464200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType getSingleStepDesugaredType() const; // end of this file
465200fa53fd420aa8369586f569dbece04930ad6a3John McCall
466200fa53fd420aa8369586f569dbece04930ad6a3John McCall  // Make llvm::tie work.
467200fa53fd420aa8369586f569dbece04930ad6a3John McCall  operator std::pair<const Type *,Qualifiers>() const {
468200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return std::pair<const Type *,Qualifiers>(Ty, Quals);
469200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
470200fa53fd420aa8369586f569dbece04930ad6a3John McCall
471200fa53fd420aa8369586f569dbece04930ad6a3John McCall  friend bool operator==(SplitQualType a, SplitQualType b) {
472200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return a.Ty == b.Ty && a.Quals == b.Quals;
473200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
474200fa53fd420aa8369586f569dbece04930ad6a3John McCall  friend bool operator!=(SplitQualType a, SplitQualType b) {
475200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return a.Ty != b.Ty || a.Quals != b.Quals;
476200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
477200fa53fd420aa8369586f569dbece04930ad6a3John McCall};
4780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// QualType - For efficiency, we don't store CV-qualified types as nodes on
4800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// their own: instead each reference to a type stores the qualifiers.  This
4810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// greatly reduces the number of nodes we need to allocate for types (for
4820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// example we only need one for 'int', 'const int', 'volatile int',
4830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 'const volatile int', etc).
4840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall///
4850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// As an added efficiency bonus, instead of making this a pair, we
4860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// just store the two bits we care about in the low bits of the
4870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// pointer.  To handle the packing/unpacking, we make QualType be a
4880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// simple wrapper class that acts like a smart pointer.  A third bit
4890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// indicates whether there are extended qualifiers present, in which
4900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// case the pointer points to a special structure.
4910953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualType {
4920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Thankfully, these are efficiently composable.
4930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
4940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall                       Qualifiers::FastWidth> Value;
4950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const ExtQuals *getExtQualsUnsafe() const {
4970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const ExtQuals*>();
4980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
4990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  const Type *getTypePtrUnsafe() const {
5010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().get<const Type*>();
5020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
5030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
5043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQualsTypeCommonBase *getCommonPtr() const {
5053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!isNull() && "Cannot retrieve a NULL type pointer");
5063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    uintptr_t CommonPtrVal
5073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
5083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
5093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
5103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
5113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
5120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  friend class QualifierCollector;
5130953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
5145cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType() {}
5151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5165cf243a883872441d73ca49cea7e20de5802629bChris Lattner  QualType(const Type *Ptr, unsigned Quals)
5170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
5180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType(const ExtQuals *Ptr, unsigned Quals)
5190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    : Value(Ptr, Quals) {}
5200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
521a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
522a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Retrieves a pointer to the underlying (unqualified) type.
5250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// This should really return a const Type, but it's not worth
5260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// changing all the users right now.
5271ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
5281ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
5291ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
5303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtr() const;
531ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtrOrNull() const;
5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5344d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain  /// Retrieves a pointer to the name of the base type.
5354d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain  const IdentifierInfo *getBaseTypeIdentifier() const;
5364d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain
53749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
53849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
5393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  SplitQualType split() const;
54049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
5415cf243a883872441d73ca49cea7e20de5802629bChris Lattner  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
542f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  static QualType getFromOpaquePtr(const void *Ptr) {
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
544f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
548f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type &operator*() const {
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
552f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *operator->() const {
5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
556467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonical() const;
55754e14c4db764c0636160d26c5bbf491637c83a76John McCall  bool isCanonicalAsParam() const;
558467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
5610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Value.getPointer().isNull();
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
564ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether this particular QualType instance has the
565a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "const" qualifier set, without looking through typedefs that may have
566a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "const" at a different level.
567a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalConstQualified() const {
568a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Const);
5690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
570ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
571a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is const-qualified.
572fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isConstQualified() const;
573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
574ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether this particular QualType instance has the
575a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "restrict" qualifier set, without looking through typedefs that may have
576a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "restrict" at a different level.
577a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalRestrictQualified() const {
578a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Restrict);
579a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  }
580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
581a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is restrict-qualified.
582fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isRestrictQualified() const;
583ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
584ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether this particular QualType instance has the
585a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "volatile" qualifier set, without looking through typedefs that may have
586a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// added "volatile" at a different level.
587a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool isLocalVolatileQualified() const {
588f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
591a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type is volatile-qualified.
592fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool isVolatileQualified() const;
593ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
594a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
595ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// qualifiers, without looking through any typedefs that might add
596a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// qualifiers at a different level.
597a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalQualifiers() const {
598a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
5990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
601a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this type has any qualifiers.
602fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  bool hasQualifiers() const;
603ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
604a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Determine whether this particular QualType instance has any
605a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
606a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance.
607a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  bool hasLocalNonFastQualifiers() const {
608a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor    return Value.getPointer().is<const ExtQuals*>();
6090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
611a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers local to this particular QualType
612a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// instance, not including any qualifiers acquired through typedefs or
613a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// other sugar.
6143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getLocalQualifiers() const;
6150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
616a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Retrieve the set of qualifiers applied to this type.
617fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  Qualifiers getQualifiers() const;
618ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
619ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
620a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// local to this particular QualType instance, not including any qualifiers
621a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// acquired through typedefs or other sugar.
622a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  unsigned getLocalCVRQualifiers() const {
623f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
625b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes
626ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
627a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// applied to this type.
628fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  unsigned getCVRQualifiers() const;
629e724246b9f655801bd96b727daf9dddc44beef4dChandler Carruth
630bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isConstant(ASTContext& Ctx) const {
631bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall    return QualType::isConstant(*this, Ctx);
632bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
634f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
635f85e193739c953358c865005855253af4f68a497John McCall  bool isPODType(ASTContext &Context) const;
636f85e193739c953358c865005855253af4f68a497John McCall
637152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// isCXX98PODType() - Return true if this is a POD type according to the
638152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// rules of the C++98 standard, regardless of the current compilation's
639152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// language.
640152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  bool isCXX98PODType(ASTContext &Context) const;
641152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer
642f85e193739c953358c865005855253af4f68a497John McCall  /// isCXX11PODType() - Return true if this is a POD type according to the
643f85e193739c953358c865005855253af4f68a497John McCall  /// more relaxed rules of the C++11 standard, regardless of the current
644f85e193739c953358c865005855253af4f68a497John McCall  /// compilation's language.
645f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
646f85e193739c953358c865005855253af4f68a497John McCall  bool isCXX11PODType(ASTContext &Context) const;
647ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
648f85e193739c953358c865005855253af4f68a497John McCall  /// isTrivialType - Return true if this is a trivial type
649f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
650ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isTrivialType(ASTContext &Context) const;
651f85e193739c953358c865005855253af4f68a497John McCall
652f85e193739c953358c865005855253af4f68a497John McCall  /// isTriviallyCopyableType - Return true if this is a trivially
653f85e193739c953358c865005855253af4f68a497John McCall  /// copyable type (C++0x [basic.types]p9)
654f85e193739c953358c865005855253af4f68a497John McCall  bool isTriviallyCopyableType(ASTContext &Context) const;
655f85e193739c953358c865005855253af4f68a497John McCall
6560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Don't promise in the API that anything besides 'const' can be
6570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // easily added.
6580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
659ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// addConst - add the specified type qualifier to this QualType.
6600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addConst() {
6610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    addFastQualifiers(Qualifiers::Const);
6620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withConst() const {
6640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return withFastQualifiers(Qualifiers::Const);
6650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
667ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// addVolatile - add the specified type qualifier to this QualType.
668308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  void addVolatile() {
669308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    addFastQualifiers(Qualifiers::Volatile);
670308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
671308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  QualType withVolatile() const {
672308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    return withFastQualifiers(Qualifiers::Volatile);
673308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
67418932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek
67518932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  /// Add the restrict qualifier to this QualType.
67618932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  void addRestrict() {
67718932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek    addFastQualifiers(Qualifiers::Restrict);
67818932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  }
67918932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  QualType withRestrict() const {
68018932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek    return withFastQualifiers(Qualifiers::Restrict);
68118932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  }
682308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt
683a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  QualType withCVRQualifiers(unsigned CVR) const {
684a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall    return withFastQualifiers(CVR);
685a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  }
686a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall
6870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  void addFastQualifiers(unsigned TQs) {
6880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(TQs & ~Qualifiers::FastMask)
6890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall           && "non-fast qualifier bits set in mask!");
6900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() | TQs);
6910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
69349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
69449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
69549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
69649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
6970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
69849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
69949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
7000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
7010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Value.setInt(Value.getInt() & ~Mask);
7020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with the given qualifiers in addition to any
7050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // qualifiers already on this type.
7060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  QualType withFastQualifiers(unsigned TQs) const {
7070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
7080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    T.addFastQualifiers(TQs);
7090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
7100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
7111c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta
7120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Creates a type with exactly the given fast qualifiers, removing
7130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // any existing fast qualifiers.
71449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
71549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
7180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Removes fast qualifiers, but leaves any extended qualifiers in place.
71949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
7200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    QualType T = *this;
72149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
7220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return T;
723c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  }
724971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis
7253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType getCanonicalType() const;
7263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
727a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// \brief Return this type with all of the instance-specific qualifiers
728a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// removed, but without removing any qualifiers that may have been applied
729a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  /// through typedefs.
730a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Retrieve the unqualified variant of the given type,
73362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// removing as little sugar as possible.
73462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
73562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// This routine looks through various kinds of sugar to find the
73662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// least-desugared type that is unqualified. For example, given:
73762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
73862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \code
73962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef int Integer;
74062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef const Integer CInteger;
74162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef CInteger DifferenceType;
74262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \endcode
74362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
74462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
74562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
74662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
74762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
74862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
74962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
75062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline QualType getUnqualifiedType() const;
75162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
75262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
75362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// given type, removing as little sugar as possible.
75462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
75562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Like getUnqualifiedType(), but also returns the set of
75662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers that were built up.
75762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
75862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// The resulting type might still be qualified if it's an array
75962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// type.  To strip qualifiers even from within an array type, use
76062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
76162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline SplitQualType getSplitUnqualifiedType() const;
762ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
76361d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is more qualified than the other
76461d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
765e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isMoreQualifiedThan(QualType Other) const;
76661d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
76761d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is at least as qualified as the other
76861d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
769e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  bool isAtLeastAsQualifiedAs(QualType Other) const;
770ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
771e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  QualType getNonReferenceType() const;
7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7736398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
7746398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// specified result type.
775ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ///
7766398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// This routine should be used for expressions for which the return type is
7776398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
778ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// an lvalue. It removes a top-level reference (since there are no
7795291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
7805291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// from non-class types (in C++) or all types (in C).
7816398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor  QualType getNonLValueExprType(ASTContext &Context) const;
782ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7832fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
7842fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
7852fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
7862fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
7872fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
7882fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner  /// concrete.
7890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  ///
7900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Qualifiers are left in place.
7914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getDesugaredType(const ASTContext &Context) const {
79249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
79349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
79449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
79549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
79649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
797bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
79898cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
799f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// \brief Return the specified type with one level of "sugar" removed from
800ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// the type.
801f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  ///
802f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// This routine takes off the first typedef, typeof, etc. If the outer level
803f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// of the type is already concrete, it returns it unmodified.
804200fa53fd420aa8369586f569dbece04930ad6a3John McCall  QualType getSingleStepDesugaredType(const ASTContext &Context) const {
805200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getSingleStepDesugaredTypeImpl(*this, Context);
806200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
807ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
808075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
809075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
810075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
811723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
812723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
813723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
814075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
815075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
81850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator==(const QualType &LHS, const QualType &RHS) {
81950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value == RHS.Value;
8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
82150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
82250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor    return LHS.Value != RHS.Value;
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
82449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
82549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
82649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
82749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
828200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getAsString(split.Ty, split.Quals);
82949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
83049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
831d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor
8327ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  std::string getAsString(const PrintingPolicy &Policy) const;
8337ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
8347ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void print(raw_ostream &OS, const PrintingPolicy &Policy,
8357ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis             const Twine &PlaceHolder = Twine()) const {
8367ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    print(split(), OS, Policy, PlaceHolder);
8377ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  }
8387ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void print(SplitQualType split, raw_ostream &OS,
8397ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                    const PrintingPolicy &policy, const Twine &PlaceHolder) {
8407ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    return print(split.Ty, split.Quals, OS, policy, PlaceHolder);
8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8427ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void print(const Type *ty, Qualifiers qs,
8437ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                    raw_ostream &OS, const PrintingPolicy &policy,
8447ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                    const Twine &PlaceHolder);
8457ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
846e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner  void getAsStringInternal(std::string &Str,
84749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                           const PrintingPolicy &Policy) const {
84849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsStringInternal(split(), Str, Policy);
84949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
85049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(SplitQualType split, std::string &out,
85149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy) {
852200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getAsStringInternal(split.Ty, split.Quals, out, policy);
85349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
85449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static void getAsStringInternal(const Type *ty, Qualifiers qs,
85549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  std::string &out,
85649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall                                  const PrintingPolicy &policy);
8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8587ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  class StreamedQualTypeHelper {
8597ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    const QualType &T;
8607ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    const PrintingPolicy &Policy;
8617ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    const Twine &PlaceHolder;
8627ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  public:
8637ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy,
8647ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                           const Twine &PlaceHolder)
8657ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis      : T(T), Policy(Policy), PlaceHolder(PlaceHolder) { }
8667ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
8677ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    friend raw_ostream &operator<<(raw_ostream &OS,
8687ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                   const StreamedQualTypeHelper &SQT) {
8697ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis      SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder);
8707ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis      return OS;
8717ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    }
8727ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  };
8737ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
8747ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  StreamedQualTypeHelper stream(const PrintingPolicy &Policy,
8757ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                const Twine &PlaceHolder = Twine()) const {
8767ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    return StreamedQualTypeHelper(*this, Policy, PlaceHolder);
8777ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  }
8787ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
879c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump(const char *s) const;
880c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner  void dump() const;
8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8823f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) const {
8833f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek    ID.AddPointer(getAsOpaquePtr());
8843f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek  }
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
886ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// getAddressSpace - Return the address space of this type.
887ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  inline unsigned getAddressSpace() const;
8881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
889f85e193739c953358c865005855253af4f68a497John McCall  /// getObjCGCAttr - Returns gc attribute of this type.
8900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  inline Qualifiers::GC getObjCGCAttr() const;
891f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
892f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCWeak true when Type is objc's weak.
893f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCWeak() const {
8940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Weak;
895f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
896f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian
897f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  /// isObjCGCStrong true when Type is objc's strong.
898f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  bool isObjCGCStrong() const {
8990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return getObjCGCAttr() == Qualifiers::Strong;
900f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian  }
9012455636163fdd18581d7fdae816433f886d88213Mike Stump
902f85e193739c953358c865005855253af4f68a497John McCall  /// getObjCLifetime - Returns lifetime attribute of this type.
903f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCLifetime() const {
904f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().getObjCLifetime();
905f85e193739c953358c865005855253af4f68a497John McCall  }
906f85e193739c953358c865005855253af4f68a497John McCall
907f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
908f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().hasNonTrivialObjCLifetime();
909f85e193739c953358c865005855253af4f68a497John McCall  }
910f85e193739c953358c865005855253af4f68a497John McCall
911f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
912f85e193739c953358c865005855253af4f68a497John McCall    return getQualifiers().hasStrongOrWeakObjCLifetime();
913f85e193739c953358c865005855253af4f68a497John McCall  }
914f85e193739c953358c865005855253af4f68a497John McCall
9150d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  enum DestructionKind {
9160d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    DK_none,
917f85e193739c953358c865005855253af4f68a497John McCall    DK_cxx_destructor,
918f85e193739c953358c865005855253af4f68a497John McCall    DK_objc_strong_lifetime,
919f85e193739c953358c865005855253af4f68a497John McCall    DK_objc_weak_lifetime
9200d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  };
9210d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
9220d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// isDestructedType - nonzero if objects of this type require
9230d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// non-trivial work to clean up after.  Non-zero because it's
9240d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// conceivable that qualifiers (objc_gc(weak)?) could make
9250d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  /// something require destruction.
9260d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  DestructionKind isDestructedType() const {
9270d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall    return isDestructedTypeImpl(*this);
9280d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  }
9290d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall
930ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Determine whether expressions of the given type are forbidden
9312b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// from being lvalues in C.
9322b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///
9332b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// The expression types that are forbidden to be lvalues are:
9342b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   - 'void', but not qualified void
9352b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   - function types
9362b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///
9372b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  /// The exact rule here is C99 6.3.2.1:
9382b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   An lvalue is an expression with an object type or an incomplete
9392b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  ///   type other than void.
9402b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  bool isCForbiddenLValueType() const;
9412b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
94285ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl  /// \brief Determine whether this type has trivial copy/move-assignment
94385ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl  ///        semantics.
94485ea7aa961deac1d754f610af8062ae3f8b4e2a5Sebastian Redl  bool hasTrivialAssignment(ASTContext &Context, bool Copying) const;
945ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
946bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCallprivate:
947bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // These methods are implemented in a separate translation unit;
948bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // "static"-ize them to avoid creating temporary QualTypes in the
949bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  // caller.
950bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  static bool isConstant(QualType T, ASTContext& Ctx);
9514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static QualType getDesugaredType(QualType T, const ASTContext &Context);
95249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static SplitQualType getSplitDesugaredType(QualType T);
95362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
954200fa53fd420aa8369586f569dbece04930ad6a3John McCall  static QualType getSingleStepDesugaredTypeImpl(QualType type,
955200fa53fd420aa8369586f569dbece04930ad6a3John McCall                                                 const ASTContext &C);
956075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static QualType IgnoreParens(QualType T);
9570d70d71ccbc4f7f59cadb759f61b7172a149676cJohn McCall  static DestructionKind isDestructedTypeImpl(QualType type);
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
966f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  typedef const ::clang::Type *SimpleType;
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
9684472fc641ea3069463798fb56a04043c28ea2910Douglas Gregor    return Val.getTypePtr();
9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9744e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer".
9754e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<>
976daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> {
9774e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic:
9784e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline void *getAsVoidPointer(clang::QualType P) {
9794e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return P.getAsOpaquePtr();
9804e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
9814e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  static inline clang::QualType getFromVoidPointer(void *P) {
9824e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner    return clang::QualType::getFromOpaquePtr(P);
9834e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner  }
9840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Various qualifiers go in low bits.
9850eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner  enum { NumLowBitsAvailable = 0 };
9864e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner};
9871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
992ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief Base class that is common to both the \c ExtQuals and \c Type
9933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// classes, which allows \c QualType to access the common fields between the
9943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// two.
9953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
9963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQualsTypeCommonBase {
9973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
9983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : BaseType(baseType), CanonicalType(canon) {}
9993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The "base" type of an extended qualifiers type (\c ExtQuals) or
10013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// a self-referential pointer (for \c Type).
10023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ///
1003ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This pointer allows an efficient mapping from a QualType to its
10043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// underlying type pointer.
10053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *const BaseType;
10063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief The canonical type of this type.  A QualType.
10083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType CanonicalType;
10093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class QualType;
10113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class Type;
10123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  friend class ExtQuals;
10133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
1014ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// ExtQuals - We can encode up to four bits in the low bits of a
10163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// type pointer, but there are many more type qualifiers that we want
10173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// to be able to apply to an arbitrary type.  Therefore we have this
10183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// struct, intended to be heap-allocated and used by QualType to
10193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// store qualifiers.
10203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall///
1021ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
10223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// in three low bits on the QualType pointer; a fourth bit records whether
10233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
10243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall/// Objective-C GC attributes) are much more rare.
10253b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallclass ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
10263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // NOTE: changing the fast qualifiers should be straightforward as
10273b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // long as you don't make 'const' non-fast.
10283b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 1. Qualifiers:
10293b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
10303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       Fast qualifiers must occupy the low-order bits.
10313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update Qualifiers::FastWidth and FastMask.
10323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 2. QualType:
10333b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update is{Volatile,Restrict}Qualified(), defined inline.
10343b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    b) Update remove{Volatile,Restrict}, defined near the end of
10353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //       this header.
10363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // 3. ASTContext:
10373b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  //    a) Update get{Volatile,Restrict}Type.
10383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Quals - the immutable set of qualifiers applied by this
10403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// node;  always contains extended qualifiers.
10413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
10423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  ExtQuals *this_() { return this; }
10443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
1046ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
10473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(baseType,
10483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon),
10493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      Quals(quals)
10503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  {
10513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(Quals.hasNonFastQualifiers()
10523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with no fast qualifiers");
10533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers()
10543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall           && "ExtQuals created with fast qualifiers");
10553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
10563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getQualifiers() const { return Quals; }
10583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
10603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
10613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1062f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1063f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCLifetime() const {
1064f85e193739c953358c865005855253af4f68a497John McCall    return Quals.getObjCLifetime();
1065f85e193739c953358c865005855253af4f68a497John McCall  }
1066f85e193739c953358c865005855253af4f68a497John McCall
10673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
10683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
10693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getBaseType() const { return BaseType; }
10713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
10723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallpublic:
10733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  void Profile(llvm::FoldingSetNodeID &ID) const {
10743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Profile(ID, getBaseType(), Quals);
10753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
10763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
10773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      const Type *BaseType,
10783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                      Qualifiers Quals) {
10793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
10803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    ID.AddPointer(BaseType);
10813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals.Profile(ID);
10823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
10833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall};
10843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1085ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// \brief The kind of C++0x ref-qualifier associated with a function type,
1086ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// which determines whether a member function's "this" object can be an
1087c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor/// lvalue, rvalue, or neither.
1088c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregorenum RefQualifierKind {
1089c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief No ref-qualifier was provided.
1090c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_None = 0,
1091c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An lvalue ref-qualifier was provided (\c &).
1092c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_LValue,
1093c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief An rvalue ref-qualifier was provided (\c &&).
1094c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RQ_RValue
1095c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor};
1096ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
110872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
111172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
11221ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregorclass Type : public ExtQualsTypeCommonBase {
11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
112572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class,
112627935ee59c30b0d8b610ab676aab8e65350af932John McCall#define LAST_TYPE(Class) TypeLast = Class,
112772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base)
112872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def"
112972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    TagFirst = Record, TagLast = Enum
11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
11311bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1133c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  Type(const Type&);           // DO NOT IMPLEMENT.
1134c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  void operator=(const Type&); // DO NOT IMPLEMENT.
1135c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
1136b870b88df784c2940efce448ebfaf54dece14666John McCall  /// Bitfields required by the Type class.
1137b870b88df784c2940efce448ebfaf54dece14666John McCall  class TypeBitfields {
1138b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class Type;
1139b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall    template <class T> friend class TypePropertyCache;
114027935ee59c30b0d8b610ab676aab8e65350af932John McCall
1141b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1142b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TC : 8;
1143b870b88df784c2940efce448ebfaf54dece14666John McCall
1144b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
1145b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Note that this should stay at the end of the ivars for Type so that
1146b870b88df784c2940efce448ebfaf54dece14666John McCall    /// subclasses can pack their bitfields into the same word.
1147bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned Dependent : 1;
1148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1149ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    /// \brief Whether this type somehow involves a template parameter, even
1150561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    /// if the resolution of the type does not depend on a template parameter.
1151561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    unsigned InstantiationDependent : 1;
1152ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1153b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1154bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned VariablyModified : 1;
1155d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
1156d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// \brief Whether this type contains an unexpanded parameter pack
1157d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /// (for C++0x variadic templates).
1158d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    unsigned ContainsUnexpandedParameterPack : 1;
1159ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
11601fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// \brief Nonzero if the cache (i.e. the bitfields here starting
11611fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// with 'Cache') is valid.  If so, then this is a
11621fb0caaa7bef765b85972274e3b434af2572c141John McCall    /// LangOptions::VisibilityMode+1.
11631fb0caaa7bef765b85972274e3b434af2572c141John McCall    mutable unsigned CacheValidAndVisibility : 2;
1164ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1165093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    /// \brief True if the visibility was set explicitly in the source code.
1166093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    mutable unsigned CachedExplicitVisibility : 1;
1167093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola
1168b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief Linkage of this type.
1169b870b88df784c2940efce448ebfaf54dece14666John McCall    mutable unsigned CachedLinkage : 2;
117007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1171ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    /// \brief Whether this type involves and local or unnamed types.
1172bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned CachedLocalOrUnnamed : 1;
1173ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1174b870b88df784c2940efce448ebfaf54dece14666John McCall    /// \brief FromAST - Whether this type comes from an AST file.
1175bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    mutable unsigned FromAST : 1;
1176b870b88df784c2940efce448ebfaf54dece14666John McCall
11771fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool isCacheValid() const {
11781fb0caaa7bef765b85972274e3b434af2572c141John McCall      return (CacheValidAndVisibility != 0);
11791fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
11801fb0caaa7bef765b85972274e3b434af2572c141John McCall    Visibility getVisibility() const {
11811fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
11821fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Visibility>(CacheValidAndVisibility-1);
11831fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
1184093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    bool isVisibilityExplicit() const {
1185093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola      assert(isCacheValid() && "getting linkage from invalid cache");
1186093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola      return CachedExplicitVisibility;
1187093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    }
11881fb0caaa7bef765b85972274e3b434af2572c141John McCall    Linkage getLinkage() const {
11891fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
11901fb0caaa7bef765b85972274e3b434af2572c141John McCall      return static_cast<Linkage>(CachedLinkage);
11911fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
11921fb0caaa7bef765b85972274e3b434af2572c141John McCall    bool hasLocalOrUnnamedType() const {
11931fb0caaa7bef765b85972274e3b434af2572c141John McCall      assert(isCacheValid() && "getting linkage from invalid cache");
11941fb0caaa7bef765b85972274e3b434af2572c141John McCall      return CachedLocalOrUnnamed;
11951fb0caaa7bef765b85972274e3b434af2572c141John McCall    }
1196b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1197093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola  enum { NumTypeBits = 19 };
1198b870b88df784c2940efce448ebfaf54dece14666John McCall
1199b870b88df784c2940efce448ebfaf54dece14666John McCallprotected:
1200b870b88df784c2940efce448ebfaf54dece14666John McCall  // These classes allow subclasses to somewhat cleanly pack bitfields
1201b870b88df784c2940efce448ebfaf54dece14666John McCall  // into Type.
1202b870b88df784c2940efce448ebfaf54dece14666John McCall
1203b870b88df784c2940efce448ebfaf54dece14666John McCall  class ArrayTypeBitfields {
1204b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ArrayType;
1205b870b88df784c2940efce448ebfaf54dece14666John McCall
1206b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1207b870b88df784c2940efce448ebfaf54dece14666John McCall
1208b870b88df784c2940efce448ebfaf54dece14666John McCall    /// IndexTypeQuals - CVR qualifiers from declarations like
1209b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
1210b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned IndexTypeQuals : 3;
1211b870b88df784c2940efce448ebfaf54dece14666John McCall
1212b870b88df784c2940efce448ebfaf54dece14666John McCall    /// SizeModifier - storage class qualifiers from declarations like
1213b870b88df784c2940efce448ebfaf54dece14666John McCall    /// 'int X[static restrict 4]'. For function parameters only.
1214b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Actually an ArrayType::ArraySizeModifier.
1215b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned SizeModifier : 3;
1216b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1217b870b88df784c2940efce448ebfaf54dece14666John McCall
1218b870b88df784c2940efce448ebfaf54dece14666John McCall  class BuiltinTypeBitfields {
1219b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class BuiltinType;
1220b870b88df784c2940efce448ebfaf54dece14666John McCall
1221b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1222b870b88df784c2940efce448ebfaf54dece14666John McCall
1223b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The kind (BuiltinType::Kind) of builtin type this is.
1224b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned Kind : 8;
1225b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1226b870b88df784c2940efce448ebfaf54dece14666John McCall
1227b870b88df784c2940efce448ebfaf54dece14666John McCall  class FunctionTypeBitfields {
1228b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class FunctionType;
1229b870b88df784c2940efce448ebfaf54dece14666John McCall
1230b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1231b870b88df784c2940efce448ebfaf54dece14666John McCall
1232b870b88df784c2940efce448ebfaf54dece14666John McCall    /// Extra information which affects how the function is called, like
1233b870b88df784c2940efce448ebfaf54dece14666John McCall    /// regparm and the calling convention.
12347e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    unsigned ExtInfo : 8;
1235b870b88df784c2940efce448ebfaf54dece14666John McCall
1236b870b88df784c2940efce448ebfaf54dece14666John McCall    /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1237b870b88df784c2940efce448ebfaf54dece14666John McCall    /// other bitfields.
1238b870b88df784c2940efce448ebfaf54dece14666John McCall    /// The qualifiers are part of FunctionProtoType because...
1239b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1240b870b88df784c2940efce448ebfaf54dece14666John McCall    /// C++ 8.3.5p4: The return type, the parameter type list and the
1241b870b88df784c2940efce448ebfaf54dece14666John McCall    /// cv-qualifier-seq, [...], are part of the function type.
1242b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned TypeQuals : 3;
1243ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1244c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// \brief The ref-qualifier associated with a \c FunctionProtoType.
1245c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    ///
1246c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    /// This is a value of type \c RefQualifierKind.
1247c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    unsigned RefQualifier : 2;
1248b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1249b870b88df784c2940efce448ebfaf54dece14666John McCall
1250b870b88df784c2940efce448ebfaf54dece14666John McCall  class ObjCObjectTypeBitfields {
1251b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ObjCObjectType;
1252b870b88df784c2940efce448ebfaf54dece14666John McCall
1253b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1254b870b88df784c2940efce448ebfaf54dece14666John McCall
1255b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumProtocols - The number of protocols stored directly on this
1256b870b88df784c2940efce448ebfaf54dece14666John McCall    /// object type.
1257b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned NumProtocols : 32 - NumTypeBits;
1258b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1259b870b88df784c2940efce448ebfaf54dece14666John McCall
1260b870b88df784c2940efce448ebfaf54dece14666John McCall  class ReferenceTypeBitfields {
1261b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class ReferenceType;
1262b870b88df784c2940efce448ebfaf54dece14666John McCall
1263b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
1264b870b88df784c2940efce448ebfaf54dece14666John McCall
1265b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the type was originally spelled with an lvalue sigil.
1266b870b88df784c2940efce448ebfaf54dece14666John McCall    /// This is never true of rvalue references but can also be false
1267b870b88df784c2940efce448ebfaf54dece14666John McCall    /// on lvalue references because of C++0x [dcl.typedef]p9,
1268b870b88df784c2940efce448ebfaf54dece14666John McCall    /// as follows:
1269b870b88df784c2940efce448ebfaf54dece14666John McCall    ///
1270b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &ref;    // lvalue, spelled lvalue
1271b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   typedef int &&rvref; // rvalue
1272b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &a;              // lvalue, inner ref, spelled lvalue
1273b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   ref &&a;             // lvalue, inner ref
1274b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &a;            // lvalue, inner ref, spelled lvalue
1275b870b88df784c2940efce448ebfaf54dece14666John McCall    ///   rvref &&a;           // rvalue, inner ref
1276bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned SpelledAsLValue : 1;
1277b870b88df784c2940efce448ebfaf54dece14666John McCall
1278b870b88df784c2940efce448ebfaf54dece14666John McCall    /// True if the inner type is a reference type.  This only happens
1279b870b88df784c2940efce448ebfaf54dece14666John McCall    /// in non-canonical forms.
1280bdb5b0e8ad8ed297ad01eb2ccd0d6d5ed6058033Francois Pichet    unsigned InnerRef : 1;
1281b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1282b870b88df784c2940efce448ebfaf54dece14666John McCall
128377be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  class TypeWithKeywordBitfields {
128477be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    friend class TypeWithKeyword;
128577be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
128677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned : NumTypeBits;
128777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
128877be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    /// An ElaboratedTypeKeyword.  8 bits for efficient access.
128977be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    unsigned Keyword : 8;
129077be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  };
129177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall
1292b870b88df784c2940efce448ebfaf54dece14666John McCall  class VectorTypeBitfields {
1293b870b88df784c2940efce448ebfaf54dece14666John McCall    friend class VectorType;
129407a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1295b870b88df784c2940efce448ebfaf54dece14666John McCall    unsigned : NumTypeBits;
129671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
1297e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// VecKind - The kind of vector, either a generic vector type or some
1298e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    /// target-specific vector type such as for AltiVec or Neon.
1299cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned VecKind : 3;
1300b870b88df784c2940efce448ebfaf54dece14666John McCall
1301b870b88df784c2940efce448ebfaf54dece14666John McCall    /// NumElements - The number of elements in the vector.
1302cc3b946c35c4372272034e6f0663089477a9a5bdBob Wilson    unsigned NumElements : 29 - NumTypeBits;
1303b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1304b870b88df784c2940efce448ebfaf54dece14666John McCall
13059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  class AttributedTypeBitfields {
13069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    friend class AttributedType;
13079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
13089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned : NumTypeBits;
13099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
13109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    /// AttrKind - an AttributedType::Kind
13119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    unsigned AttrKind : 32 - NumTypeBits;
13129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
13139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
1314b870b88df784c2940efce448ebfaf54dece14666John McCall  union {
1315b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBitfields TypeBits;
1316b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBitfields ArrayTypeBits;
13179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBitfields AttributedTypeBits;
1318b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBitfields BuiltinTypeBits;
1319b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBitfields FunctionTypeBits;
1320b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBitfields ObjCObjectTypeBits;
1321b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBitfields ReferenceTypeBits;
132277be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBitfields TypeWithKeywordBits;
1323b870b88df784c2940efce448ebfaf54dece14666John McCall    VectorTypeBitfields VectorTypeBits;
1324b870b88df784c2940efce448ebfaf54dece14666John McCall  };
1325b870b88df784c2940efce448ebfaf54dece14666John McCall
1326b870b88df784c2940efce448ebfaf54dece14666John McCallprivate:
13273c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set whether this type comes from an AST file.
1328ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setFromAST(bool V = true) const {
1329b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = V;
133007a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl  }
133107a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1332b7b2688bab0eac053d3e2938b329c8e523fd252bJohn McCall  template <class T> friend class TypePropertyCache;
13331fb0caaa7bef765b85972274e3b434af2572c141John McCall
13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
1335124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
1336124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
1337ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  Type(TypeClass tc, QualType canon, bool Dependent,
1338561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor       bool InstantiationDependent, bool VariablyModified,
1339d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor       bool ContainsUnexpandedParameterPack)
13403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    : ExtQualsTypeCommonBase(this,
13413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                             canon.isNull() ? QualType(this_(), 0) : canon) {
1342b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.TC = tc;
1343b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.Dependent = Dependent;
1344561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    TypeBits.InstantiationDependent = Dependent || InstantiationDependent;
1345b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.VariablyModified = VariablyModified;
1346d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
13471fb0caaa7bef765b85972274e3b434af2572c141John McCall    TypeBits.CacheValidAndVisibility = 0;
1348093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola    TypeBits.CachedExplicitVisibility = false;
1349b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLocalOrUnnamed = false;
1350b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.CachedLinkage = NoLinkage;
1351b870b88df784c2940efce448ebfaf54dece14666John McCall    TypeBits.FromAST = false;
1352b870b88df784c2940efce448ebfaf54dece14666John McCall  }
13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
13541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1355ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setDependent(bool D = true) {
1356ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    TypeBits.Dependent = D;
1357561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    if (D)
1358561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor      TypeBits.InstantiationDependent = true;
1359561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1360ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setInstantiationDependent(bool D = true) {
1361561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    TypeBits.InstantiationDependent = D; }
1362ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  void setVariablyModified(bool VM = true) { TypeBits.VariablyModified = VM;
1363561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1364d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  void setContainsUnexpandedParameterPack(bool PP = true) {
1365d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    TypeBits.ContainsUnexpandedParameterPack = PP;
1366d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1367d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
13688b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
1369b870b88df784c2940efce448ebfaf54dece14666John McCall  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
13701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13713c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Whether this type comes from an AST file.
1372b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isFromAST() const { return TypeBits.FromAST; }
137307a353c2af3a3c557205466d4f4ed2513462ebfeSebastian Redl
1374d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Whether this type is or contains an unexpanded parameter
1375d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// pack, used to support C++0x variadic templates.
1376d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1377d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// A type that contains a parameter pack shall be expanded by the
1378d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// ellipsis operator at some point. For example, the typedef in the
1379d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// following example contains an unexpanded parameter pack 'T':
1380d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1381d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \code
1382d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// template<typename ...T>
1383d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// struct X {
1384d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///   typedef T* pointer_types; // ill-formed; T is a parameter pack.
1385d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// };
1386d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \endcode
1387d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  ///
1388ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Note that this routine does not specify which
1389ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool containsUnexpandedParameterPack() const {
1390d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return TypeBits.ContainsUnexpandedParameterPack;
1391d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
1392d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
13933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// Determines if this type would be canonical if it had no further
13943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualification.
1395467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  bool isCanonicalUnqualified() const {
13963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return CanonicalType == QualType(this, 0);
1397467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall  }
13985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1399200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// Pull a single level of sugar off of this locally-unqualified type.
1400200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
1401200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
1402200fa53fd420aa8369586f569dbece04930ad6a3John McCall  QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
1403200fa53fd420aa8369586f569dbece04930ad6a3John McCall
14041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
14055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
14061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
14101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// routine will need to determine if the size is actually required.
1411d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  ///
1412d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  /// \brief Def If non-NULL, and the type refers to some kind of declaration
1413d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  /// that can be completed (such as a C struct, C++ class, or Objective-C
1414d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  /// class), will be set to the declaration.
1415d07cc36c71558b62889691184dd04655a33fd12aDouglas Gregor  bool isIncompleteType(NamedDecl **Def = 0) const;
1416d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner
1417d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
1418d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  /// type, in other words, not a function type.
1419d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  bool isIncompleteOrObjectType() const {
1420d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner    return !isFunctionType();
1421d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner  }
1422ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14232fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  /// \brief Determine whether this type is an object type.
14242fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  bool isObjectType() const {
14252fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    // C++ [basic.types]p8:
1426ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    //   An object type is a (possibly cv-qualified) type that is not a
14272fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    //   function type, not a reference type, and not a void type.
14282fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor    return !isReferenceType() && !isFunctionType() && !isVoidType();
14292fdc5e8199e1e239620f2faae88997153703e16fDouglas Gregor  }
143064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl
1431ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// isLiteralType - Return true if this is a literal type
1432ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  /// (C++0x [basic.types]p10)
1433ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl  bool isLiteralType() const;
1434ccf43505dbc47da041c06125f90b3bd3ac7eac97Sebastian Redl
1435636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// \brief Test if this type is a standard-layout type.
1436636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  /// (C++0x [basic.type]p9)
1437636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth  bool isStandardLayoutType() const;
1438636a617cc6021a4366380b3ce673f4472f3d99dbChandler Carruth
14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
1440ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  /// operate on the canonical type, ignoring typedefs and qualifiers.
1441e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
14429b065ddabf572772991a4aadad5bf4921fac5069Tom Care  /// isBuiltinType - returns true if the type is a builtin type.
14439b065ddabf572772991a4aadad5bf4921fac5069Tom Care  bool isBuiltinType() const;
14449b065ddabf572772991a4aadad5bf4921fac5069Tom Care
1445e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  /// isSpecificBuiltinType - Test for a particular builtin type.
1446e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  bool isSpecificBuiltinType(unsigned K) const;
14471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14482a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// isPlaceholderType - Test for a type which does not represent an
14492a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// actual type-system type but is instead used as a placeholder for
14502a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// various convenient purposes within Clang.  All such types are
14512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  /// BuiltinTypes.
14522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const;
1453a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  const BuiltinType *getAsPlaceholderType() const;
14542a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
1455864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// isSpecificPlaceholderType - Test for a specific placeholder type.
1456864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  bool isSpecificPlaceholderType(unsigned K) const;
1457864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
145832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// isNonOverloadPlaceholderType - Test for a placeholder type
145932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// other than Overload;  see BuiltinType::isNonOverloadPlaceholderType.
146032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  bool isNonOverloadPlaceholderType() const;
146132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall
146296d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isIntegerType() does *not* include complex integers (a GCC extension).
146396d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
14645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
146513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
146613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
146713b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
146877a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor  bool isWideCharType() const;
14695cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isChar16Type() const;
14705cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor  bool isChar32Type() const;
147120093b4bf698f292c664676987541d5103b65b15Douglas Gregor  bool isAnyCharacterType() const;
14729d3347a5887d2d25afe8b0bd35783a72ec86cce2Douglas Gregor  bool isIntegralType(ASTContext &Ctx) const;
1473ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14742ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  /// \brief Determine whether this type is an integral or enumeration type.
14752ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor  bool isIntegralOrEnumerationType() const;
14761274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// \brief Determine whether this type is an integral or unscoped enumeration
14771274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  /// type.
14781274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor  bool isIntegralOrUnscopedEnumerationType() const;
1479ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
148202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexType() does *not* include complex integers (a GCC extension).
148302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff  /// isComplexIntegerType() can be used to test for complex integers.
14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
1485f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
1487aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov  bool isHalfType() const;         // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
1490c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
1491c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
1492c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
1493d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor  bool isAggregateType() const;
1494aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isFundamentalType() const;
1495aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  bool isCompoundType() const;
14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1497c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
1498ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb  // type, ignoring typedefs and qualifiers.
1499c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
1500183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
1501183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
1502befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
150358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
15045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  bool isBlockPointerType() const;
15057154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff  bool isVoidPointerType() const;
1506a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
15077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isLValueReferenceType() const;
15087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  bool isRValueReferenceType() const;
1509bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  bool isFunctionPointerType() const;
1510f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberPointerType() const;
1511f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  bool isMemberFunctionPointerType() const;
1512db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  bool isMemberDataPointerType() const;
1513c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
1514c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isConstantArrayType() const;
1515c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isIncompleteArrayType() const;
1516c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  bool isVariableArrayType() const;
1517898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  bool isDependentSizedArrayType() const;
1518c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isClassType() const;
15201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isStructureType() const;
1521fb87b89fc9eb103e19fb8e4b925c23f0bd091b99Douglas Gregor  bool isStructureOrClassType() const;
15224cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  bool isUnionType() const;
1523368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isComplexIntegerType() const;            // GCC _Complex integer type.
1524368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isVectorType() const;                    // GCC vector type.
1525213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  bool isExtVectorType() const;                 // Extended vector type.
1526f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCObjectPointerType() const;         // pointer to ObjC object
1527f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCRetainableType() const;            // ObjC object or block pointer
1528f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCLifetimeType() const;              // (array of)* retainable type
1529f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCIndirectLifetimeType() const;      // (pointer to)* lifetime type
1530f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCNSObjectType() const;              // __attribute__((NSObject))
153114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
153214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for the common case.
1533c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCObjectType() const;                // NSString or typeof(*(id)0)
1534368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
1535368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner  bool isObjCQualifiedIdType() const;           // id<foo>
1536470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const;        // Class<foo>
1537569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor  bool isObjCObjectOrInterfaceType() const;
153814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const;                    // id
153914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const;                 // Class
154013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  bool isObjCSelType() const;                 // Class
1541de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  bool isObjCBuiltinType() const;               // 'id' or 'Class'
1542f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCARCBridgableType() const;
1543f85e193739c953358c865005855253af4f68a497John McCall  bool isCARCBridgableType() const;
154472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  bool isTemplateTypeParmType() const;          // C++ template type parameter
15456e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  bool isNullPtrType() const;                   // C++0x nullptr_t
1546ffbe9b9c64ab2e94b9d48ec56e511f75826fc80aBenjamin Kramer  bool isAtomicType() const;                    // C11 _Atomic()
1547898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
1548f85e193739c953358c865005855253af4f68a497John McCall  /// Determines if this type, which must satisfy
1549f85e193739c953358c865005855253af4f68a497John McCall  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
1550f85e193739c953358c865005855253af4f68a497John McCall  /// than implicitly __strong.
1551f85e193739c953358c865005855253af4f68a497John McCall  bool isObjCARCImplicitlyUnretainedType() const;
1552f85e193739c953358c865005855253af4f68a497John McCall
1553f85e193739c953358c865005855253af4f68a497John McCall  /// Return the implicit lifetime for this type, which must not be dependent.
1554f85e193739c953358c865005855253af4f68a497John McCall  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
1555f85e193739c953358c865005855253af4f68a497John McCall
1556daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  enum ScalarTypeKind {
15571d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall    STK_CPointer,
15581d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall    STK_BlockPointer,
15591d9b3b25f7ac0d0195bba6b507a684fe5e7943eeJohn McCall    STK_ObjCObjectPointer,
1560daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_MemberPointer,
1561daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Bool,
1562daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Integral,
1563daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_Floating,
1564daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_IntegralComplex,
1565daa8e4e888758d55a7a759dd4a91b83921cef222John McCall    STK_FloatingComplex
1566daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  };
1567daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  /// getScalarTypeKind - Given that this is a scalar type, classify it.
1568daa8e4e888758d55a7a759dd4a91b83921cef222John McCall  ScalarTypeKind getScalarTypeKind() const;
1569daa8e4e888758d55a7a759dd4a91b83921cef222John McCall
1570898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// isDependentType - Whether this type is a dependent type, meaning
15711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// that its definition somehow depends on a template parameter
1572898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// (C++ [temp.dep.type]).
1573b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isDependentType() const { return TypeBits.Dependent; }
1574ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1575561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// \brief Determine whether this type is an instantiation-dependent type,
1576561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// meaning that the type involves a template parameter (even if the
1577561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// definition does not actually depend on the type substituted for that
1578561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  /// template parameter).
1579ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  bool isInstantiationDependentType() const {
1580ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    return TypeBits.InstantiationDependent;
1581561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  }
1582ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
158335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor  /// \brief Whether this type is a variably-modified type (C99 6.7.5).
1584b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isVariablyModifiedType() const { return TypeBits.VariablyModified; }
15853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
15863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// \brief Whether this type involves a variable-length array type
15873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with a definite size.
15883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  bool hasSizedVLAType() const;
1589ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1590db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  /// \brief Whether this type is or contains a local or unnamed type.
1591db4d4bb03df52920cf379797a7ff5c9900f938a6Douglas Gregor  bool hasUnnamedOrLocalType() const;
1592ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1593063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  bool isOverloadableType() const;
159472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
15954033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  /// \brief Determine wither this type is a C++ elaborated-type-specifier.
15964033642464e8ba0982f88f34cffad808d247b393Douglas Gregor  bool isElaboratedTypeSpecifier() const;
1597bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth
1598bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth  bool canDecayToPointerType() const;
1599ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16008958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// hasPointerRepresentation - Whether this type is represented
16018958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// natively as a pointer; this includes pointers, references, block
16028958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  /// pointers, and Objective-C interface, qualified id, and qualified
16036e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl  /// interface types, as well as nullptr_t.
16048958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  bool hasPointerRepresentation() const;
16058958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
1606820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// hasObjCPointerRepresentation - Whether this type can represent
1607820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian  /// an objective pointer type for the purpose of GC'ability
16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool hasObjCPointerRepresentation() const;
1609820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
1610f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an integer representation
1611f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an integer type or a vector.
1612f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasIntegerRepresentation() const;
1613f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1614f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an signed integer representation
1615f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an signed integer type or a vector.
1616f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasSignedIntegerRepresentation() const;
1617f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1618f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// \brief Determine whether this type has an unsigned integer representation
1619f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  /// of some sort, e.g., it is an unsigned integer type or a vector.
1620f60946222721d9ba3c059563935c17b84703187aDouglas Gregor  bool hasUnsignedIntegerRepresentation() const;
1621f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
16228eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// \brief Determine whether this type has a floating-point representation
16238eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  /// of some sort, e.g., it is a floating-point type or a vector thereof.
16248eee119bf4f1693dde17b8552c1f9f81bf2b681eDouglas Gregor  bool hasFloatingRepresentation() const;
1625f60946222721d9ba3c059563935c17b84703187aDouglas Gregor
1626c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
1627f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // specified type, ignoring typedefs and qualifiers, and return a pointer to
1628f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner  // the best type we can.
1629769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek  const RecordType *getAsStructureType() const;
1630898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// NOTE: getAs*ArrayType are methods on ASTContext.
1631c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
16324cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
163314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // The following is a convenience method that returns an ObjCObjectPointerType
163414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  // for object declared using an interface.
163514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
163614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
1637759abb4d9ec14ae32104a9677b60f0542b60d1d8Fariborz Jahanian  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
1638c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
1639a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1641c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// \brief Retrieves the CXXRecordDecl that this type refers to, either
1642ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// because the type is a RecordType or because it is the injected-class-name
1643c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  /// type of a class template or class template partial specialization.
1644c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor  CXXRecordDecl *getAsCXXRecordDecl() const;
164534b41d939a1328f484511c6002ba2456db879a29Richard Smith
164634b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// \brief Get the AutoType whose type will be deduced for a variable with
164734b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// an initializer of this type. This looks through declarators like pointer
164834b41d939a1328f484511c6002ba2456db879a29Richard Smith  /// types, but not through decltype or typedefs.
164934b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType *getContainedAutoType() const;
1650ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1651d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template getAs<specific type>'.  Look through sugar for
1652d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// an instance of <specific type>.   This scheme will eventually
1653d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// replace the specific getAsXXXX methods above.
1654d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1655d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// There are some specializations of this member template listed
1656d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// immediately following this class.
16571a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  template <typename T> const T *getAs() const;
16581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// A variant of getAs<> for array types which silently discards
16603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// qualifiers from the outermost type.
16613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ArrayType *getAsArrayTypeUnsafe() const;
16623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
1663d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// Member-template castAs<specific type>.  Look through sugar for
1664d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// the underlying instance of <specific type>.
1665d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ///
1666d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// This method has the same relationship to getAs<T> as cast<T> has
1667d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// to dyn_cast<T>; which is to say, the underlying type *must*
1668d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// have the intended type, and this method will never return null.
1669d0370f59e79702ac908c81bf556519f91e9ca297John McCall  template <typename T> const T *castAs() const;
1670d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1671d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// A variant of castAs<> for array type which silently discards
1672d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// qualifiers from the outermost type.
1673d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const ArrayType *castAsArrayTypeUnsafe() const;
1674d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1675d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// getBaseElementTypeUnsafe - Get the base element type of this
1676d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// type, potentially discarding type qualifiers.  This method
1677d0370f59e79702ac908c81bf556519f91e9ca297John McCall  /// should never be used when type qualifiers are meaningful.
1678d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *getBaseElementTypeUnsafe() const;
1679d0370f59e79702ac908c81bf556519f91e9ca297John McCall
1680c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
1681c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// element type of the array, potentially with type qualifiers missing.
1682c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  /// This method should never be used when type qualifiers are meaningful.
1683c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const Type *getArrayElementTypeNoTypeQual() const;
16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1685f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
1686f8910df57799256c1897a8610dc52685729ae90eSteve Naroff  /// pointer, this returns the respective pointee.
168714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const;
16881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1689bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// getUnqualifiedDesugaredType() - Return the specified type with
1690bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// any "sugar" removed from the type, removing any typedefs,
1691bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// typeofs, etc., as well as any qualifiers.
1692bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  const Type *getUnqualifiedDesugaredType() const;
16931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
16955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
1698d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
16995f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// or an enum decl which has a signed representation.
17005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
1703ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
17045f3827cabd526d0dd5f291d46c310103cebe7a44Eli Friedman  /// or an enum decl which has an unsigned representation.
17055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
1706d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
1707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Determines whether this is an integer type that is signed or an
1708575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// enumeration types whose underlying type is a signed integer type.
1709575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  bool isSignedIntegerOrEnumerationType() const;
1710ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1711ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// Determines whether this is an integer type that is unsigned or an
1712575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  /// enumeration types whose underlying type is a unsigned integer type.
1713575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor  bool isUnsignedIntegerOrEnumerationType() const;
1714575a1c9dc8dc5b4977194993e289f9eda7295c39Douglas Gregor
17155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
17169bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
17179bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
17183c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman  bool isConstantSizeType() const;
1719c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
172022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// isSpecifierType - Returns true if this type can be represented by some
172122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  /// set of type specifiers.
172222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman  bool isSpecifierType() const;
172322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman
17240b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor  /// \brief Determine the linkage of this type.
172560e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  Linkage getLinkage() const;
17261fb0caaa7bef765b85972274e3b434af2572c141John McCall
17271fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the visibility of this type.
17281fb0caaa7bef765b85972274e3b434af2572c141John McCall  Visibility getVisibility() const;
17291fb0caaa7bef765b85972274e3b434af2572c141John McCall
1730093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola  /// \brief Return true if the visibility was explicitly set is the code.
1731093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola  bool isVisibilityExplicit() const;
1732093ecc92afb70f6125d249eef31f40c0c57b7d24Rafael Espindola
17331fb0caaa7bef765b85972274e3b434af2572c141John McCall  /// \brief Determine the linkage and visibility of this type.
17341fb0caaa7bef765b85972274e3b434af2572c141John McCall  std::pair<Linkage,Visibility> getLinkageAndVisibility() const;
1735ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
173660e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  /// \brief Note that the linkage is no longer known.
173760e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  void ClearLinkageCache();
1738ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
173960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor  const char *getTypeClassName() const;
17400b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
1741ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  QualType getCanonicalTypeInternal() const {
1742ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall    return CanonicalType;
1743ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  }
1744ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
1745b5f2c419842d016892b9c976d4d6e91880e0e43aArgyrios Kyrtzidis  LLVM_ATTRIBUTE_USED void dump() const;
1746f85e193739c953358c865005855253af4f68a497John McCall
17475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
1748be191100e034b23a3e13053757a57b7f5068c24aArgyrios Kyrtzidis
1749c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader;
1750a4232eb646d89e7d52424bb42eb87d9061f39e63Sebastian Redl  friend class ASTWriter;
17515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
17525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1753183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const TypedefType *Type::getAs() const {
1754183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  return dyn_cast<TypedefType>(this);
1755183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1756183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1757183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// We can do canonical leaf types faster, because we don't have to
1758183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall// worry about preserving child type decoration.
1759183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define TYPE(Class, Base)
1760183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#define LEAF_TYPE(Class) \
1761183700f494ec9b6701b6efe82bcb25f4c79ba561John McCalltemplate <> inline const Class##Type *Type::getAs() const { \
17620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  return dyn_cast<Class##Type>(CanonicalType); \
1763d0370f59e79702ac908c81bf556519f91e9ca297John McCall} \
1764d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <> inline const Class##Type *Type::castAs() const { \
1765d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<Class##Type>(CanonicalType); \
1766183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall}
1767183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall#include "clang/AST/TypeNodes.def"
1768183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
1769183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall
17705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
17715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
17725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
17735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
1775e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define BUILTIN_TYPE(Id, SingletonId) Id,
1776e0a22d06888c13989b3f72db319f1d498bf69153John McCall#define LAST_BUILTIN_TYPE(Id) LastKind = Id
1777e0a22d06888c13989b3f72db319f1d498bf69153John McCall#include "clang/AST/BuiltinTypes.def"
17785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
177971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
17811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  BuiltinType(Kind K)
178235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent),
1783561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/(K == Dependent),
1784d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*VariablyModified=*/false,
1785d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*Unexpanded paramter pack=*/false) {
1786b870b88df784c2940efce448ebfaf54dece14666John McCall    BuiltinTypeBits.Kind = K;
178771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
17881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1789b870b88df784c2940efce448ebfaf54dece14666John McCall  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
179027a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis  StringRef getName(const PrintingPolicy &Policy) const;
179127a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis  const char *getNameAsCString(const PrintingPolicy &Policy) const {
179227a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    // The StringRef is null-terminated.
179327a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    StringRef str = getName(Policy);
179427a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    assert(!str.empty() && str.data()[str.size()] == '\0');
179527a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis    return str.data();
179627a00970bf4ababdc115e54383e6252cc3276dfaArgyrios Kyrtzidis  }
17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1798bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1799bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1800bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
1801680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isInteger() const {
180271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= Int128;
1803680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1804680523a91dd3351389667c8de17121ba7ae82673John McCall
1805680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isSignedInteger() const {
180671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Char_S && getKind() <= Int128;
1807680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1808680523a91dd3351389667c8de17121ba7ae82673John McCall
1809680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isUnsignedInteger() const {
181071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return getKind() >= Bool && getKind() <= UInt128;
1811680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1812680523a91dd3351389667c8de17121ba7ae82673John McCall
1813680523a91dd3351389667c8de17121ba7ae82673John McCall  bool isFloatingPoint() const {
1814aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov    return getKind() >= Half && getKind() <= LongDouble;
1815680523a91dd3351389667c8de17121ba7ae82673John McCall  }
1816680523a91dd3351389667c8de17121ba7ae82673John McCall
181785def357129b6cdfd69a66ad0e6994506418a2a9John McCall  /// Determines whether the given kind corresponds to a placeholder type.
181885def357129b6cdfd69a66ad0e6994506418a2a9John McCall  static bool isPlaceholderTypeKind(Kind K) {
181985def357129b6cdfd69a66ad0e6994506418a2a9John McCall    return K >= Overload;
182085def357129b6cdfd69a66ad0e6994506418a2a9John McCall  }
182185def357129b6cdfd69a66ad0e6994506418a2a9John McCall
1822864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// Determines whether this type is a placeholder type, i.e. a type
1823864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// which cannot appear in arbitrary positions in a fully-formed
1824864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  /// expression.
18252a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  bool isPlaceholderType() const {
182685def357129b6cdfd69a66ad0e6994506418a2a9John McCall    return isPlaceholderTypeKind(getKind());
18272a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  }
18282a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
182932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// Determines whether this type is a placeholder type other than
183032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// Overload.  Most placeholder types require only syntactic
183132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// information about their context in order to be resolved (e.g.
183232509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// whether it is a call expression), which means they can (and
183332509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// should) be resolved in an earlier "phase" of analysis.
183432509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// Overload expressions sometimes pick up further information
183532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// from their context, like whether the context expects a
183632509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// specific function-pointer type, and so frequently need
183732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  /// special treatment.
183832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  bool isNonOverloadPlaceholderType() const {
183932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall    return getKind() > Overload;
184032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  }
184132509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall
18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
18435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
18445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
18485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
18495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
18505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
18515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
185235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Complex, CanonicalPtr, Element->isDependentType(),
1853561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Element->isInstantiationDependentType(),
1854d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->isVariablyModifiedType(),
1855d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Element->containsUnexpandedParameterPack()),
1856898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    ElementType(Element) {
18575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
185960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
18621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1863bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1864bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1865bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
18705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1877075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara/// ParenType - Sugar for parentheses used when specifying types.
1878075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara///
1879075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaraclass ParenType : public Type, public llvm::FoldingSetNode {
1880075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType Inner;
1881075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1882075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  ParenType(QualType InnerType, QualType CanonType) :
1883075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Type(Paren, CanonType, InnerType->isDependentType(),
1884561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         InnerType->isInstantiationDependentType(),
1885d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->isVariablyModifiedType(),
1886d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         InnerType->containsUnexpandedParameterPack()),
1887075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner(InnerType) {
1888075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1889075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  friend class ASTContext;  // ASTContext creates these.
1890075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1891075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnarapublic:
1892075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1893075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType getInnerType() const { return Inner; }
1894075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1895075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  bool isSugared() const { return true; }
1896075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType desugar() const { return getInnerType(); }
1897075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1898075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  void Profile(llvm::FoldingSetNodeID &ID) {
1899075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Profile(ID, getInnerType());
1900075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1901075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
1902075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara    Inner.Profile(ID);
1903075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  }
1904075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
1905075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
1906075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  static bool classof(const ParenType *) { return true; }
1907075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara};
1908075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara
190968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators.
1910bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner///
191168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode {
1912bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner  QualType PointeeType;
19135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
191535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(Pointer, CanonicalPtr, Pointee->isDependentType(),
1916561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Pointee->isInstantiationDependentType(),
1917d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1918ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         Pointee->containsUnexpandedParameterPack()),
191935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    PointeeType(Pointee) {
19205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
192260e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
19235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
19241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
192568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType getPointeeType() const { return PointeeType; }
192668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
1927bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1928bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1929bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
19315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
19325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
19345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
19355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
19385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
19395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
19415618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type.
19425618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as
19435618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type.
19445618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff///
19455618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode {
19465618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType PointeeType;  // Block is some kind of pointer type
19475618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
194835495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(BlockPointer, CanonicalCls, Pointee->isDependentType(),
1949561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Pointee->isInstantiationDependentType(),
1950d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
1951d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->containsUnexpandedParameterPack()),
1952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    PointeeType(Pointee) {
19535618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
19545618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  friend class ASTContext;  // ASTContext creates these.
1955ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19565618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic:
19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  // Get the pointee type. Pointee is required to always be a function type.
19595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  QualType getPointeeType() const { return PointeeType; }
19605618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
1961bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
1962bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
1963bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
19645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
19655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      Profile(ID, getPointeeType());
19665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
19675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
19685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff      ID.AddPointer(Pointee.getAsOpaquePtr());
19695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
19711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == BlockPointer;
19735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  }
19745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff  static bool classof(const BlockPointerType *) { return true; }
19755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff};
19765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff
19777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
19785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
197968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode {
198068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar  QualType PointeeType;
198168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
19827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected:
198354e14c4db764c0636160d26c5bbf491637c83a76John McCall  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
198454e14c4db764c0636160d26c5bbf491637c83a76John McCall                bool SpelledAsLValue) :
198535495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    Type(tc, CanonicalRef, Referencee->isDependentType(),
1986561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor         Referencee->isInstantiationDependentType(),
1987d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Referencee->isVariablyModifiedType(),
1988ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         Referencee->containsUnexpandedParameterPack()),
1989ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    PointeeType(Referencee)
1990d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  {
1991b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
1992b870b88df784c2940efce448ebfaf54dece14666John McCall    ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
19935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1994ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
19955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1996b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
1997b870b88df784c2940efce448ebfaf54dece14666John McCall  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
1998ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
199954e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeTypeAsWritten() const { return PointeeType; }
200054e14c4db764c0636160d26c5bbf491637c83a76John McCall  QualType getPointeeType() const {
200154e14c4db764c0636160d26c5bbf491637c83a76John McCall    // FIXME: this might strip inner qualifiers; okay?
200254e14c4db764c0636160d26c5bbf491637c83a76John McCall    const ReferenceType *T = this;
200371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    while (T->isInnerRef())
2004d0370f59e79702ac908c81bf556519f91e9ca297John McCall      T = T->PointeeType->castAs<ReferenceType>();
200554e14c4db764c0636160d26c5bbf491637c83a76John McCall    return T->PointeeType;
200654e14c4db764c0636160d26c5bbf491637c83a76John McCall  }
200768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar
20085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
200971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, PointeeType, isSpelledAsLValue());
20105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
201154e14c4db764c0636160d26c5bbf491637c83a76John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
201254e14c4db764c0636160d26c5bbf491637c83a76John McCall                      QualType Referencee,
201354e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) {
20145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
201554e14c4db764c0636160d26c5bbf491637c83a76John McCall    ID.AddBoolean(SpelledAsLValue);
20165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
20175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
20197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference ||
20207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl           T->getTypeClass() == RValueReference;
20217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
20237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
20247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
20257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
20267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
20277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType {
202854e14c4db764c0636160d26c5bbf491637c83a76John McCall  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
202954e14c4db764c0636160d26c5bbf491637c83a76John McCall                      bool SpelledAsLValue) :
203054e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(LValueReference, Referencee, CanonicalRef, SpelledAsLValue)
203154e14c4db764c0636160d26c5bbf491637c83a76John McCall  {}
20327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
20337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
2034bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2035bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2036bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
20387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == LValueReference;
20397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const LValueReferenceType *) { return true; }
20417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl};
20427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl
20437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
20447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl///
20457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType {
20467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
204754e14c4db764c0636160d26c5bbf491637c83a76John McCall    ReferenceType(RValueReference, Referencee, CanonicalRef, false) {
20487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  friend class ASTContext; // ASTContext creates these
20507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic:
2051bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2052bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2053bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
20547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const Type *T) {
20557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl    return T->getTypeClass() == RValueReference;
20567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  }
20577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl  static bool classof(const RValueReferenceType *) { return true; }
2058f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl};
2059f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2060f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members
2061f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl///
2062f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode {
2063f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType PointeeType;
2064f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// The class of which the pointee is a member. Must ultimately be a
2065f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  /// RecordType, but could be a typedef or a template parameter too.
2066f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *Class;
2067f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2068f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
2069f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Type(MemberPointer, CanonicalPtr,
207035495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor         Cls->isDependentType() || Pointee->isDependentType(),
2071ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         (Cls->isInstantiationDependentType() ||
2072561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor          Pointee->isInstantiationDependentType()),
2073d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         Pointee->isVariablyModifiedType(),
2074ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie         (Cls->containsUnexpandedParameterPack() ||
2075d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor          Pointee->containsUnexpandedParameterPack())),
2076f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    PointeeType(Pointee), Class(Cls) {
2077f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2078f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  friend class ASTContext; // ASTContext creates these.
2079ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2080f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic:
2081f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  QualType getPointeeType() const { return PointeeType; }
2082f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
20830bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
20840bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// function type rather than a data-member type.
20850bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberFunctionPointer() const {
20860bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return PointeeType->isFunctionProtoType();
20870bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
20880bab0cdab751248ca389a5592bcb70eac5d39260John McCall
20890bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Returns true if the member type (i.e. the pointee type) is a
20900bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// data type rather than a function type.
20910bab0cdab751248ca389a5592bcb70eac5d39260John McCall  bool isMemberDataPointer() const {
20920bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return !PointeeType->isFunctionProtoType();
20930bab0cdab751248ca389a5592bcb70eac5d39260John McCall  }
20940bab0cdab751248ca389a5592bcb70eac5d39260John McCall
2095f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  const Type *getClass() const { return Class; }
2096f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2097bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2098bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2099bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2100f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID) {
2101f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    Profile(ID, getPointeeType(), getClass());
2102f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2103f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
2104f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl                      const Type *Class) {
2105f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Pointee.getAsOpaquePtr());
2106f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    ID.AddPointer(Class);
2107f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2108f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
2109f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const Type *T) {
2110f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return T->getTypeClass() == MemberPointer;
2111f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  }
2112f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  static bool classof(const MemberPointerType *) { return true; }
21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
21145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
21155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
21165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
21172e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
21185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
21195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
2120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// an array with a static size (e.g. int X[static 4]), or an array
2121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// with a star size (e.g. int X[*]).
2122898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// 'static' is only allowed on function parameters.
21235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
21245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
21255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
21265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2127fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
2128fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2130fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
2131898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  // C++ [temp.dep.type]p1:
2132898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //   A type is dependent if it is...
2133898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //     - an array type constructed from any dependent type or whose
2134898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       size is specified by a constant expression that is
2135898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  //       value-dependent,
2136c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
2137d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            ArraySizeModifier sm, unsigned tq,
2138d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor            bool ContainsUnexpandedParameterPack)
213935495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray,
2140561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           et->isInstantiationDependentType() || tc == DependentSizedArray,
2141d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           (tc == VariableArray || et->isVariablyModifiedType()),
2142d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           ContainsUnexpandedParameterPack),
214371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ElementType(et) {
2144b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.IndexTypeQuals = tq;
2145b870b88df784c2940efce448ebfaf54dece14666John McCall    ArrayTypeBits.SizeModifier = sm;
214671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2147898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2148fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
214960e7064d78f1a29cf969f255a19a9ae25e6bc128Douglas Gregor
2150fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
2151fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
2152ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  ArraySizeModifier getSizeModifier() const {
2153b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArraySizeModifier(ArrayTypeBits.SizeModifier);
2154ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek  }
21550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers getIndexTypeQualifiers() const {
215671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
215771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
215871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  unsigned getIndexTypeCVRQualifiers() const {
2159b870b88df784c2940efce448ebfaf54dece14666John McCall    return ArrayTypeBits.IndexTypeQuals;
21600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
21611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2162fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
2163fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
2164c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman           T->getTypeClass() == VariableArray ||
2165898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == IncompleteArray ||
2166898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor           T->getTypeClass() == DependentSizedArray;
2167fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2168fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
2169fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
2170fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
21717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of
21727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size.  For example, the canonical
21737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
21747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404.
21752e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
2176fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21780be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
2179c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
2180d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    : ArrayType(ConstantArray, et, can, sm, tq,
2181d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
21827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      Size(size) {}
21837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected:
21847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  ConstantArrayType(TypeClass tc, QualType et, QualType can,
21857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
2186ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : ArrayType(tc, et, can, sm, tq, et->containsUnexpandedParameterPack()),
2187d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      Size(size) {}
2188fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
2189fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
2190c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  const llvm::APInt &getSize() const { return Size; }
2191bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2192bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2193bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2194ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
21952767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the number of bits required to address a member of
21962767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  // an array with the given element type and number of elements.
21972767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getNumAddressingBits(ASTContext &Context,
21982767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       QualType ElementType,
21992767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor                                       const llvm::APInt &NumElements);
2200ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
22012767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// \brief Determine the maximum number of active bits that an array's size
22022767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  /// can require, which limits the maximum size of the array.
22032767ce2e21d8bc17869b8436220bce719b3369e4Douglas Gregor  static unsigned getMaxSizeBits(ASTContext &Context);
2204ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2205fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
22061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, getElementType(), getSize(),
22070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers());
2208fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2209fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
22100be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
22110be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      unsigned TypeQuals) {
2212fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
2213fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
22140be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
22150be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2216fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
22177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  static bool classof(const Type *T) {
221846a617a792bfab0d9b1e057371ea3b9540802226John McCall    return T->getTypeClass() == ConstantArray;
2219fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
2220fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
2221fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
2222fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
2223da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified
2224da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size.  For example 'int A[]' has an IncompleteArrayType where the element
2225da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified.
2226c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType {
22277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2228c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  IncompleteArrayType(QualType et, QualType can,
22297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                      ArraySizeModifier sm, unsigned tq)
2230ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : ArrayType(IncompleteArray, et, can, sm, tq,
2231d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()) {}
2232c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class ASTContext;  // ASTContext creates these.
2233c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic:
2234bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2235bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2236bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
22371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
22381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == IncompleteArray;
2239c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2240c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  static bool classof(const IncompleteArrayType *) { return true; }
22411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2242c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  friend class StmtIteratorBase;
22431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2244c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
22450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Profile(ID, getElementType(), getSizeModifier(),
22460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getIndexTypeCVRQualifiers());
2247c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
22481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22490be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
22500be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
2251c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman    ID.AddPointer(ET.getAsOpaquePtr());
22520be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(SizeMod);
22530be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner    ID.AddInteger(TypeQuals);
2254c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman  }
2255c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman};
2256c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman
2257da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size
2258da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
2259da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such.
2260da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2261da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
2262da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean
2263da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type
2264da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically:
2265da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
2266da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) {
2267da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Y[x];
2268da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   ++x;
2269da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///   int Z[x];
2270da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// }
2271da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner///
22722e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
22731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// SizeExpr - An assignment expression. VLA's are only permitted within
22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// a function block.
2275b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  Stmt *SizeExpr;
22767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
22777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
22787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor
2279c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
22807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    ArraySizeModifier sm, unsigned tq,
22817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor                    SourceRange brackets)
2282ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : ArrayType(VariableArray, et, can, sm, tq,
2283d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                et->containsUnexpandedParameterPack()),
22847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor      SizeExpr((Stmt*) e), Brackets(brackets) {}
22855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
22864b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
22875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
22881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2289b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // We use C-style casts instead of cast<> here because we do not wish
2290b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    // to have a dependency of Type.h on Stmt.h/Expr.h.
2291b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek    return (Expr*) SizeExpr;
2292b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek  }
22937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
22947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
22957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
22961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2297bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2298bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2299bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
23011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == VariableArray;
23025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2303fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
23041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
230592866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23072bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
2308b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie    llvm_unreachable("Cannot unique VariableArrayTypes.");
23092bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
23105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
23115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2312898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in
2313898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example:
2314cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2315cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \code
23161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size>
2317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array {
2318898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor///   T data[Size];
2319898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// };
2320cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor/// \endcode
2321cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor///
2322898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is
2323898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will
2324898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType.
2325898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType {
23264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
23271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2328cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// \brief An assignment expression that will instantiate to the
2329898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  /// size of the array.
2330cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  ///
2331cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// The expression itself might be NULL, in which case the array
2332cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor  /// type will have its size deduced from an initializer.
2333898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  Stmt *SizeExpr;
2334cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor
23357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  /// Brackets - The left and right array brackets.
23367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange Brackets;
23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
233904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                          Expr *e, ArraySizeModifier sm, unsigned tq,
2340d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                          SourceRange brackets);
2341d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2342898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class ASTContext;  // ASTContext creates these.
2343898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2344898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic:
23451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  Expr *getSizeExpr() const {
2346898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // We use C-style casts instead of cast<> here because we do not wish
2347898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    // to have a dependency of Type.h on Stmt.h/Expr.h.
2348898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor    return (Expr*) SizeExpr;
2349898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
23507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceRange getBracketsRange() const { return Brackets; }
23517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
23527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
23531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2354bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2355bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2356bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
23571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedArray;
2359898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
2360898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  static bool classof(const DependentSizedArrayType *) { return true; }
23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2362898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  friend class StmtIteratorBase;
23631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2365898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
23661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    Profile(ID, Context, getElementType(),
23670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall            getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
2368898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor  }
23691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
23711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      QualType ET, ArraySizeModifier SizeMod,
237204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor                      unsigned TypeQuals, Expr *E);
2373898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor};
2374898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor
2375f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type
23769cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example:
23779cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code
23789cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size>
23799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector {
23809cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor///   typedef T __attribute__((ext_vector_type(Size))) type;
23819cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// }
23829cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode
23832ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
23844ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
23859cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  Expr *SizeExpr;
23869cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  /// ElementType - The element type of the array.
23879cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType ElementType;
23889cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation loc;
23891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
2391d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                              QualType can, Expr *SizeExpr, SourceLocation loc);
2392d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
23939cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  friend class ASTContext;
23949cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
23959cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic:
23962ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  Expr *getSizeExpr() const { return SizeExpr; }
23979cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  QualType getElementType() const { return ElementType; }
23989cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  SourceLocation getAttributeLoc() const { return loc; }
23999cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
2400bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2401bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2402bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
24031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == DependentSizedExtVector;
24059cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor  }
24061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const DependentSizedExtVectorType *) { return true; }
24072ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor
24082ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
24092ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor    Profile(ID, Context, getElementType(), getSizeExpr());
24102ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor  }
24111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
24132ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor                      QualType ElementType, Expr *SizeExpr);
24149cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor};
24151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24169cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor
241773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
24181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in
241982287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// bytes; or from an Altivec __vector or vector declaration.
242082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson/// Since the constructor takes the number of vector elements, the
242173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
2423788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattnerpublic:
2424e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  enum VectorKind {
2425e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    GenericVector,  // not a target-specific vector type
2426e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecVector,  // is AltiVec vector
2427e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecPixel,   // is AltiVec 'vector Pixel'
2428e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    AltiVecBool,    // is AltiVec 'vector bool ...'
2429491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonVector,     // is ARM Neon vector
2430491328c90c00ecad6ad27fa0ab3cdf9195a4a820Bob Wilson    NeonPolyVector  // is ARM Neon polynomial vector
2431788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner  };
243273322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
24335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
24345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
24351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
243682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson  VectorType(QualType vecType, unsigned nElements, QualType canonType,
2437d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             VectorKind vecKind);
2438ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
24391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
2440d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor             QualType canonType, VectorKind vecKind);
2441d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
24425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
2443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
24445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
24465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
2447b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2449bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2450bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2451bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
2452e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson  VectorKind getVectorKind() const {
2453e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    return VectorKind(VectorTypeBits.VecKind);
245471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2455788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner
24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
245771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Profile(ID, getElementType(), getNumElements(),
2458e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson            getTypeClass(), getVectorKind());
24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
246182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson                      unsigned NumElements, TypeClass TypeClass,
2462e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson                      VectorKind VecKind) {
24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
24645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
246573322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
2466e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    ID.AddInteger(VecKind);
246773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
24680b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
24691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
24701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
24715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
24725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
24735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
24745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2475213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using
2476213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
2477213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
2478fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
2479fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
2480213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType {
2481213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
2482e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson    VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
248373322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
248473322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
248588dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
248688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
248788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
248888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
248988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
249088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
249188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
249288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2493e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2494353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman  static int getNumericAccessorIdx(char c) {
249588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
2496353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      default: return -1;
2497353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '0': return 0;
2498353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '1': return 1;
2499353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '2': return 2;
2500353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '3': return 3;
2501353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '4': return 4;
2502353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '5': return 5;
2503353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '6': return 6;
2504353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '7': return 7;
2505353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '8': return 8;
2506353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case '9': return 9;
2507131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'A':
2508353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'a': return 10;
2509131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'B':
2510353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'b': return 11;
2511131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'C':
2512353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'c': return 12;
2513131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'D':
2514353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'd': return 13;
2515131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'E':
2516353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'e': return 14;
2517131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman      case 'F':
2518353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman      case 'f': return 15;
251988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
2520e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2522b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
2523b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
2524353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman    return getNumericAccessorIdx(c);
2525b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
25261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
252788dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
2528b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
252971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return unsigned(idx-1) < getNumElements();
253088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
2531e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
2532bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2533bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2534bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
25351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
25361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ExtVector;
253773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
2538213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  static bool classof(const ExtVectorType *) { return true; }
253973322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
254073322924127c873c13101b705dd823f5539ffa5fSteve Naroff
25415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
254272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType.
25435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
25445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
25455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
25465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
2547264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2548264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola public:
2549373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// ExtInfo - A class which abstracts out some details necessary for
2550373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// making a call.
2551373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2552373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// It is not actually used directly for storing this information in
2553373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// a FunctionType, although FunctionType does currently use the
2554373920bd733b1d28fe7bf209945a62eb9248d948John McCall  /// same bit-pattern.
2555373920bd733b1d28fe7bf209945a62eb9248d948John McCall  ///
2556075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // If you add a field (say Foo), other than the obvious places (both,
2557075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // constructors, compile failures), what you need to update is
2558075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  // * Operator==
2559425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * getFoo
2560425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * withFoo
2561425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * functionType. Add Foo, getFoo.
2562425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::getFooType
2563425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * ASTContext::mergeFunctionTypes
2564425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionNoProtoType::Profile
2565425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * FunctionProtoType::Profile
2566425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * TypePrinter::PrintFunctionProto
25673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  // * AST read and write
2568425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola  // * Codegen
2569264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  class ExtInfo {
25707e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    // Feel free to rearrange or add bits, but if you go over 8,
2571373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // you'll need to adjust both the Bits field below and
2572373920bd733b1d28fe7bf209945a62eb9248d948John McCall    // Type::FunctionTypeBitfields.
2573373920bd733b1d28fe7bf209945a62eb9248d948John McCall
25747e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //   |  CC  |noreturn|produces|regparm|
25757e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //   |0 .. 2|   3    |    4   | 5 .. 7|
25767e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    //
25777e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    // regparm is either 0 (no regparm attribute) or the regparm value+1.
2578b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { CallConvMask = 0x7 };
2579b870b88df784c2940efce448ebfaf54dece14666John McCall    enum { NoReturnMask = 0x8 };
2580f85e193739c953358c865005855253af4f68a497John McCall    enum { ProducesResultMask = 0x10 };
2581f85e193739c953358c865005855253af4f68a497John McCall    enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask),
25827e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor           RegParmOffset = 5 }; // Assumed to be the last field
2583b870b88df784c2940efce448ebfaf54dece14666John McCall
2584f85e193739c953358c865005855253af4f68a497John McCall    uint16_t Bits;
258571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2586f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
258771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
258871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    friend class FunctionType;
258971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall
2590264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola   public:
2591264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with no defaults. Use this when you know that you
25923c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl    // have all the elements (when reading an AST file for example).
2593f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
2594f85e193739c953358c865005855253af4f68a497John McCall            bool producesResult) {
25957e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
2596b870b88df784c2940efce448ebfaf54dece14666John McCall      Bits = ((unsigned) cc) |
2597b870b88df784c2940efce448ebfaf54dece14666John McCall             (noReturn ? NoReturnMask : 0) |
2598f85e193739c953358c865005855253af4f68a497John McCall             (producesResult ? ProducesResultMask : 0) |
25997e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor             (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0);
260071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2601264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2602264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Constructor with all defaults. Use when for example creating a
2603264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // function know to use defaults.
260471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    ExtInfo() : Bits(0) {}
2605264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2606b870b88df784c2940efce448ebfaf54dece14666John McCall    bool getNoReturn() const { return Bits & NoReturnMask; }
2607f85e193739c953358c865005855253af4f68a497John McCall    bool getProducesResult() const { return Bits & ProducesResultMask; }
26087e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
2609ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    unsigned getRegParm() const {
26107e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      unsigned RegParm = Bits >> RegParmOffset;
26117e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      if (RegParm > 0)
26127e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor        --RegParm;
26137e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      return RegParm;
26147e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor    }
2615b870b88df784c2940efce448ebfaf54dece14666John McCall    CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
2616264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
261771c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator==(ExtInfo Other) const {
261871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits == Other.Bits;
2619264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
262071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    bool operator!=(ExtInfo Other) const {
262171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      return Bits != Other.Bits;
2622264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2623264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2624264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // Note that we don't have setters. That is by design, use
2625264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    // the following with methods instead of mutating these objects.
2626264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2627264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withNoReturn(bool noReturn) const {
262871c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      if (noReturn)
262971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits | NoReturnMask);
263071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      else
263171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall        return ExtInfo(Bits & ~NoReturnMask);
2632425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    }
2633425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola
2634f85e193739c953358c865005855253af4f68a497John McCall    ExtInfo withProducesResult(bool producesResult) const {
2635f85e193739c953358c865005855253af4f68a497John McCall      if (producesResult)
2636f85e193739c953358c865005855253af4f68a497John McCall        return ExtInfo(Bits | ProducesResultMask);
2637f85e193739c953358c865005855253af4f68a497John McCall      else
2638f85e193739c953358c865005855253af4f68a497John McCall        return ExtInfo(Bits & ~ProducesResultMask);
2639f85e193739c953358c865005855253af4f68a497John McCall    }
2640f85e193739c953358c865005855253af4f68a497John McCall
2641425ef72306d4ff6b3698b744353e5f0e56b4b884Rafael Espindola    ExtInfo withRegParm(unsigned RegParm) const {
26427e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor      assert(RegParm < 7 && "Invalid regparm value");
2643f85e193739c953358c865005855253af4f68a497John McCall      return ExtInfo((Bits & ~RegParmMask) |
26447e47e1e7e6a2b83d903c97129f27e92f584c3dc2Douglas Gregor                     ((RegParm + 1) << RegParmOffset));
2645264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2646264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2647264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    ExtInfo withCallingConv(CallingConv cc) const {
2648b870b88df784c2940efce448ebfaf54dece14666John McCall      return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
2649264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    }
2650264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
2651e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    void Profile(llvm::FoldingSetNodeID &ID) const {
265271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      ID.AddInteger(Bits);
265371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    }
2654264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  };
2655264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola
26565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2657eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  FunctionType(TypeClass tc, QualType res,
2658c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               unsigned typeQuals, RefQualifierKind RefQualifier,
2659c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor               QualType Canonical, bool Dependent,
2660561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor               bool InstantiationDependent,
2661ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie               bool VariablyModified, bool ContainsUnexpandedParameterPack,
2662d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor               ExtInfo Info)
2663ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
2664ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           ContainsUnexpandedParameterPack),
2665d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      ResultType(res) {
2666b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.ExtInfo = Info.Bits;
2667b870b88df784c2940efce448ebfaf54dece14666John McCall    FunctionTypeBits.TypeQuals = typeQuals;
2668c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    FunctionTypeBits.RefQualifier = static_cast<unsigned>(RefQualifier);
266971c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
2670b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getTypeQuals() const { return FunctionTypeBits.TypeQuals; }
2671ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2672c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2673c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
2674c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2675c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor
26765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
26771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
26785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
2679a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman
2680a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
2681b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
2682b870b88df784c2940efce448ebfaf54dece14666John McCall  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
2683b870b88df784c2940efce448ebfaf54dece14666John McCall  CallingConv getCallConv() const { return getExtInfo().getCC(); }
2684b870b88df784c2940efce448ebfaf54dece14666John McCall  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
26855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
26865291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// \brief Determine the type of an expression that calls a function of
26875291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  /// this type.
2688ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  QualType getCallResultType(ASTContext &Context) const {
26896398235d7890a81b785ea5af3b6e66d86bf184ccDouglas Gregor    return getResultType().getNonLValueExprType(Context);
26905291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor  }
26915291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor
2692686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  static StringRef getNameForCallConv(CallingConv CC);
269304a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall
26945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
26955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
26965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
26975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
26985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
26995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
27005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
270172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
27025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
270372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
270471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
2705eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith    : FunctionType(FunctionNoProto, Result, 0, RQ_None, Canonical,
2706561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                   /*Dependent=*/false, /*InstantiationDependent=*/false,
2707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                   Result->isVariablyModifiedType(),
2708d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                   /*ContainsUnexpandedParameterPack=*/false, Info) {}
2709d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
27105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
2711ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
27125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
27135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
27141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2715bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2716bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2717bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
27185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
2719264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    Profile(ID, getResultType(), getExtInfo());
27205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27212455636163fdd18581d7fdae816433f886d88213Mike Stump  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
272271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall                      ExtInfo Info) {
272371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall    Info.Profile(ID);
27245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
27255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
27261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
27285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
27295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
273072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionNoProtoType *) { return true; }
27315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
27325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
273372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g.
27345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
2735465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an
2736465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical
2737465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type.
273872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
2739e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallpublic:
2740e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  /// ExtProtoInfo - Extra information about a function prototype.
2741e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  struct ExtProtoInfo {
2742e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo() :
2743361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer      Variadic(false), HasTrailingReturn(false), TypeQuals(0),
2744361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer      ExceptionSpecType(EST_None), RefQualifier(RQ_None),
274513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      NumExceptions(0), Exceptions(0), NoexceptExpr(0),
274613bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      ExceptionSpecDecl(0), ExceptionSpecTemplate(0),
2747e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith      ConsumedArguments(0) {}
2748e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2749e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    FunctionType::ExtInfo ExtInfo;
27500e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer    bool Variadic : 1;
27510e2e13f4daa71edac982633120531333b45e77b5Benjamin Kramer    bool HasTrailingReturn : 1;
2752e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned char TypeQuals;
2753361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer    ExceptionSpecificationType ExceptionSpecType;
2754361ae9a83e1e3098adabaaad34d0925b30358f38Benjamin Kramer    RefQualifierKind RefQualifier;
2755e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    unsigned NumExceptions;
2756e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    const QualType *Exceptions;
27578b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl    Expr *NoexceptExpr;
2758e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith    FunctionDecl *ExceptionSpecDecl;
275913bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    FunctionDecl *ExceptionSpecTemplate;
2760f85e193739c953358c865005855253af4f68a497John McCall    const bool *ConsumedArguments;
2761e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  };
2762e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
2763e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCallprivate:
2764d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// \brief Determine whether there are any argument types that
2765d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  /// contain an unexpanded parameter pack.
2766ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
2767d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                                                 unsigned numArgs) {
2768d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
2769d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor      if (ArgArray[Idx]->containsUnexpandedParameterPack())
2770d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor        return true;
2771d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2772d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    return false;
2773d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor  }
2774d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
2775e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  FunctionProtoType(QualType result, const QualType *args, unsigned numArgs,
27768026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                    QualType canonical, const ExtProtoInfo &epi);
2777465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
27785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
2779eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  unsigned NumArgs : 17;
2780465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2781465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  /// NumExceptions - The number of types in the exception spec, if any.
278260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned NumExceptions : 9;
2783465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
278460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// ExceptionSpecType - The type of exception specification this function has.
278560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  unsigned ExceptionSpecType : 3;
2786465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2787f85e193739c953358c865005855253af4f68a497John McCall  /// HasAnyConsumedArgs - Whether this function has any consumed arguments.
2788f85e193739c953358c865005855253af4f68a497John McCall  unsigned HasAnyConsumedArgs : 1;
2789f85e193739c953358c865005855253af4f68a497John McCall
2790eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  /// Variadic - Whether the function is variadic.
2791eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  unsigned Variadic : 1;
2792eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith
2793eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  /// HasTrailingReturn - Whether this function has a trailing return type.
2794eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  unsigned HasTrailingReturn : 1;
2795eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith
27966a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // ArgInfo - There is an variable size array after the class in memory that
27976a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // holds the argument types.
2798b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
27996a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // Exceptions - There is another variable size array after ArgInfo that
28006a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // holds the exception types.
2801b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
28026a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // NoexceptExpr - Instead of Exceptions, there may be a single Expr* pointing
28036a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // to the expression in the noexcept() specifier.
2804b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
280513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // ExceptionSpecDecl, ExceptionSpecTemplate - Instead of Exceptions, there may
280613bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // be a pair of FunctionDecl* pointing to the function which should be used to
280713bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // instantiate this function type's exception specification, and the function
280813bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  // from which it should be instantiated.
2809e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith
28106a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // ConsumedArgs - A variable size array, following Exceptions
28116a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // and of length NumArgs, holding flags indicating which arguments
28126a2ccc51d9b8357e1433e0029d544d95c5877a5cTed Kremenek  // are consumed.  This only appears if HasAnyConsumedArgs is true.
2813b8706f95eae8f85af01a26eee899c5daf8d6fcdeTed Kremenek
28145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
28154b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek
2816f85e193739c953358c865005855253af4f68a497John McCall  const bool *getConsumedArgsBuffer() const {
2817f85e193739c953358c865005855253af4f68a497John McCall    assert(hasAnyConsumedArgs());
2818f85e193739c953358c865005855253af4f68a497John McCall
2819f85e193739c953358c865005855253af4f68a497John McCall    // Find the end of the exceptions.
2820f85e193739c953358c865005855253af4f68a497John McCall    Expr * const *eh_end = reinterpret_cast<Expr * const *>(arg_type_end());
2821f85e193739c953358c865005855253af4f68a497John McCall    if (getExceptionSpecType() != EST_ComputedNoexcept)
2822f85e193739c953358c865005855253af4f68a497John McCall      eh_end += NumExceptions;
2823f85e193739c953358c865005855253af4f68a497John McCall    else
2824f85e193739c953358c865005855253af4f68a497John McCall      eh_end += 1; // NoexceptExpr
2825f85e193739c953358c865005855253af4f68a497John McCall
2826f85e193739c953358c865005855253af4f68a497John McCall    return reinterpret_cast<const bool*>(eh_end);
2827f85e193739c953358c865005855253af4f68a497John McCall  }
2828f85e193739c953358c865005855253af4f68a497John McCall
28295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
28305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
28315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
28325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
2833942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
28345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2835465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2836e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  ExtProtoInfo getExtProtoInfo() const {
2837e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    ExtProtoInfo EPI;
2838e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.ExtInfo = getExtInfo();
2839e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.Variadic = isVariadic();
2840eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith    EPI.HasTrailingReturn = hasTrailingReturn();
284160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    EPI.ExceptionSpecType = getExceptionSpecType();
2842e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    EPI.TypeQuals = static_cast<unsigned char>(getTypeQuals());
2843c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    EPI.RefQualifier = getRefQualifier();
284460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EPI.ExceptionSpecType == EST_Dynamic) {
284560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NumExceptions = NumExceptions;
284660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.Exceptions = exception_begin();
284760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) {
284860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      EPI.NoexceptExpr = getNoexceptExpr();
2849e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith    } else if (EPI.ExceptionSpecType == EST_Uninstantiated) {
2850e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith      EPI.ExceptionSpecDecl = getExceptionSpecDecl();
285113bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      EPI.ExceptionSpecTemplate = getExceptionSpecTemplate();
285260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    }
2853f85e193739c953358c865005855253af4f68a497John McCall    if (hasAnyConsumedArgs())
2854f85e193739c953358c865005855253af4f68a497John McCall      EPI.ConsumedArguments = getConsumedArgsBuffer();
2855e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall    return EPI;
2856e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall  }
2857e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall
285860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the kind of exception specification on this function.
285960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  ExceptionSpecificationType getExceptionSpecType() const {
286060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
286160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
286260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has any kind of exception spec.
286360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasExceptionSpec() const {
286460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return getExceptionSpecType() != EST_None;
286560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
286660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Return whether this function has a dynamic (throw) exception spec.
286760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasDynamicExceptionSpec() const {
286860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isDynamicExceptionSpec(getExceptionSpecType());
286960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
2870fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// \brief Return whether this function has a noexcept exception spec.
287160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  bool hasNoexceptExceptionSpec() const {
287260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return isNoexceptExceptionSpec(getExceptionSpecType());
287360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  }
287460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Result type of getNoexceptSpec().
287560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  enum NoexceptResult {
287660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_NoNoexcept,  ///< There is no noexcept specifier.
287760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_BadNoexcept, ///< The noexcept specifier has a bad expression.
287860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Dependent,   ///< The noexcept specifier is dependent.
287960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Throw,       ///< The noexcept specifier evaluates to false.
288060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    NR_Nothrow      ///< The noexcept specifier evaluates to true.
288160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  };
288260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  /// \brief Get the meaning of the noexcept spec on this function, if any.
28838026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  NoexceptResult getNoexceptSpec(ASTContext &Ctx) const;
2884465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  unsigned getNumExceptions() const { return NumExceptions; }
2885465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  QualType getExceptionType(unsigned i) const {
2886465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    assert(i < NumExceptions && "Invalid exception number!");
2887465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin()[i];
2888465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
288960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl  Expr *getNoexceptExpr() const {
289060618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_ComputedNoexcept)
289160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return 0;
289260618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    // NoexceptExpr sits where the arguments end.
289360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    return *reinterpret_cast<Expr *const *>(arg_type_end());
2894d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson  }
289513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// \brief If this function type has an uninstantiated exception
289613bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// specification, this is the function whose exception specification
289713bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// is represented by this type.
2898e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  FunctionDecl *getExceptionSpecDecl() const {
2899e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith    if (getExceptionSpecType() != EST_Uninstantiated)
2900e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith      return 0;
290113bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[0];
290213bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  }
290313bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// \brief If this function type has an uninstantiated exception
290413bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// specification, this is the function whose exception specification
290513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// should be instantiated to find the exception specification for
290613bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  /// this type.
290713bffc532bafd45d4a77867993c1afb83c7661beRichard Smith  FunctionDecl *getExceptionSpecTemplate() const {
290813bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    if (getExceptionSpecType() != EST_Uninstantiated)
290913bffc532bafd45d4a77867993c1afb83c7661beRichard Smith      return 0;
291013bffc532bafd45d4a77867993c1afb83c7661beRichard Smith    return reinterpret_cast<FunctionDecl * const *>(arg_type_end())[1];
2911e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  }
29128026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  bool isNothrow(ASTContext &Ctx) const {
291360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    ExceptionSpecificationType EST = getExceptionSpecType();
2914e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith    assert(EST != EST_Delayed && EST != EST_Uninstantiated);
291560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST == EST_DynamicNone || EST == EST_BasicNoexcept)
291660618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return true;
291760618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (EST != EST_ComputedNoexcept)
291860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return false;
29198026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl    return getNoexceptSpec(Ctx) == NR_Nothrow;
2920c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall  }
2921c2f3e7f42c8bf9e8d4393a6e8c4762dafc4f28ddJohn McCall
2922eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  bool isVariadic() const { return Variadic; }
292360618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl
2924f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// \brief Determines whether this function prototype contains a
2925f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// parameter pack at the end.
2926f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  ///
2927f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// A function template whose last parameter is a parameter pack can be
2928f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  /// called with an arbitrary number of arguments, much like a variadic
2929eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  /// function.
2930f5c65ffbd7374b6c8d9f1e361041578640cab320Douglas Gregor  bool isTemplateVariadic() const;
2931ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2932eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith  bool hasTrailingReturn() const { return HasTrailingReturn; }
2933eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith
2934971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
29351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2936ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2937c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  /// \brief Retrieve the ref-qualifier associated with this function type.
2938c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  RefQualifierKind getRefQualifier() const {
2939c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor    return FunctionType::getRefQualifier();
2940c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor  }
2941ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
29425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
2943942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
2944942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
2945942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
2946942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
2947465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2948465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  typedef const QualType *exception_iterator;
2949465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_begin() const {
2950465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    // exceptions begin where arguments end
2951465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return arg_type_end();
2952465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2953465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  exception_iterator exception_end() const {
295460618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl    if (getExceptionSpecType() != EST_Dynamic)
295560618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl      return exception_begin();
2956465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl    return exception_begin() + NumExceptions;
2957465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl  }
2958465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
2959f85e193739c953358c865005855253af4f68a497John McCall  bool hasAnyConsumedArgs() const {
2960f85e193739c953358c865005855253af4f68a497John McCall    return HasAnyConsumedArgs;
2961f85e193739c953358c865005855253af4f68a497John McCall  }
2962f85e193739c953358c865005855253af4f68a497John McCall  bool isArgConsumed(unsigned I) const {
2963f85e193739c953358c865005855253af4f68a497John McCall    assert(I < getNumArgs() && "argument index out of range!");
2964f85e193739c953358c865005855253af4f68a497John McCall    if (hasAnyConsumedArgs())
2965f85e193739c953358c865005855253af4f68a497John McCall      return getConsumedArgsBuffer()[I];
2966f85e193739c953358c865005855253af4f68a497John McCall    return false;
2967f85e193739c953358c865005855253af4f68a497John McCall  }
2968f85e193739c953358c865005855253af4f68a497John McCall
2969bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
2970bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
2971bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
29727ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  // FIXME: Remove the string version.
297301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  void printExceptionSpecification(std::string &S,
297401d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor                                   PrintingPolicy Policy) const;
29757ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void printExceptionSpecification(raw_ostream &OS,
29767ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                   PrintingPolicy Policy) const;
297701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
29785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
29795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
29805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
298172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const FunctionProtoType *) { return true; }
2982465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl
29838026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
29845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
2985942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
29868026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl                      const ExtProtoInfo &EPI, const ASTContext &Context);
29875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
29885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
29895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2990ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// \brief Represents the dependent type named by a dependently-scoped
2991ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// typename using declaration, e.g.
2992ed97649e9574b9d854fa4d6109c9333ae0993554John McCall///   using typename Base<T>::foo;
2993ed97649e9574b9d854fa4d6109c9333ae0993554John McCall/// Template instantiation turns these into the underlying type.
2994ed97649e9574b9d854fa4d6109c9333ae0993554John McCallclass UnresolvedUsingType : public Type {
2995ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *Decl;
2996ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
299719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D)
2998ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(UnresolvedUsing, QualType(), true, true, false,
2999d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
300019c8576b7328f4dc2d07682f5da552875c1912efJohn McCall      Decl(const_cast<UnresolvedUsingTypenameDecl*>(D)) {}
3001ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  friend class ASTContext; // ASTContext creates these.
3002ed97649e9574b9d854fa4d6109c9333ae0993554John McCallpublic:
3003ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3004ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
3005ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3006ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  bool isSugared() const { return false; }
3007ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  QualType desugar() const { return QualType(this, 0); }
3008ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3009ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const Type *T) {
3010ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return T->getTypeClass() == UnresolvedUsing;
3011ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3012ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static bool classof(const UnresolvedUsingType *) { return true; }
3013ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3014ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
3015ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    return Profile(ID, Decl);
3016ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3017ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
3018ed97649e9574b9d854fa4d6109c9333ae0993554John McCall                      UnresolvedUsingTypenameDecl *D) {
3019ed97649e9574b9d854fa4d6109c9333ae0993554John McCall    ID.AddPointer(D);
3020ed97649e9574b9d854fa4d6109c9333ae0993554John McCall  }
3021ed97649e9574b9d854fa4d6109c9333ae0993554John McCall};
3022ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
3023ed97649e9574b9d854fa4d6109c9333ae0993554John McCall
30245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
3025162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *Decl;
3026c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
3027162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType can)
3028ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(tc, can, can->isDependentType(),
3029561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           can->isInstantiationDependentType(),
3030ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           can->isVariablyModifiedType(),
3031d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
3032162e1c1b487352434552147967c3dd296ebee2f7Richard Smith      Decl(const_cast<TypedefNameDecl*>(D)) {
30335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
30345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
30355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
30365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
30371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3038162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  TypedefNameDecl *getDecl() const { return Decl; }
30391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3040bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3041bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
3042bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
304372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
30445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
30455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
30465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
304772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension).
304872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type {
3049d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
30501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3051b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected:
3052dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor  TypeOfExprType(Expr *E, QualType can = QualType());
3053d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
3054d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
3055d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
30561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3057bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3058bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const;
3059bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3060bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
30616af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor  bool isSugared() const;
3062bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
306372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
306472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const TypeOfExprType *) { return true; }
3065d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
3066d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
3067c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
30681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types.
3069c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
3070c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
3071c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
3072c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via TypeOfExprType nodes.
30731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType
3074b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  : public TypeOfExprType, public llvm::FoldingSetNode {
30754ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
30761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3077b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic:
30784ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentTypeOfExprType(const ASTContext &Context, Expr *E)
3079b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    : TypeOfExprType(E), Context(Context) { }
30801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3081b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3082b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
3083b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor  }
30841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
30854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3086b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor                      Expr *E);
3087b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor};
30881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3089d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
3090d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
3091d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
30921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TypeOfType(QualType T, QualType can)
3093ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(TypeOf, can, T->isDependentType(),
3094561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           T->isInstantiationDependentType(),
3095ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           T->isVariablyModifiedType(),
3096ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           T->containsUnexpandedParameterPack()),
309735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor      TOType(T) {
3098d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
3099d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
3100d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
3101d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
3102d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
31031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3104bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3105bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getUnderlyingType(); }
3106bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3107bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3108bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3109bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
311072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
3111d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
3112d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
31135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3114395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x)
3115395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type {
3116395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *E;
3117563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType UnderlyingType;
31181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31199d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected:
3120563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
3121395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  friend class ASTContext;  // ASTContext creates these.
3122395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic:
3123395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  Expr *getUnderlyingExpr() const { return E; }
3124563a03b1338d31c2462def43253a722bc885d384Anders Carlsson  QualType getUnderlyingType() const { return UnderlyingType; }
3125563a03b1338d31c2462def43253a722bc885d384Anders Carlsson
3126bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
31276af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor  QualType desugar() const;
3128bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3129bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
31306af9f3ca25157379efd5c1caad82e9d01c17b9ffDouglas Gregor  bool isSugared() const;
3131bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3132395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
3133395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson  static bool classof(const DecltypeType *) { return true; }
3134395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson};
31351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3136c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// \brief Internal representation of canonical, dependent
3137c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// decltype(expr) types.
3138c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor///
3139c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// This class is used internally by the ASTContext to manage
3140c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// canonical, dependent types, only. Clients will only see instances
3141c4875ee41ba35f1d746f4266ce47461247f19f41Douglas Gregor/// of this class via DecltypeType nodes.
31429d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
31434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  const ASTContext &Context;
31441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31459d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic:
31464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  DependentDecltypeType(const ASTContext &Context, Expr *E);
31471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31489d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
31499d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor    Profile(ID, Context, getUnderlyingExpr());
31509d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor  }
31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
31524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
31531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      Expr *E);
31549d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor};
31551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3156ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// \brief A unary type transform, which is a type constructed from another
3157ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntclass UnaryTransformType : public Type {
3158ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
3159ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  enum UTTKind {
3160ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    EnumUnderlyingType
3161ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  };
3162ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3163ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprivate:
3164ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// The untransformed type.
3165ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType BaseType;
3166ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  /// The transformed type if not dependent, otherwise the same as BaseType.
3167ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType UnderlyingType;
3168ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3169ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UTTKind UKind;
3170ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntprotected:
3171ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
3172ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt                     QualType CanonicalTy);
3173ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  friend class ASTContext;
3174ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Huntpublic:
3175ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  bool isSugared() const { return !isDependentType(); }
3176ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType desugar() const { return UnderlyingType; }
3177ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3178ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType getUnderlyingType() const { return UnderlyingType; }
3179ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  QualType getBaseType() const { return BaseType; }
3180ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
3181ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  UTTKind getUTTKind() const { return UKind; }
3182ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3183ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  static bool classof(const Type *T) {
3184ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt    return T->getTypeClass() == UnaryTransform;
3185ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  }
3186ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt  static bool classof(const UnaryTransformType *) { return true; }
3187ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt};
3188ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt
31895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
3190ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// Stores the TagDecl associated with this type. The decl may point to any
3191ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  /// TagDecl that declares the entity.
3192ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl * decl;
31932ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
319456ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor  friend class ASTReader;
319556ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor
31962ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected:
319719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  TagType(TypeClass TC, const TagDecl *D, QualType can);
31982ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor
31991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
3200ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  TagDecl *getDecl() const;
32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32020b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor  /// @brief Determines whether this type is in the process of being
32031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// defined.
3204ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  bool isBeingDefined() const;
32050b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor
32061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
320772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
320872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  }
32095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
32105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
32115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
32125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
32135edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes.
32145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType {
321549aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected:
321619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit RecordType(const RecordDecl *D)
321719c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) { }
321872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  explicit RecordType(TypeClass TC, RecordDecl *D)
321919c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) { }
32202ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
32215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
32221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  RecordDecl *getDecl() const {
32245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
32255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
32261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // FIXME: This predicate is a helper to QualType/Type. It needs to
32285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  // recursively check all fields for const-ness. If any field is declared
32291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  // const, it needs to return false.
32305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  bool hasConstFields() const { return false; }
32315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
3232bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3233bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3234bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
323595b68f94d28a4b94f4c3fb029b9f1690e1bb728bPeter Collingbourne  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
32365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const RecordType *) { return true; }
32375edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
32385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
32395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
32405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums.
32415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType {
324219c8576b7328f4dc2d07682f5da552875c1912efJohn McCall  explicit EnumType(const EnumDecl *D)
324319c8576b7328f4dc2d07682f5da552875c1912efJohn McCall    : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) { }
32442ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor  friend class ASTContext;   // ASTContext creates these.
32455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic:
32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
32475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  EnumDecl *getDecl() const {
32485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
32495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  }
32501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3251bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3252bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3253bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
325495b68f94d28a4b94f4c3fb029b9f1690e1bb728bPeter Collingbourne  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
32555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner  static bool classof(const EnumType *) { return true; }
32565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner};
32575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner
32589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// AttributedType - An attributed type is a type to which a type
32599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// attribute has been applied.  The "modified type" is the
32609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// fully-sugared type to which the attributed type was applied;
32619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// generally it is not canonically equivalent to the attributed type.
32629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// The "equivalent type" is the minimally-desugared type which the
32639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// type is canonically equivalent to.
32649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///
32659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall/// For example, in the following attributed type:
32669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///     int32_t __attribute__((vector_size(16)))
32679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the modified type is the TypedefType for int32_t
32689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the equivalent type is VectorType(16, int32_t)
32699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall///   - the canonical type is VectorType(16, int)
32709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallclass AttributedType : public Type, public llvm::FoldingSetNode {
32719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
32729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // It is really silly to have yet another attribute-kind enum, but
32739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  // clang::attr::Kind doesn't currently cover the pure type attrs.
32749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  enum Kind {
32759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Expression operand.
3276170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_address_space,
3277170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_regparm,
3278170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_vector_size,
3279170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_vector_type,
3280170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_neon_polyvector_type,
32819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3282170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstExprOperandKind = attr_address_space,
3283170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    LastExprOperandKind = attr_neon_polyvector_type,
32849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
32859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // Enumerated operand (string or keyword).
3286170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    attr_objc_gc,
3287b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis    attr_objc_ownership,
3288414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    attr_pcs,
32899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3290170464b7c0a2c0c86f2821f14a46f0d540cb5e94Francois Pichet    FirstEnumOperandKind = attr_objc_gc,
3291414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov    LastEnumOperandKind = attr_pcs,
32929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
32939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    // No operand.
32943cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_noreturn,
32953cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_cdecl,
32963cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_fastcall,
32973cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_stdcall,
32983cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_thiscall,
32993cd47e7883dbfce73189b583850cea81e1d1d261Francois Pichet    attr_pascal
33009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  };
33019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallprivate:
33039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType ModifiedType;
33049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType EquivalentType;
33059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  friend class ASTContext; // creates these
33079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  AttributedType(QualType canon, Kind attrKind,
33099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                 QualType modified, QualType equivalent)
33109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    : Type(Attributed, canon, canon->isDependentType(),
3311561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           canon->isInstantiationDependentType(),
33129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->isVariablyModifiedType(),
33139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall           canon->containsUnexpandedParameterPack()),
33149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall      ModifiedType(modified), EquivalentType(equivalent) {
33159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    AttributedTypeBits.AttrKind = attrKind;
33169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallpublic:
33199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  Kind getAttrKind() const {
33209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return static_cast<Kind>(AttributedTypeBits.AttrKind);
33219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getModifiedType() const { return ModifiedType; }
33249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType getEquivalentType() const { return EquivalentType; }
33259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  bool isSugared() const { return true; }
33279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  QualType desugar() const { return getEquivalentType(); }
33289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
33309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
33319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
33349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall                      QualType modified, QualType equivalent) {
33359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddInteger(attrKind);
33369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(modified.getAsOpaquePtr());
33379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    ID.AddPointer(equivalent.getAsOpaquePtr());
33389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
33409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const Type *T) {
33419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall    return T->getTypeClass() == Attributed;
33429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  }
33439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall  static bool classof(const AttributedType *T) { return true; }
33449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall};
33459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall
3346fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
33474fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  // Helper data collector for canonical types.
33484fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  struct CanonicalTTPTInfo {
33494fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Depth : 15;
33504fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned ParameterPack : 1;
33514fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    unsigned Index : 16;
33524fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
33534fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
33544fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  union {
33554fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the canonical type.
33564fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanonicalTTPTInfo CanTTPTInfo;
33574fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    // Info for the non-canonical type.
33584fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    TemplateTypeParmDecl *TTPDecl;
33594fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  };
336072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
33614fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build a non-canonical type.
33624fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon)
336335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(TemplateTypeParm, Canon, /*Dependent=*/true,
3364561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
33654fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false,
33665d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth           Canon->containsUnexpandedParameterPack()),
33674fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth      TTPDecl(TTPDecl) { }
336872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
33694fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  /// Build the canonical type.
33701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
3371ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    : Type(TemplateTypeParm, QualType(this, 0),
3372561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*Dependent=*/true,
3373561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
33744fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth           /*VariablyModified=*/false, PP) {
33754fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Depth = D;
33764fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.Index = I;
33774fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    CanTTPTInfo.ParameterPack = PP;
33784fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
337972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
3380fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  friend class ASTContext;  // ASTContext creates these
338172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
33824fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  const CanonicalTTPTInfo& getCanTTPTInfo() const {
33834fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    QualType Can = getCanonicalTypeInternal();
33845d65e34b08b3e57a4da834195757d0d15baaffd0Chandler Carruth    return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
33854fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
33864fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3387fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic:
33884fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
33894fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  unsigned getIndex() const { return getCanTTPTInfo().Index; }
33904fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
33914fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
33924fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  TemplateTypeParmDecl *getDecl() const {
33934fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    return isCanonicalUnqualified() ? 0 : TTPDecl;
33944fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth  }
33954fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth
3396b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const;
33971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3398bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3399bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3400bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3401fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
34024fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
3403fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3404fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
34051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
34061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                      unsigned Index, bool ParameterPack,
34074fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth                      TemplateTypeParmDecl *TTPDecl) {
3408fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Depth);
3409fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor    ID.AddInteger(Index);
341076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson    ID.AddBoolean(ParameterPack);
34114fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth    ID.AddPointer(TTPDecl);
3412fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor  }
3413fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
34141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
34151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateTypeParm;
341672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  }
341772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor  static bool classof(const TemplateTypeParmType *T) { return true; }
341872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor};
3419fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor
342049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Represents the result of substituting a type for a template
342149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type parameter.
342249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall///
342349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// Within an instantiated template, all template type parameters have
342449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// been replaced with these.  They are used solely to record that a
342549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// type was originally written as a template type parameter;
342649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// therefore they are never canonical.
342749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallclass SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
342849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  // The original type parameter.
342949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *Replaced;
343049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
343149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon)
343235495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(SubstTemplateTypeParm, Canon, Canon->isDependentType(),
3433561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           Canon->isInstantiationDependentType(),
3434d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->isVariablyModifiedType(),
3435d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           Canon->containsUnexpandedParameterPack()),
343649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall      Replaced(Param) { }
343749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
343849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  friend class ASTContext;
343949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
344049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallpublic:
344149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the template parameter that was substituted for.
344249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  const TemplateTypeParmType *getReplacedParameter() const {
344349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return Replaced;
344449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
344549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
344649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// Gets the type that was substituted for the template
344749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  /// parameter.
344849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType getReplacementType() const {
344949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return getCanonicalTypeInternal();
345049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
345149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
345249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  bool isSugared() const { return true; }
345349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  QualType desugar() const { return getReplacementType(); }
345449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
345549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  void Profile(llvm::FoldingSetNodeID &ID) {
345649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    Profile(ID, getReplacedParameter(), getReplacementType());
345749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
345849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID,
345949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      const TemplateTypeParmType *Replaced,
346049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall                      QualType Replacement) {
346149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replaced);
346249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    ID.AddPointer(Replacement.getAsOpaquePtr());
346349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
346449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
346549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const Type *T) {
346649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall    return T->getTypeClass() == SubstTemplateTypeParm;
346749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  }
346849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall  static bool classof(const SubstTemplateTypeParmType *T) { return true; }
346949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall};
347049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall
3471c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Represents the result of substituting a set of types for a template
3472c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// type parameter pack.
3473c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor///
3474c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// When a pack expansion in the source code contains multiple parameter packs
3475c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// and those parameter packs correspond to different levels of template
3476ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// parameter lists, this type node is used to represent a template type
3477c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// parameter pack from an outer level, which has already had its argument pack
3478c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// substituted but that still lives within a pack expansion that itself
3479c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// could not be instantiated. When actually performing a substitution into
3480c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// that pack expansion (e.g., when all template parameters have corresponding
3481c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
3482c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// at the current pack substitution index.
3483c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorclass SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
3484c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The original type parameter.
3485c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *Replaced;
3486ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3487c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief A pointer to the set of template arguments that this
3488c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// parameter pack is instantiated with.
3489c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateArgument *Arguments;
3490ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3491c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// \brief The number of template arguments in \c Arguments.
3492c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  unsigned NumArguments;
3493ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3494ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
3495c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                QualType Canon,
3496c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                                const TemplateArgument &ArgPack);
3497ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3498c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  friend class ASTContext;
3499ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3500c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregorpublic:
3501b7efff4bae117604f442bb6859c844f90b15f3ffChandler Carruth  IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); }
3502ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3503c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  /// Gets the template parameter that was substituted for.
3504c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  const TemplateTypeParmType *getReplacedParameter() const {
3505c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return Replaced;
3506c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3507ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3508c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  bool isSugared() const { return false; }
3509c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
3510ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3511c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  TemplateArgument getArgumentPack() const;
3512ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3513c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID);
3514c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID,
3515c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateTypeParmType *Replaced,
3516c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor                      const TemplateArgument &ArgPack);
3517ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
3518c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const Type *T) {
3519c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor    return T->getTypeClass() == SubstTemplateTypeParmPack;
3520c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  }
3521c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor  static bool classof(const SubstTemplateTypeParmPackType *T) { return true; }
3522c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor};
3523c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor
352434b41d939a1328f484511c6002ba2456db879a29Richard Smith/// \brief Represents a C++0x auto type.
352534b41d939a1328f484511c6002ba2456db879a29Richard Smith///
352634b41d939a1328f484511c6002ba2456db879a29Richard Smith/// These types are usually a placeholder for a deduced type. However, within
352734b41d939a1328f484511c6002ba2456db879a29Richard Smith/// templates and before the initializer is attached, there is no deduced type
352834b41d939a1328f484511c6002ba2456db879a29Richard Smith/// and an auto type is type-dependent and canonical.
352934b41d939a1328f484511c6002ba2456db879a29Richard Smithclass AutoType : public Type, public llvm::FoldingSetNode {
353034b41d939a1328f484511c6002ba2456db879a29Richard Smith  AutoType(QualType DeducedType)
353134b41d939a1328f484511c6002ba2456db879a29Richard Smith    : Type(Auto, DeducedType.isNull() ? QualType(this, 0) : DeducedType,
353234b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*Dependent=*/DeducedType.isNull(),
3533561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/DeducedType.isNull(),
353434b41d939a1328f484511c6002ba2456db879a29Richard Smith           /*VariablyModified=*/false, /*ContainsParameterPack=*/false) {
353534b41d939a1328f484511c6002ba2456db879a29Richard Smith    assert((DeducedType.isNull() || !DeducedType->isDependentType()) &&
353634b41d939a1328f484511c6002ba2456db879a29Richard Smith           "deduced a dependent type for auto");
353734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
353834b41d939a1328f484511c6002ba2456db879a29Richard Smith
353934b41d939a1328f484511c6002ba2456db879a29Richard Smith  friend class ASTContext;  // ASTContext creates these
354034b41d939a1328f484511c6002ba2456db879a29Richard Smith
354134b41d939a1328f484511c6002ba2456db879a29Richard Smithpublic:
354234b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isSugared() const { return isDeduced(); }
354334b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType desugar() const { return getCanonicalTypeInternal(); }
354434b41d939a1328f484511c6002ba2456db879a29Richard Smith
354534b41d939a1328f484511c6002ba2456db879a29Richard Smith  QualType getDeducedType() const {
354634b41d939a1328f484511c6002ba2456db879a29Richard Smith    return isDeduced() ? getCanonicalTypeInternal() : QualType();
354734b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
354834b41d939a1328f484511c6002ba2456db879a29Richard Smith  bool isDeduced() const {
354934b41d939a1328f484511c6002ba2456db879a29Richard Smith    return !isDependentType();
355034b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
355134b41d939a1328f484511c6002ba2456db879a29Richard Smith
355234b41d939a1328f484511c6002ba2456db879a29Richard Smith  void Profile(llvm::FoldingSetNodeID &ID) {
355334b41d939a1328f484511c6002ba2456db879a29Richard Smith    Profile(ID, getDeducedType());
355434b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
355534b41d939a1328f484511c6002ba2456db879a29Richard Smith
355634b41d939a1328f484511c6002ba2456db879a29Richard Smith  static void Profile(llvm::FoldingSetNodeID &ID,
355734b41d939a1328f484511c6002ba2456db879a29Richard Smith                      QualType Deduced) {
355834b41d939a1328f484511c6002ba2456db879a29Richard Smith    ID.AddPointer(Deduced.getAsOpaquePtr());
355934b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
356034b41d939a1328f484511c6002ba2456db879a29Richard Smith
356134b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const Type *T) {
356234b41d939a1328f484511c6002ba2456db879a29Richard Smith    return T->getTypeClass() == Auto;
356334b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
356434b41d939a1328f484511c6002ba2456db879a29Richard Smith  static bool classof(const AutoType *T) { return true; }
356534b41d939a1328f484511c6002ba2456db879a29Richard Smith};
356634b41d939a1328f484511c6002ba2456db879a29Richard Smith
35671901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// \brief Represents a type template specialization; the template
35681901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// must be a class template, a type alias template, or a template
35691901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template parameter.  A template which cannot be resolved to one of
35701901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// these, e.g. because it is written with a dependent scope
35711901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specifier, is instead represented as a
35721901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// @c DependentTemplateSpecializationType.
357355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor///
35741901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// A non-dependent template specialization type is always "sugar",
35751901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// typically for a @c RecordType.  For example, a class template
35761901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// specialization type of @c vector<int> will refer to a tag type for
35771901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// the instantiation @c std::vector<int, std::allocator<int>>
35787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor///
35791901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Template specializations are dependent if either the template or
35801901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// any of the template arguments are dependent, in which case the
35811901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// type may also be canonical.
35823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith///
35831901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// Instances of this type are allocated with a trailing array of
35841901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// TemplateArguments, followed by a QualType representing the
35851901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// non-canonical aliased type when the template is a type alias
35861901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall/// template.
35871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType
358855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  : public Type, public llvm::FoldingSetNode {
35891901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// \brief The name of the template being specialized.  This is
35901901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// either a TemplateName::Template (in which case it is a
35911901dce8b1e78d0bf7072cccab695bd58c7eec21John McCall  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
3592146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TypeAliasTemplateDecl*), a
3593146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TemplateName::SubstTemplateTemplateParmPack, or a
3594146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// TemplateName::SubstTemplateTemplateParm (in which case the
3595146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall  /// replacement must, recursively, be one of these).
35967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName Template;
359755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
359840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief - The number of template arguments named in this class
359940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// template specialization.
3600b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  unsigned NumArgs : 31;
360155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
3602b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \brief Whether this template specialization type is a substituted
3603b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// type alias.
3604b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  bool TypeAlias : 1;
3605b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor
3606ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  TemplateSpecializationType(TemplateName T,
36077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor                             const TemplateArgument *Args,
36083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             unsigned NumArgs, QualType Canon,
36093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith                             QualType Aliased);
361055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
361155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  friend class ASTContext;  // ASTContext creates these
361255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
361355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic:
361440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Determine whether any of the given template arguments are
361540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// dependent.
361640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
3617561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            unsigned NumArgs,
3618561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            bool &InstantiationDependent);
361940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
3620833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static bool anyDependentTemplateArguments(const TemplateArgumentLoc *Args,
3621561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            unsigned NumArgs,
3622561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            bool &InstantiationDependent);
3623833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3624561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor  static bool anyDependentTemplateArguments(const TemplateArgumentListInfo &,
3625561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                                            bool &InstantiationDependent);
3626d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
3627df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// \brief Print a template argument list, including the '<' and '>'
3628df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  /// enclosing the template arguments.
36297ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  // FIXME: remove the string ones.
3630df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
3631d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor                                               unsigned NumArgs,
3632dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               const PrintingPolicy &Policy,
3633dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor                                               bool SkipBrackets = false);
3634df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor
3635833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentLoc *Args,
3636833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               unsigned NumArgs,
3637833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                                               const PrintingPolicy &Policy);
3638833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
3639d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall  static std::string PrintTemplateArgumentList(const TemplateArgumentListInfo &,
3640d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall                                               const PrintingPolicy &Policy);
3641d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall
36427ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  /// \brief Print a template argument list, including the '<' and '>'
36437ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  /// enclosing the template arguments.
36447ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void PrintTemplateArgumentList(raw_ostream &OS,
36457ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const TemplateArgument *Args,
36467ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        unsigned NumArgs,
36477ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const PrintingPolicy &Policy,
36487ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        bool SkipBrackets = false);
36497ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
36507ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void PrintTemplateArgumentList(raw_ostream &OS,
36517ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const TemplateArgumentLoc *Args,
36527ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        unsigned NumArgs,
36537ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const PrintingPolicy &Policy);
36547ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
36557ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  static void PrintTemplateArgumentList(raw_ostream &OS,
36567ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const TemplateArgumentListInfo &,
36577ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis                                        const PrintingPolicy &Policy);
36587ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
365931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// True if this template specialization type matches a current
366031f17ecbef57b5679c017c375db330546b7b5145John McCall  /// instantiation in the context in which it is found.
366131f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isCurrentInstantiation() const {
366271d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    return isa<InjectedClassNameType>(getCanonicalTypeInternal());
366331f17ecbef57b5679c017c375db330546b7b5145John McCall  }
366431f17ecbef57b5679c017c375db330546b7b5145John McCall
3665b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \brief Determine if this template specialization type is for a type alias
3666b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template that has been substituted.
3667b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  ///
3668b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// Nearly every template specialization type whose template is an alias
3669b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template will be substituted. However, this is not the case when
3670b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// the specialization contains a pack expansion but the template alias
3671b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// does not have a corresponding parameter pack, e.g.,
3672b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  ///
3673b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \code
3674b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template<typename T, typename U, typename V> struct S;
3675b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template<typename T, typename U> using A = S<T, int, U>;
3676b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// template<typename... Ts> struct X {
3677b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  ///   typedef A<Ts...> type; // not a type alias
3678b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// };
3679b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  /// \endcode
3680b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor  bool isTypeAlias() const { return TypeAlias; }
3681b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor
36823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// Get the aliased type, if this is a specialization of a type alias
36833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  /// template.
36843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  QualType getAliasedType() const {
36853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    assert(isTypeAlias() && "not a type alias template specialization");
36863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return *reinterpret_cast<const QualType*>(end());
36873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith  }
36883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith
368940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  typedef const TemplateArgument * iterator;
369040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
369140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  iterator begin() const { return getArgs(); }
369233500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // defined inline in TemplateBase.h
369340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
36947532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  /// \brief Retrieve the name of the template that we are specializing.
36957532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  TemplateName getTemplateName() const { return Template; }
369655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
369740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the template arguments.
36981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const TemplateArgument *getArgs() const {
369940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor    return reinterpret_cast<const TemplateArgument *>(this + 1);
370040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  }
370140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor
370240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor  /// \brief Retrieve the number of template arguments.
370355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  unsigned getNumArgs() const { return NumArgs; }
370455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
370555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \brief Retrieve a specific template argument as a type.
370655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  /// \precondition @c isArgType(Arg)
370733500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
370855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
370931f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const {
37103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
371131f17ecbef57b5679c017c375db330546b7b5145John McCall  }
3712bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getCanonicalTypeInternal(); }
3713bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
37144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
371571d74bc0d6e522ce7c21a599db8e19d3883b518fJohn McCall    Profile(ID, Template, getArgs(), NumArgs, Ctx);
37163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith    if (isTypeAlias())
37173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith      getAliasedType().Profile(ID);
371855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
371955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
37207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
372131f17ecbef57b5679c017c375db330546b7b5145John McCall                      const TemplateArgument *Args,
372231f17ecbef57b5679c017c375db330546b7b5145John McCall                      unsigned NumArgs,
37234ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context);
372455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
37251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
37261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == TemplateSpecialization;
372755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor  }
37287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor  static bool classof(const TemplateSpecializationType *T) { return true; }
372955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor};
373055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor
373131f17ecbef57b5679c017c375db330546b7b5145John McCall/// \brief The injected class name of a C++ class template or class
373231f17ecbef57b5679c017c375db330546b7b5145John McCall/// template partial specialization.  Used to record that a type was
373331f17ecbef57b5679c017c375db330546b7b5145John McCall/// spelled with a bare identifier rather than as a template-id; the
373431f17ecbef57b5679c017c375db330546b7b5145John McCall/// equivalent for non-templated classes is just RecordType.
37353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
373631f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always dependent.  Template
373731f17ecbef57b5679c017c375db330546b7b5145John McCall/// instantiation turns these into RecordTypes.
37383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall///
373931f17ecbef57b5679c017c375db330546b7b5145John McCall/// Injected class name types are always canonical.  This works
374031f17ecbef57b5679c017c375db330546b7b5145John McCall/// because it is impossible to compare an injected class name type
374131f17ecbef57b5679c017c375db330546b7b5145John McCall/// with the corresponding non-injected template type, for the same
374231f17ecbef57b5679c017c375db330546b7b5145John McCall/// reason that it is impossible to directly compare template
374331f17ecbef57b5679c017c375db330546b7b5145John McCall/// parameters from different dependent contexts: injected class name
374431f17ecbef57b5679c017c375db330546b7b5145John McCall/// types can only occur within the scope of a particular templated
374531f17ecbef57b5679c017c375db330546b7b5145John McCall/// declaration, and within that scope every template specialization
374631f17ecbef57b5679c017c375db330546b7b5145John McCall/// will canonicalize to the injected class name (when appropriate
374731f17ecbef57b5679c017c375db330546b7b5145John McCall/// according to the rules of the language).
37483cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallclass InjectedClassNameType : public Type {
37493cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  CXXRecordDecl *Decl;
37503cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
375131f17ecbef57b5679c017c375db330546b7b5145John McCall  /// The template specialization which this type represents.
375231f17ecbef57b5679c017c375db330546b7b5145John McCall  /// For example, in
375331f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class T> class A { ... };
375431f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<T>, whereas in
375531f17ecbef57b5679c017c375db330546b7b5145John McCall  ///   template <class X, class Y> class A<B<X,Y> > { ... };
375631f17ecbef57b5679c017c375db330546b7b5145John McCall  /// this is A<B<X,Y> >.
375731f17ecbef57b5679c017c375db330546b7b5145John McCall  ///
375831f17ecbef57b5679c017c375db330546b7b5145John McCall  /// It is always unqualified, always a template specialization type,
375931f17ecbef57b5679c017c375db330546b7b5145John McCall  /// and always dependent.
376031f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType InjectedType;
37613cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
37623cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  friend class ASTContext; // ASTContext creates these.
3763c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
3764c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl                          // currently suitable for AST reading, too much
376543921b53b582145f0d1b7c48223bd4d9f0a9d1beArgyrios Kyrtzidis                          // interdependencies.
376631f17ecbef57b5679c017c375db330546b7b5145John McCall  InjectedClassNameType(CXXRecordDecl *D, QualType TST)
376735495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : Type(InjectedClassName, QualType(), /*Dependent=*/true,
3768561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
3769ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie           /*VariablyModified=*/false,
3770d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
377131f17ecbef57b5679c017c375db330546b7b5145John McCall      Decl(D), InjectedType(TST) {
37723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(isa<TemplateSpecializationType>(TST));
37733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    assert(!TST.hasQualifiers());
377431f17ecbef57b5679c017c375db330546b7b5145John McCall    assert(TST->isDependentType());
37753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
37763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
37773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallpublic:
377831f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType getInjectedSpecializationType() const { return InjectedType; }
377931f17ecbef57b5679c017c375db330546b7b5145John McCall  const TemplateSpecializationType *getInjectedTST() const {
378031f17ecbef57b5679c017c375db330546b7b5145John McCall    return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
37813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
37823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3783ed48a8faa10b6750f334540711c7b3949bbfb3aeSebastian Redl  CXXRecordDecl *getDecl() const;
37843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
378531f17ecbef57b5679c017c375db330546b7b5145John McCall  bool isSugared() const { return false; }
378631f17ecbef57b5679c017c375db330546b7b5145John McCall  QualType desugar() const { return QualType(this, 0); }
37873cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
37883cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const Type *T) {
37893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall    return T->getTypeClass() == InjectedClassName;
37903cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  }
37913cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall  static bool classof(const InjectedClassNameType *T) { return true; }
37923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall};
37933cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall
3794465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief The kind of a tag type.
3795465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraenum TagTypeKind {
3796465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "struct" keyword.
3797465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Struct,
3798465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "union" keyword.
3799465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Union,
3800465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword.
3801465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Class,
3802465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "enum" keyword.
3803465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TTK_Enum
3804465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3805465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
38064a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief The elaboration keyword that precedes a qualified type name or
38074a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// introduces an elaborated-type-specifier.
38084a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregorenum ElaboratedTypeKeyword {
38094a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "struct" keyword introduces the elaborated-type-specifier.
38104a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Struct,
38114a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "union" keyword introduces the elaborated-type-specifier.
38124a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  ETK_Union,
3813465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "class" keyword introduces the elaborated-type-specifier.
3814465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Class,
38154a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  /// \brief The "enum" keyword introduces the elaborated-type-specifier.
3816465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Enum,
3817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief The "typename" keyword precedes the qualified type name, e.g.,
3818465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \c typename T::type.
3819465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_Typename,
3820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// \brief No keyword precedes the qualified type name.
3821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ETK_None
38224a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor};
3823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// A helper class for Type nodes having an ElaboratedTypeKeyword.
3825465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The keyword in stored in the free bits of the base class.
3826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// Also provides a few static helpers for converting and printing
3827465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// elaborated type keyword and tag type kind enumerations.
3828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass TypeWithKeyword : public Type {
3829465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraprotected:
3830465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc,
3831ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                  QualType Canonical, bool Dependent,
3832ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                  bool InstantiationDependent, bool VariablyModified,
3833d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                  bool ContainsUnexpandedParameterPack)
3834ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  : Type(tc, Canonical, Dependent, InstantiationDependent, VariablyModified,
3835d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor         ContainsUnexpandedParameterPack) {
383677be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    TypeWithKeywordBits.Keyword = Keyword;
383777be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall  }
3838465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3839465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnarapublic:
3840465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedTypeKeyword getKeyword() const {
384177be2b485f65ad134b3804a6930d5df9d0d974ceJohn McCall    return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
3842465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3843465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3844465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTypeSpec - Converts a type specifier (DeclSpec::TST)
3845465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into an elaborated type keyword.
3846465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
3847465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3848465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForTypeSpec - Converts a type specifier (DeclSpec::TST)
3849465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// into a tag type kind.  It is an error to provide a type specifier
3850465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3851465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
3852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3853465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getKeywordForTagDeclKind - Converts a TagTypeKind into an
3854465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// elaborated type keyword.
3855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
3856465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// getTagTypeKindForKeyword - Converts an elaborated type keyword into
3858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  // a TagTypeKind. It is an error to provide an elaborated type keyword
3859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  /// which *isn't* a tag kind here.
3860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
3861465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3862465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
3863465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3864465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getKeywordName(ElaboratedTypeKeyword Keyword);
3865465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3866465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static const char *getTagTypeKindName(TagTypeKind Kind) {
3867465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return getKeywordName(getKeywordForTagTypeKind(Kind));
3868465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3869465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3870465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  class CannotCastToThisType {};
3871465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static CannotCastToThisType classof(const Type *);
3872465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara};
3873465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3874465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// \brief Represents a type that was referred to using an elaborated type
3875465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
3876465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// or both.
3877e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor///
3878e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the
3879465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// source code, including tag keywords and any nested-name-specifiers.
3880465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// The type itself is always "sugar", used to express what was written
3881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara/// in the source code but containing no additional semantic information.
3882465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass ElaboratedType : public TypeWithKeyword, public llvm::FoldingSetNode {
3883465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3884ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3885ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *NNS;
3886e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3887e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief The type that this qualified name refers to.
3888e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType NamedType;
3889e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3890465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
3891465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                 QualType NamedType, QualType CanonType)
3892465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    : TypeWithKeyword(Keyword, Elaborated, CanonType,
389335495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor                      NamedType->isDependentType(),
3894561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                      NamedType->isInstantiationDependentType(),
3895d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->isVariablyModifiedType(),
3896d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NamedType->containsUnexpandedParameterPack()),
3897465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), NamedType(NamedType) {
3898465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    assert(!(Keyword == ETK_None && NNS == 0) &&
3899465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "ElaboratedType cannot have elaborated type keyword "
3900465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara           "and name qualifier both null.");
3901465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  }
3902e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3903e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3904e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3905e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic:
390633500955d731c73717af52088b7fc0e7a85681e7John McCall  ~ElaboratedType();
3907465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3908ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  /// \brief Retrieve the qualification on this type.
3909ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3910e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3911e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  /// \brief Retrieve the type named by the qualified-id.
3912e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  QualType getNamedType() const { return NamedType; }
3913e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3914bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Remove a single level of sugar.
3915bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return getNamedType(); }
3916bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3917bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  /// \brief Returns whether this type directly provides sugar.
3918bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return true; }
3919bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3920e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3921465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, NamedType);
3922e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3923e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
3924465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
3925465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara                      NestedNameSpecifier *NNS, QualType NamedType) {
3926465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    ID.AddInteger(Keyword);
3927ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    ID.AddPointer(NNS);
3928ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor    NamedType.Profile(ID);
3929ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor  }
3930e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
39311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
3932465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    return T->getTypeClass() == Elaborated;
3933e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor  }
3934465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara  static bool classof(const ElaboratedType *T) { return true; }
3935e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor};
3936e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor
39374a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// \brief Represents a qualified type name for which the type name is
3938ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// dependent.
3939d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor///
3940ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// DependentNameType represents a class of dependent types that involve a
3941ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// dependent nested-name-specifier (e.g., "T::") followed by a (dependent)
39424a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// name of a type. The DependentNameType may start with a "typename" (for a
3943ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// typename-specifier), "class", "struct", "union", or "enum" (for a
39444a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// dependent elaborated-type-specifier), or nothing (in contexts where we
39454a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor/// know that we must be referring to a type, e.g., in a base class specifier).
3946465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnaraclass DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
3947465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara
3948d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The nested name specifier containing the qualifier.
3949d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *NNS;
3950d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3951d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief The type that this typename specifier refers to.
395233500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
3953d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3954ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
39554a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor                    const IdentifierInfo *Name, QualType CanonType)
395635495eb14f22c4e96956912e23ca2a433227ad8cDouglas Gregor    : TypeWithKeyword(Keyword, DependentName, CanonType, /*Dependent=*/true,
3957561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor                      /*InstantiationDependent=*/true,
3958d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      /*VariablyModified=*/false,
3959d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor                      NNS->containsUnexpandedParameterPack()),
3960465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara      NNS(NNS), Name(Name) {
39611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    assert(NNS->isDependent() &&
39624714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor           "DependentNameType requires a dependent nested-name-specifier");
3963d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3964d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3965d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  friend class ASTContext;  // ASTContext creates these
3966d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3967d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic:
3968d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  /// \brief Retrieve the qualification on this type.
3969d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  NestedNameSpecifier *getQualifier() const { return NNS; }
3970d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
39711734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// \brief Retrieve the type named by the typename specifier as an
39721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// identifier.
39731734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  ///
39741734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// This routine will return a non-NULL identifier pointer when the
39751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// form of the original typename was terminated by an identifier,
39761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  /// e.g., "typename T::type".
39771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const IdentifierInfo *getIdentifier() const {
397833500955d731c73717af52088b7fc0e7a85681e7John McCall    return Name;
39791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor  }
3980d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
3981bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
3982bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
3983bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
3984d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
3985465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara    Profile(ID, getKeyword(), NNS, Name);
3986d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3987d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
39884a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
398933500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
39904a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor    ID.AddInteger(Keyword);
3991d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor    ID.AddPointer(NNS);
399233500955d731c73717af52088b7fc0e7a85681e7John McCall    ID.AddPointer(Name);
3993d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
3994d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
39951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
39964714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor    return T->getTypeClass() == DependentName;
3997d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor  }
39984714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor  static bool classof(const DependentNameType *T) { return true; }
3999d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor};
4000d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor
400133500955d731c73717af52088b7fc0e7a85681e7John McCall/// DependentTemplateSpecializationType - Represents a template
400233500955d731c73717af52088b7fc0e7a85681e7John McCall/// specialization type whose template cannot be resolved, e.g.
400333500955d731c73717af52088b7fc0e7a85681e7John McCall///   A<T>::template B<T>
400433500955d731c73717af52088b7fc0e7a85681e7John McCallclass DependentTemplateSpecializationType :
400533500955d731c73717af52088b7fc0e7a85681e7John McCall  public TypeWithKeyword, public llvm::FoldingSetNode {
400633500955d731c73717af52088b7fc0e7a85681e7John McCall
400733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The nested name specifier containing the qualifier.
400833500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *NNS;
400933500955d731c73717af52088b7fc0e7a85681e7John McCall
401033500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief The identifier of the template.
401133500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *Name;
401233500955d731c73717af52088b7fc0e7a85681e7John McCall
401333500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief - The number of template arguments named in this class
401433500955d731c73717af52088b7fc0e7a85681e7John McCall  /// template specialization.
401533500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned NumArgs;
401633500955d731c73717af52088b7fc0e7a85681e7John McCall
401733500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgBuffer() const {
401833500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<const TemplateArgument*>(this+1);
401933500955d731c73717af52088b7fc0e7a85681e7John McCall  }
402033500955d731c73717af52088b7fc0e7a85681e7John McCall  TemplateArgument *getArgBuffer() {
402133500955d731c73717af52088b7fc0e7a85681e7John McCall    return reinterpret_cast<TemplateArgument*>(this+1);
402233500955d731c73717af52088b7fc0e7a85681e7John McCall  }
402333500955d731c73717af52088b7fc0e7a85681e7John McCall
4024ef99001908e799c388f1363b1e607dad5f5b57d3John McCall  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
402533500955d731c73717af52088b7fc0e7a85681e7John McCall                                      NestedNameSpecifier *NNS,
402633500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const IdentifierInfo *Name,
402733500955d731c73717af52088b7fc0e7a85681e7John McCall                                      unsigned NumArgs,
402833500955d731c73717af52088b7fc0e7a85681e7John McCall                                      const TemplateArgument *Args,
402933500955d731c73717af52088b7fc0e7a85681e7John McCall                                      QualType Canon);
403033500955d731c73717af52088b7fc0e7a85681e7John McCall
403133500955d731c73717af52088b7fc0e7a85681e7John McCall  friend class ASTContext;  // ASTContext creates these
403233500955d731c73717af52088b7fc0e7a85681e7John McCall
403333500955d731c73717af52088b7fc0e7a85681e7John McCallpublic:
403433500955d731c73717af52088b7fc0e7a85681e7John McCall  NestedNameSpecifier *getQualifier() const { return NNS; }
403533500955d731c73717af52088b7fc0e7a85681e7John McCall  const IdentifierInfo *getIdentifier() const { return Name; }
403633500955d731c73717af52088b7fc0e7a85681e7John McCall
403733500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the template arguments.
403833500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument *getArgs() const {
403933500955d731c73717af52088b7fc0e7a85681e7John McCall    return getArgBuffer();
404033500955d731c73717af52088b7fc0e7a85681e7John McCall  }
404133500955d731c73717af52088b7fc0e7a85681e7John McCall
404233500955d731c73717af52088b7fc0e7a85681e7John McCall  /// \brief Retrieve the number of template arguments.
404333500955d731c73717af52088b7fc0e7a85681e7John McCall  unsigned getNumArgs() const { return NumArgs; }
404433500955d731c73717af52088b7fc0e7a85681e7John McCall
404533500955d731c73717af52088b7fc0e7a85681e7John McCall  const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
404633500955d731c73717af52088b7fc0e7a85681e7John McCall
404733500955d731c73717af52088b7fc0e7a85681e7John McCall  typedef const TemplateArgument * iterator;
404833500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator begin() const { return getArgs(); }
404933500955d731c73717af52088b7fc0e7a85681e7John McCall  iterator end() const; // inline in TemplateBase.h
405033500955d731c73717af52088b7fc0e7a85681e7John McCall
405133500955d731c73717af52088b7fc0e7a85681e7John McCall  bool isSugared() const { return false; }
405233500955d731c73717af52088b7fc0e7a85681e7John McCall  QualType desugar() const { return QualType(this, 0); }
405333500955d731c73717af52088b7fc0e7a85681e7John McCall
40544ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
405533500955d731c73717af52088b7fc0e7a85681e7John McCall    Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
405633500955d731c73717af52088b7fc0e7a85681e7John McCall  }
405733500955d731c73717af52088b7fc0e7a85681e7John McCall
405833500955d731c73717af52088b7fc0e7a85681e7John McCall  static void Profile(llvm::FoldingSetNodeID &ID,
40594ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad                      const ASTContext &Context,
406033500955d731c73717af52088b7fc0e7a85681e7John McCall                      ElaboratedTypeKeyword Keyword,
406133500955d731c73717af52088b7fc0e7a85681e7John McCall                      NestedNameSpecifier *Qualifier,
406233500955d731c73717af52088b7fc0e7a85681e7John McCall                      const IdentifierInfo *Name,
406333500955d731c73717af52088b7fc0e7a85681e7John McCall                      unsigned NumArgs,
406433500955d731c73717af52088b7fc0e7a85681e7John McCall                      const TemplateArgument *Args);
406533500955d731c73717af52088b7fc0e7a85681e7John McCall
406633500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const Type *T) {
406733500955d731c73717af52088b7fc0e7a85681e7John McCall    return T->getTypeClass() == DependentTemplateSpecialization;
406833500955d731c73717af52088b7fc0e7a85681e7John McCall  }
406933500955d731c73717af52088b7fc0e7a85681e7John McCall  static bool classof(const DependentTemplateSpecializationType *T) {
407033500955d731c73717af52088b7fc0e7a85681e7John McCall    return true;
4071ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
407233500955d731c73717af52088b7fc0e7a85681e7John McCall};
407333500955d731c73717af52088b7fc0e7a85681e7John McCall
40747536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \brief Represents a pack expansion of types.
40757536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
40767536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Pack expansions are part of C++0x variadic templates. A pack
40777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// expansion contains a pattern, which itself contains one or more
40787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// "unexpanded" parameter packs. When instantiated, a pack expansion
40797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// produces a series of types, each instantiated from the pattern of
40807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// the expansion, where the Ith instantiation of the pattern uses the
40817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Ith arguments bound to each of the unexpanded parameter packs. The
40827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// pack expansion is considered to "expand" these unexpanded
40837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// parameter packs.
40847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
40857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \code
40867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// template<typename ...Types> struct tuple;
40877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
4088ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie/// template<typename ...Types>
40897536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// struct tuple_of_references {
40907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///   typedef tuple<Types&...> type;
40917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// };
40927536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// \endcode
40937536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor///
40947536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// Here, the pack expansion \c Types&... is represented via a
40957536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor/// PackExpansionType whose pattern is Types&.
40967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorclass PackExpansionType : public Type, public llvm::FoldingSetNode {
40977536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief The pattern of the pack expansion.
40987536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType Pattern;
40997536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4100cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief The number of expansions that this pack expansion will
4101ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// generate when substituted (+1), or indicates that
4102cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  ///
4103ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// This field will only have a non-zero value when some of the parameter
4104ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// packs that occur within the pattern have been substituted but others have
4105cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// not.
4106cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  unsigned NumExpansions;
4107ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4108cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  PackExpansionType(QualType Pattern, QualType Canon,
4109cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                    llvm::Optional<unsigned> NumExpansions)
41107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    : Type(PackExpansion, Canon, /*Dependent=*/true,
4111561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor           /*InstantiationDependent=*/true,
41127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*VariableModified=*/Pattern->isVariablyModifiedType(),
41137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor           /*ContainsUnexpandedParameterPack=*/false),
4114ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie      Pattern(Pattern),
4115cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      NumExpansions(NumExpansions? *NumExpansions + 1: 0) { }
41167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
41177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  friend class ASTContext;  // ASTContext creates these
4118ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
41197536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpublic:
41207536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// \brief Retrieve the pattern of this pack expansion, which is the
41217536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// type that will be repeatedly instantiated when instantiating the
41227536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  /// pack expansion itself.
41237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType getPattern() const { return Pattern; }
41247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4125cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// \brief Retrieve the number of expansions that this pack expansion will
4126cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  /// generate, if known.
4127cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  llvm::Optional<unsigned> getNumExpansions() const {
4128cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
4129cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      return NumExpansions - 1;
4130ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4131cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    return llvm::Optional<unsigned>();
4132cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  }
4133ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
41347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  bool isSugared() const { return false; }
41357536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  QualType desugar() const { return QualType(this, 0); }
41367536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
41377536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  void Profile(llvm::FoldingSetNodeID &ID) {
4138cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    Profile(ID, getPattern(), getNumExpansions());
41397536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
41407536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4141cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
4142cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor                      llvm::Optional<unsigned> NumExpansions) {
41437536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    ID.AddPointer(Pattern.getAsOpaquePtr());
4144cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    ID.AddBoolean(NumExpansions);
4145cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor    if (NumExpansions)
4146cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor      ID.AddInteger(*NumExpansions);
41477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
41487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
41497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const Type *T) {
41507536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return T->getTypeClass() == PackExpansion;
41517536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  }
41527536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor  static bool classof(const PackExpansionType *T) {
41537536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor    return true;
4154ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  }
41557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor};
41567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
4157c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectType - Represents a class type in Objective C.
4158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Every Objective C type is a combination of a base type and a
4159c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// list of protocols.
4160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4161c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// Given the following declarations:
4162c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @class C;
4163c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///   @protocol P;
4164c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4165c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C' is an ObjCInterfaceType C.  It is sugar for an ObjCObjectType
4166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// with base C and no protocols.
4167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// 'C<P>' is an ObjCObjectType with base C and protocol list [P].
4169c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4170e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id' is a TypedefType which is sugar for an ObjCPointerType whose
4171e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
4172e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// and no protocols.
4173c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall///
4174e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// 'id<P>' is an ObjCPointerType whose pointee is an ObjCObjecType
4175e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// with base BuiltinType::ObjCIdType and protocol list [P].  Eventually
4176e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// this should get its own sugar class to better represent the source.
4177c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectType : public Type {
4178b870b88df784c2940efce448ebfaf54dece14666John McCall  // ObjCObjectType.NumProtocols - the number of protocols stored
4179b870b88df784c2940efce448ebfaf54dece14666John McCall  // after the ObjCObjectPointerType node.
418071c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
418171c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // These protocols are those written directly on the type.  If
418271c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // protocol qualifiers ever become additive, the iterators will need
418371c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // to get kindof complicated.
418471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  //
418571c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // In the canonical object type, these are sorted alphabetically
418671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  // and uniqued.
4187c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
4188c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Either a BuiltinType or an InterfaceType or sugar for either.
4189c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType BaseType;
4190c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4191c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl * const *getProtocolStorage() const {
4192c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return const_cast<ObjCObjectType*>(this)->getProtocolStorage();
4193c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4194c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4195c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCProtocolDecl **getProtocolStorage();
4196c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallprotected:
4198ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCObjectType(QualType Canonical, QualType Base,
4199c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                 ObjCProtocolDecl * const *Protocols, unsigned NumProtocols);
4200c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4201c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum Nonce_ObjCInterface { Nonce_ObjCInterface };
4202c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectType(enum Nonce_ObjCInterface)
4203561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor        : Type(ObjCInterface, QualType(), false, false, false, false),
420471c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall      BaseType(QualType(this_(), 0)) {
4205b870b88df784c2940efce448ebfaf54dece14666John McCall    ObjCObjectTypeBits.NumProtocols = 0;
420671c3673d1e3756d8ef3cbc559fcad1d0b2f18a1fJohn McCall  }
4207c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff
42083536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
4209e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getBaseType - Gets the base type of this object type.  This is
4210e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// always (possibly sugar for) one of:
4211e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'id' builtin type (as opposed to the 'id' type visible to the
4212e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///    user, which is a typedef for an ObjCPointerType)
4213e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - the 'Class' builtin type (same caveat)
4214e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///  - an ObjCObjectType (currently always an ObjCInterfaceType)
4215c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType getBaseType() const { return BaseType; }
421671842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek
4217c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCId() const {
4218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
4219c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4220c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCClass() const {
4221c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
4222c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4223c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
4224c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
4225c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCUnqualifiedIdOrClass() const {
4226c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (!qual_empty()) return false;
4227c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
4228c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      return T->getKind() == BuiltinType::ObjCId ||
4229c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall             T->getKind() == BuiltinType::ObjCClass;
4230c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return false;
4231c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4232c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
4233c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
4234c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4235c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// Gets the interface declaration for this object type, if the base type
4236c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// really is an interface.
4237c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceDecl *getInterface() const;
4238c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4239c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCProtocolDecl * const *qual_iterator;
4240c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4241c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_begin() const { return getProtocolStorage(); }
4242c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
4243c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4244c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getNumProtocols() == 0; }
42451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4246c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// getNumProtocols - Return the number of qualifying protocols in this
4247c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  /// interface type, or 0 if there are none.
4248b870b88df784c2940efce448ebfaf54dece14666John McCall  unsigned getNumProtocols() const { return ObjCObjectTypeBits.NumProtocols; }
424914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4250c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  /// \brief Fetch a protocol by index.
425173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
425273dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    assert(I < getNumProtocols() && "Out-of-range protocol access");
425373dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor    return qual_begin()[I];
425473dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
4255ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4256bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4257bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4258bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4259c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const Type *T) {
4260c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getTypeClass() == ObjCObject ||
4261c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall           T->getTypeClass() == ObjCInterface;
4262c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4263c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static bool classof(const ObjCObjectType *) { return true; }
4264c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
4265c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4266c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCObjectTypeImpl - A class providing a concrete implementation
4267c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// of ObjCObjectType, so as to not increase the footprint of
4268c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType.  Code outside of ASTContext and the core type
4269c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// system should not reference this type.
4270c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
4271c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;
4272c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4273c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
4274c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // will need to be modified.
4275c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4276ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  ObjCObjectTypeImpl(QualType Canonical, QualType Base,
4277c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     ObjCProtocolDecl * const *Protocols,
4278c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                     unsigned NumProtocols)
4279c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Canonical, Base, Protocols, NumProtocols) {}
4280c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4281c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
4282c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff  void Profile(llvm::FoldingSetNodeID &ID);
42831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static void Profile(llvm::FoldingSetNodeID &ID,
4284c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall                      QualType Base,
4285ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                      ObjCProtocolDecl *const *protocols,
4286ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                      unsigned NumProtocols);
4287c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall};
42881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4289c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() {
4290c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return reinterpret_cast<ObjCProtocolDecl**>(
4291c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall            static_cast<ObjCObjectTypeImpl*>(this) + 1);
4292c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4293c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4294c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
4295c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// object oriented design.  They basically correspond to C++ classes.  There
4296c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// are two kinds of interface types, normal interfaces like "NSString" and
4297c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// qualified interfaces, which are qualified with a protocol list like
4298c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// "NSString<NSCopyable, NSAmazing>".
4299e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///
4300e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCInterfaceType guarantees the following properties when considered
4301e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// as a subtype of its superclass, ObjCObjectType:
4302e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - There are no protocol qualifiers.  To reinforce this, code which
4303e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     tries to invoke the protocol methods via an ObjCInterfaceType will
4304e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     fail to compile.
4305e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///   - It is its own base type.  That is, if T is an ObjCInterfaceType*,
4306e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall///     T->getBaseType() == QualType(T, 0).
4307c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallclass ObjCInterfaceType : public ObjCObjectType {
43088d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor  mutable ObjCInterfaceDecl *Decl;
4309c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4310c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCInterfaceType(const ObjCInterfaceDecl *D)
4311c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    : ObjCObjectType(Nonce_ObjCInterface),
4312c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
4313c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  friend class ASTContext;  // ASTContext creates these.
431456ca8a9c0fabd65418e9b2fd85140f4ed7d3c187Douglas Gregor  friend class ASTReader;
43158d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor  friend class ObjCInterfaceDecl;
43161fb0caaa7bef765b85972274e3b434af2572c141John McCall
4317c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallpublic:
4318e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getDecl - Get the declaration of this interface.
4319deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor  ObjCInterfaceDecl *getDecl() const { return Decl; }
4320c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4321c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool isSugared() const { return false; }
4322c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  QualType desugar() const { return QualType(this, 0); }
43230b6bc8bd7a1d2a7d7478d13d78cff94cacad61fcDouglas Gregor
43241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
43251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCInterface;
43263536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
4327a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
4328c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4329c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // Nonsense to "hide" certain members of ObjCObjectType within this
4330c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // class.  People asking for protocols on an ObjCInterfaceType are
4331c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // not going to get what they want: ObjCInterfaceTypes are
4332c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  // guaranteed to have no protocols.
4333c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  enum {
4334c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_iterator,
4335c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_begin,
4336c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    qual_end,
4337c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getNumProtocols,
4338c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    getProtocol
4339c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  };
43403536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
43413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
4342c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
4343c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  if (const ObjCInterfaceType *T =
4344c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall        getBaseType()->getAs<ObjCInterfaceType>())
4345c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return T->getDecl();
4346c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return 0;
4347c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall}
4348c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4349e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// ObjCObjectPointerType - Used to represent a pointer to an
4350e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Objective C object.  These are constructed from pointer
4351e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// declarators when the pointee type is an ObjCObjectType (or sugar
4352e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for one).  In addition, the 'id' and 'Class' types are typedefs
4353e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// for these, and the protocol-qualified types 'id<P>' and 'Class<P>'
4354e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// are translated into these.
435514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff///
4356e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// Pointers to pointers to Objective C objects are still PointerTypes;
4357e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall/// only the first level of pointer gets it own type implementation.
435814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
4359e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  QualType PointeeType;
43601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4361c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
4362561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor    : Type(ObjCObjectPointer, Canonical, false, false, false, false),
4363c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall      PointeeType(Pointee) {}
436414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
43651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
436614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic:
4367e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getPointeeType - Gets the type pointed to by this ObjC pointer.
4368e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// The result will always be an ObjCObjectType or sugar thereof.
436914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  QualType getPointeeType() const { return PointeeType; }
437014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4371e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getObjCObjectType - Gets the type pointed to by this ObjC
4372e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// pointer.  This method always returns non-null.
4373e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4374e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// This method is equivalent to getPointeeType() except that
4375e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// it discards any typedefs (or other sugar) between this
4376e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type and the "outermost" object type.  So for:
4377e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   @class A; @protocol P; @protocol Q;
4378e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A<P> AP;
4379e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A A1;
4380e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1<P> A1P;
4381e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   typedef A1P<Q> A1PQ;
4382e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A*', getObjectType() will return 'A'.
4383e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A<P>*', getObjectType() will return 'A<P>'.
4384e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'AP*', getObjectType() will return 'A<P>'.
4385e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1*', getObjectType() will return 'A'.
4386e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
4387e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1P*', getObjectType() will return 'A1<P>'.
4388e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
4389e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   adding protocols to a protocol-qualified base discards the
4390e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   old qualifiers (for now).  But if it didn't, getObjectType()
4391e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   would return 'A1P<Q>' (and we'd have to make iterating over
4392e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///   qualifiers more complicated).
4393c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  const ObjCObjectType *getObjectType() const {
4394d0370f59e79702ac908c81bf556519f91e9ca297John McCall    return PointeeType->castAs<ObjCObjectType>();
4395c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
4396c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall
4397e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceType - If this pointer points to an Objective C
4398e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// @interface type, gets the type for that interface.  Any protocol
4399e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// qualifiers on the interface are ignored.
4400e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4401e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
44021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  const ObjCInterfaceType *getInterfaceType() const {
4403c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getBaseType()->getAs<ObjCInterfaceType>();
440414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4405e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4406e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getInterfaceDecl - If this pointer points to an Objective @interface
4407e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type, gets the declaration for that interface.
4408e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  ///
4409e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \return null if the base type for this pointer is 'id' or 'Class'
441014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  ObjCInterfaceDecl *getInterfaceDecl() const {
4411e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    return getObjectType()->getInterface();
441214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4413e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4414e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCIdType - True if this is equivalent to the 'id' type, i.e. if
4415e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// its object type is the primitive 'id' type with no protocols.
441614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCIdType() const {
4417c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedId();
441814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4419e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4420e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCClassType - True if this is equivalent to the 'Class' type,
4421e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
442214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  bool isObjCClassType() const {
4423c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCUnqualifiedClass();
4424de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
4425ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4426e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedIdType - True if this is equivalent to 'id<P>' for some
4427e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// non-empty set of protocols.
44281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  bool isObjCQualifiedIdType() const {
4429c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedId();
4430de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff  }
4431e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4432e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// isObjCQualifiedClassType - True if this is equivalent to 'Class<P>' for
4433e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// some non-empty set of protocols.
4434470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  bool isObjCQualifiedClassType() const {
4435c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->isObjCQualifiedClass();
443614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
4437e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall
4438e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// An iterator over the qualifiers on the object type.  Provided
4439e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// for convenience.  This will always iterate over the full set of
4440e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// protocols on a type, not just those provided directly.
4441c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  typedef ObjCObjectType::qual_iterator qual_iterator;
444214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
444371842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  qual_iterator qual_begin() const {
4444c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_begin();
444571842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4446c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  qual_iterator qual_end() const {
4447c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->qual_end();
444871842cc07aafdebc9b180322ebb46f530beca5d6Ted Kremenek  }
4449c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  bool qual_empty() const { return getObjectType()->qual_empty(); }
445014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4451e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// getNumProtocols - Return the number of qualifying protocols on
4452e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// the object type.
4453c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  unsigned getNumProtocols() const {
4454c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getNumProtocols();
4455c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
445614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff
4457e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// \brief Retrieve a qualifying protocol by index on the object
4458e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  /// type.
445973dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  ObjCProtocolDecl *getProtocol(unsigned I) const {
4460c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    return getObjectType()->getProtocol(I);
446173dc30b71e218ba2b776b10d07dc2aff09cb2c47Douglas Gregor  }
4462ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4463bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  bool isSugared() const { return false; }
4464bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  QualType desugar() const { return QualType(this, 0); }
4465bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall
4466e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  void Profile(llvm::FoldingSetNodeID &ID) {
4467e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall    Profile(ID, getPointeeType());
4468e175a6f6ede0ae31165a18ac8bf4e8d2681b39f8John McCall  }
4469c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4470c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall    ID.AddPointer(T.getAsOpaquePtr());
4471c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  }
44721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  static bool classof(const Type *T) {
44731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump    return T->getTypeClass() == ObjCObjectPointer;
447414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  }
447514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  static bool classof(const ObjCObjectPointerType *) { return true; }
447614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff};
44771bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis
4478b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmanclass AtomicType : public Type, public llvm::FoldingSetNode {
4479b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType ValueType;
4480b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4481b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  AtomicType(QualType ValTy, QualType Canonical)
4482b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    : Type(Atomic, Canonical, ValTy->isDependentType(),
4483b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman           ValTy->isInstantiationDependentType(),
4484b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman           ValTy->isVariablyModifiedType(),
4485b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman           ValTy->containsUnexpandedParameterPack()),
4486b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman      ValueType(ValTy) {}
4487b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  friend class ASTContext;  // ASTContext creates these.
4488b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4489b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  public:
4490b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// getValueType - Gets the type contained by this atomic type, i.e.
4491b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  /// the type returned by performing an atomic load of this atomic type.
4492b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType getValueType() const { return ValueType; }
4493b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4494b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  bool isSugared() const { return false; }
4495b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  QualType desugar() const { return QualType(this, 0); }
4496b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
4497b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  void Profile(llvm::FoldingSetNodeID &ID) {
4498b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    Profile(ID, getValueType());
4499b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4500b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
4501b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    ID.AddPointer(T.getAsOpaquePtr());
4502b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4503b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  static bool classof(const Type *T) {
4504b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman    return T->getTypeClass() == Atomic;
4505b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  }
4506b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  static bool classof(const AtomicType *) { return true; }
4507b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman};
4508b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman
45090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// A qualifier set is used to build a set of qualifiers.
45100953e767ff7817f97b3ab20896b229891eeff45bJohn McCallclass QualifierCollector : public Qualifiers {
45110953e767ff7817f97b3ab20896b229891eeff45bJohn McCallpublic:
451249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {}
45130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Collect any qualifiers on the given type and return an
45153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// unqualified type.  The qualifiers are assumed to be consistent
45163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  /// with those already in the type.
45173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *strip(QualType type) {
45183b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addFastQualifiers(type.getLocalFastQualifiers());
45193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    if (!type.hasLocalNonFastQualifiers())
45203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      return type.getTypePtrUnsafe();
4521ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
45223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    const ExtQuals *extQuals = type.getExtQualsUnsafe();
45233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    addConsistentQualifiers(extQuals->getQualifiers());
45243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return extQuals->getBaseType();
45250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
45260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
45284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, QualType QT) const;
45290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  /// Apply the collected qualifiers to the given type.
45314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType apply(const ASTContext &Context, const Type* T) const;
45320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall};
45330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
45340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
4535611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
45365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4537200fa53fd420aa8369586f569dbece04930ad6a3John McCallinline SplitQualType SplitQualType::getSingleStepDesugaredType() const {
4538200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType desugar =
4539200fa53fd420aa8369586f569dbece04930ad6a3John McCall    Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
4540200fa53fd420aa8369586f569dbece04930ad6a3John McCall  desugar.Quals.addConsistentQualifiers(Quals);
4541200fa53fd420aa8369586f569dbece04930ad6a3John McCall  return desugar;
4542200fa53fd420aa8369586f569dbece04930ad6a3John McCall}
4543200fa53fd420aa8369586f569dbece04930ad6a3John McCall
45443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtr() const {
45453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getCommonPtr()->BaseType;
45463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const Type *QualType::getTypePtrOrNull() const {
45493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return (isNull() ? 0 : getCommonPtr()->BaseType);
45503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline SplitQualType QualType::split() const {
45533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!hasLocalNonFastQualifiers())
45543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return SplitQualType(getTypePtrUnsafe(),
45553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall                         Qualifiers::fromFastMask(getLocalFastQualifiers()));
45563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQuals *eq = getExtQualsUnsafe();
45583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers qs = eq->getQualifiers();
45593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  qs.addFastQualifiers(getLocalFastQualifiers());
45603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return SplitQualType(eq->getBaseType(), qs);
45613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getLocalQualifiers() const {
45643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers Quals;
45653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (hasLocalNonFastQualifiers())
45663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    Quals = getExtQualsUnsafe()->getQualifiers();
45673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Quals.addFastQualifiers(getLocalFastQualifiers());
45683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return Quals;
45693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline Qualifiers QualType::getQualifiers() const {
45723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
45733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  quals.addFastQualifiers(getLocalFastQualifiers());
45743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return quals;
45753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline unsigned QualType::getCVRQualifiers() const {
45783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
45793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  cvr |= getLocalCVRQualifiers();
45803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cvr;
45813b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
45833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline QualType QualType::getCanonicalType() const {
45843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType canon = getCommonPtr()->CanonicalType;
45853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return canon.withFastQualifiers(getLocalFastQualifiers());
45863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
45873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
4588467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCallinline bool QualType::isCanonical() const {
45893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getTypePtr()->isCanonicalUnqualified();
4590467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall}
4591467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall
459254e14c4db764c0636160d26c5bbf491637c83a76John McCallinline bool QualType::isCanonicalAsParam() const {
45933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isCanonical()) return false;
4594a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  if (hasLocalQualifiers()) return false;
4595ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
459654e14c4db764c0636160d26c5bbf491637c83a76John McCall  const Type *T = getTypePtr();
45973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (T->isVariablyModifiedType() && T->hasSizedVLAType())
45983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return false;
45993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
46003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return !isa<FunctionType>(T) && !isa<ArrayType>(T);
460154e14c4db764c0636160d26c5bbf491637c83a76John McCall}
460254e14c4db764c0636160d26c5bbf491637c83a76John McCall
4603fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isConstQualified() const {
4604ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isLocalConstQualified() ||
46053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalConstQualified();
4606fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4607fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4608fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isRestrictQualified() const {
4609ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isLocalRestrictQualified() ||
46103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalRestrictQualified();
4611fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4612fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4613fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor
4614fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::isVolatileQualified() const {
4615ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isLocalVolatileQualified() ||
46163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.isLocalVolatileQualified();
4617fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4618ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4619fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregorinline bool QualType::hasQualifiers() const {
4620fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor  return hasLocalQualifiers() ||
46213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall         getCommonPtr()->CanonicalType.hasLocalQualifiers();
4622fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
462362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
462462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline QualType QualType::getUnqualifiedType() const {
462562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
462662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return QualType(getTypePtr(), 0);
462762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
4628200fa53fd420aa8369586f569dbece04930ad6a3John McCall  return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
462962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall}
463062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
463162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline SplitQualType QualType::getSplitUnqualifiedType() const {
463262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
463362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    return split();
463462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
463562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getSplitUnqualifiedTypeImpl(*this);
4636fa1a06e80706846fa15e0bd44671bdc3dfc53d84Douglas Gregor}
4637ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
463849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalConst() {
463949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Const);
46400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
46410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
464249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalRestrict() {
464349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Restrict);
46440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
46450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
464649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalVolatile() {
464749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Qualifiers::Volatile);
46480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall}
46490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
465049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCallinline void QualType::removeLocalCVRQualifiers(unsigned Mask) {
46516b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall  assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits");
4652c3c0af36bac3d71f61dd758585ab307892545de4Douglas Gregor  assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask);
46530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
46540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // Fast path: we don't need to touch the slow qualifiers.
465549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  removeLocalFastQualifiers(Mask);
4656ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4657ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb
4658ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type.
4659ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const {
46603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getAddressSpace();
4661ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}
4662611c1fff195d32df97706e0920c92468b2509900Chris Lattner
4663d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type.
46640953e767ff7817f97b3ab20896b229891eeff45bJohn McCallinline Qualifiers::GC QualType::getObjCGCAttr() const {
46653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return getQualifiers().getObjCGCAttr();
4666d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian}
46672455636163fdd18581d7fdae816433f886d88213Mike Stump
4668264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) {
4669264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  if (const PointerType *PT = t.getAs<PointerType>()) {
4670183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall    if (const FunctionType *FT = PT->getPointeeType()->getAs<FunctionType>())
4671264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola      return FT->getExtInfo();
4672264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  } else if (const FunctionType *FT = t.getAs<FunctionType>())
4673264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola    return FT->getExtInfo();
46742455636163fdd18581d7fdae816433f886d88213Mike Stump
4675264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return FunctionType::ExtInfo();
46762455636163fdd18581d7fdae816433f886d88213Mike Stump}
46771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4678264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindolainline FunctionType::ExtInfo getFunctionExtInfo(QualType t) {
4679264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola  return getFunctionExtInfo(*t);
4680ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor}
4681ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor
4682e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more
4683e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int"
4684e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and
4685e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile
4686e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int".
468762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isMoreQualifiedThan(QualType other) const {
468862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers myQuals = getQualifiers();
468962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  Qualifiers otherQuals = other.getQualifiers();
469062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return (myQuals != otherQuals && myQuals.compatiblyIncludes(otherQuals));
4691e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4692e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4693e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last
4694e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile
4695e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int",
4696e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int".
469762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallinline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
469862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  return getQualifiers().compatiblyIncludes(other.getQualifiers());
4699e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4700e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
4701e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const
4702e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const
4703e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used
4704e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6:
4705e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///
4706e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   If an expression initially has the type "reference to T" (8.3.2,
4707e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   8.5.3), the type is adjusted to "T" prior to any further
4708e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   analysis, the expression designates the object or function
4709e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor///   denoted by the reference, and the expression is an lvalue.
4710e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const {
47116217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
4712e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return RefType->getPointeeType();
4713e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor  else
4714e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor    return *this;
4715e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor}
4716e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor
47172b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregorinline bool QualType::isCForbiddenLValueType() const {
47182b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor  return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
47192b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor          getTypePtr()->isFunctionType());
47202b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor}
47212b1ad8b42bbbe00a1845e566f52f1941b8dbc725Douglas Gregor
4722aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a fundamental type.
4723aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4724aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.fundamental].
4725aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isFundamentalType() const {
4726aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isVoidType() ||
4727aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // FIXME: It's really annoying that we don't have an
4728aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         // 'isArithmeticType()' which agrees with the standard definition.
4729aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         (isArithmeticType() && !isEnumeralType());
4730aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4731aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4732aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \brief Tests whether the type is categorized as a compound type.
4733aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth///
4734aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth/// \returns True for types specified in C++0x [basic.compound].
4735aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruthinline bool Type::isCompoundType() const {
4736aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  // C++0x [basic.compound]p1:
4737aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //   Compound types can be constructed in the following ways:
4738aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- arrays of objects of a given type [...];
4739aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  return isArrayType() ||
4740aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- functions, which have parameters of given types [...];
4741aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isFunctionType() ||
4742aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to void or objects or functions [...];
4743aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isPointerType() ||
4744aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- references to objects or functions of a given type. [...]
4745aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isReferenceType() ||
4746aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- classes containing a sequence of objects of various types, [...];
4747aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isRecordType() ||
4748ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //    -- unions, which are classes capable of containing objects of different
4749ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  //               types at different times;
4750aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isUnionType() ||
4751aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- enumerations, which comprise a set of named constant values. [...];
4752aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isEnumeralType() ||
4753aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth  //    -- pointers to non-static class members, [...].
4754aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth         isMemberPointerType();
4755aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth}
4756aaf147be3cc7403d8f7889d363421bb291ef23f2Chandler Carruth
4757611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
4758a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<FunctionType>(CanonicalType);
4759611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4760611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
4761a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<PointerType>(CanonicalType);
4762611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
476358f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const {
476458f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff  return isPointerType() || isObjCObjectPointerType();
476558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff}
47665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const {
4767a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<BlockPointerType>(CanonicalType);
47685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}
4769bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const {
4770a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ReferenceType>(CanonicalType);
4771bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}
47727c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const {
4773a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<LValueReferenceType>(CanonicalType);
47747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
47757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const {
4776a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RValueReferenceType>(CanonicalType);
47777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}
4778498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
4779d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const PointerType *T = getAs<PointerType>())
4780498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
4781498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
4782498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
4783498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
4784f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const {
4785a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<MemberPointerType>(CanonicalType);
4786f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4787f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const {
47886217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek  if (const MemberPointerType* T = getAs<MemberPointerType>())
47890bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberFunctionPointer();
4790f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl  else
4791f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl    return false;
4792f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}
4793db68e28c05a67735211e688009890cf834c22e75Douglas Gregorinline bool Type::isMemberDataPointerType() const {
4794db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  if (const MemberPointerType* T = getAs<MemberPointerType>())
47950bab0cdab751248ca389a5592bcb70eac5d39260John McCall    return T->isMemberDataPointer();
4796db68e28c05a67735211e688009890cf834c22e75Douglas Gregor  else
4797db68e28c05a67735211e688009890cf834c22e75Douglas Gregor    return false;
4798db68e28c05a67735211e688009890cf834c22e75Douglas Gregor}
4799611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
4800a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ArrayType>(CanonicalType);
4801611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4802c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const {
4803a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ConstantArrayType>(CanonicalType);
4804c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4805c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const {
4806a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<IncompleteArrayType>(CanonicalType);
4807c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4808c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const {
4809a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VariableArrayType>(CanonicalType);
4810c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner}
4811898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const {
4812a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<DependentSizedArrayType>(CanonicalType);
4813898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}
48143ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isBuiltinType() const {
48153ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<BuiltinType>(CanonicalType);
48163ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4817611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
4818a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<RecordType>(CanonicalType);
4819611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
48203ff83dd534ccc828203670ce3f5125a4eb4199f8John McCallinline bool Type::isEnumeralType() const {
48213ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall  return isa<EnumType>(CanonicalType);
48223ff83dd534ccc828203670ce3f5125a4eb4199f8John McCall}
4823f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const {
4824a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ComplexType>(CanonicalType);
4825f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner}
4826611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
4827a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<VectorType>(CanonicalType);
4828611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4829213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const {
4830a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ExtVectorType>(CanonicalType);
4831611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
4832d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const {
4833a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<ObjCObjectPointerType>(CanonicalType);
4834d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}
4835c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallinline bool Type::isObjCObjectType() const {
4836c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isa<ObjCObjectType>(CanonicalType);
4837368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner}
4838569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorinline bool Type::isObjCObjectOrInterfaceType() const {
4839ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  return isa<ObjCInterfaceType>(CanonicalType) ||
4840569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor    isa<ObjCObjectType>(CanonicalType);
4841569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor}
4842b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmaninline bool Type::isAtomicType() const {
4843b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman  return isa<AtomicType>(CanonicalType);
4844b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman}
4845569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor
4846a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
4847183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4848d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff    return OPT->isObjCQualifiedIdType();
4849d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff  return false;
4850d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
4851470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const {
4852183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
4853470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff    return OPT->isObjCQualifiedClassType();
4854470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff  return false;
4855470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff}
485614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const {
4857183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
485814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCIdType();
485914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
486014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
486114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const {
4862183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
486314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff    return OPT->isObjCClassType();
486414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff  return false;
486514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}
486613dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanianinline bool Type::isObjCSelType() const {
48678d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian  if (const PointerType *OPT = getAs<PointerType>())
48688d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian    return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
486913dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return false;
487013dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian}
4871de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const {
487213dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian  return isObjCIdType() || isObjCClassType() || isObjCSelType();
4873de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff}
487472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const {
4875a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor  return isa<TemplateTypeParmType>(CanonicalType);
487672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}
487772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor
4878e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const {
4879183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall  if (const BuiltinType *BT = getAs<BuiltinType>())
4880e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar    if (BT->getKind() == (BuiltinType::Kind) K)
4881e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar      return true;
4882e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar  return false;
4883e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar}
4884e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar
48852a984cad5ac3fdceeff2bd99daa7b90979313475John McCallinline bool Type::isPlaceholderType() const {
4886a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
48872a984cad5ac3fdceeff2bd99daa7b90979313475John McCall    return BT->isPlaceholderType();
48882a984cad5ac3fdceeff2bd99daa7b90979313475John McCall  return false;
48892a984cad5ac3fdceeff2bd99daa7b90979313475John McCall}
48902a984cad5ac3fdceeff2bd99daa7b90979313475John McCall
4891a180f04c091bf3ede4fe292ba6a29d61da09e936John McCallinline const BuiltinType *Type::getAsPlaceholderType() const {
4892a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4893a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall    if (BT->isPlaceholderType())
4894a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall      return BT;
4895a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall  return 0;
4896a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall}
4897a180f04c091bf3ede4fe292ba6a29d61da09e936John McCall
4898864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCallinline bool Type::isSpecificPlaceholderType(unsigned K) const {
489985def357129b6cdfd69a66ad0e6994506418a2a9John McCall  assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
4900864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
4901864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    return (BT->getKind() == (BuiltinType::Kind) K);
4902864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall  return false;
4903864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall}
4904864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall
490532509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCallinline bool Type::isNonOverloadPlaceholderType() const {
490632509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  if (const BuiltinType *BT = dyn_cast<BuiltinType>(this))
490732509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall    return BT->isNonOverloadPlaceholderType();
490832509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall  return false;
490932509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall}
491032509f1e60451d86e9fbc473b6e853ba10b5fd1eJohn McCall
4911cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbarinline bool Type::isVoidType() const {
4912cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4913cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar    return BT->getKind() == BuiltinType::Void;
4914cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar  return false;
4915cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar}
4916cd485926f1ffda2eaa9adeea34e1e15c35ab5fbaDaniel Dunbar
4917f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isHalfType() const {
4918f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4919f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() == BuiltinType::Half;
4920f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  // FIXME: Should we allow complex __fp16? Probably not.
4921f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
4922f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4923f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4924f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isNullPtrType() const {
4925f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = getAs<BuiltinType>())
4926f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() == BuiltinType::NullPtr;
4927f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
4928f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4929f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4930f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarextern bool IsEnumDeclComplete(EnumDecl *);
493176e035a529775dc8fd31124f819745a33a085796Daniel Dunbarextern bool IsEnumDeclScoped(EnumDecl *);
493276e035a529775dc8fd31124f819745a33a085796Daniel Dunbar
493376e035a529775dc8fd31124f819745a33a085796Daniel Dunbarinline bool Type::isIntegerType() const {
493476e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
493576e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    return BT->getKind() >= BuiltinType::Bool &&
493676e035a529775dc8fd31124f819745a33a085796Daniel Dunbar           BT->getKind() <= BuiltinType::Int128;
493776e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
493876e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    // Incomplete enum types are not treated as integer types.
493976e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    // FIXME: In C++, enum types are never integer types.
494076e035a529775dc8fd31124f819745a33a085796Daniel Dunbar    return IsEnumDeclComplete(ET->getDecl()) &&
494176e035a529775dc8fd31124f819745a33a085796Daniel Dunbar      !IsEnumDeclScoped(ET->getDecl());
494276e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  }
494376e035a529775dc8fd31124f819745a33a085796Daniel Dunbar  return false;
494476e035a529775dc8fd31124f819745a33a085796Daniel Dunbar}
4945f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4946f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isScalarType() const {
4947f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4948f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() > BuiltinType::Void &&
4949f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar           BT->getKind() <= BuiltinType::NullPtr;
4950f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
4951f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    // Enums are scalar types, but only if they are defined.  Incomplete enums
4952f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    // are not treated as scalar types.
4953f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return IsEnumDeclComplete(ET->getDecl());
4954f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return isa<PointerType>(CanonicalType) ||
4955f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<BlockPointerType>(CanonicalType) ||
4956f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<MemberPointerType>(CanonicalType) ||
4957f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<ComplexType>(CanonicalType) ||
4958f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar         isa<ObjCObjectPointerType>(CanonicalType);
4959f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4960f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4961f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isIntegralOrEnumerationType() const {
4962f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4963f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() >= BuiltinType::Bool &&
4964f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar           BT->getKind() <= BuiltinType::Int128;
4965f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4966f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  // Check for a complete enum type; incomplete enum types are not properly an
4967f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  // enumeration type in the sense required here.
4968f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
4969f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return IsEnumDeclComplete(ET->getDecl());
4970f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4971f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
4972f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4973f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4974f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbarinline bool Type::isBooleanType() const {
4975f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
4976f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar    return BT->getKind() == BuiltinType::Bool;
4977f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar  return false;
4978f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar}
4979f9aa3635fccb3dc0925ef4d27dfa2b692a8e6a90Daniel Dunbar
4980063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define
4981063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator.
4982063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const {
4983063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor  return isDependentType() || isRecordType() || isEnumeralType();
4984904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor}
4985904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor
4986bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth/// \brief Determines whether this type can decay to a pointer type.
4987bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruthinline bool Type::canDecayToPointerType() const {
4988bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth  return isFunctionType() || isArrayType();
4989bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth}
4990bc8d7f9fd4346cfcc285868be32b74e019a40f01Chandler Carruth
49918958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const {
49928958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
4993c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall          isObjCObjectPointerType() || isNullPtrType());
49948958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar}
49958958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar
4996820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const {
4997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall  return isObjCObjectPointerType();
4998820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian}
4999820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian
5000d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const Type *Type::getBaseElementTypeUnsafe() const {
5001d0370f59e79702ac908c81bf556519f91e9ca297John McCall  const Type *type = this;
5002d0370f59e79702ac908c81bf556519f91e9ca297John McCall  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
5003d0370f59e79702ac908c81bf556519f91e9ca297John McCall    type = arrayType->getElementType().getTypePtr();
5004d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return type;
5005d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
5006d0370f59e79702ac908c81bf556519f91e9ca297John McCall
500722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics.  This allows sending QualType's into a
500822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<.
5009d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
5010d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                           QualType T) {
5011d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
5012d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                  DiagnosticsEngine::ak_qualtype);
5013d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  return DB;
5014d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer}
50151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
501647c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// Insertion operator for partial diagnostics.  This allows sending QualType's
501747c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth/// into a diagnostic with <<.
5018d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramerinline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
5019d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                                           QualType T) {
5020d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
5021d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer                  DiagnosticsEngine::ak_qualtype);
5022d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer  return PD;
5023d7a3e2c5f61cd4893f95b69a424fe4def3aa0f69Benjamin Kramer}
502447c24b1d94f446c43e3a64732867eabed7d9c961Chandler Carruth
502589c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// Helper class template that is used by Type::getAs to ensure that one does
502689c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor// not try to look through a qualified type to get to an array type.
502789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T,
502889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor         bool isArrayType = (llvm::is_same<T, ArrayType>::value ||
502989c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor                             llvm::is_base_of<ArrayType, T>::value)>
503089c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs { };
5031ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
503289c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregortemplate<typename T>
503389c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregorstruct ArrayType_cannot_be_used_with_getAs<T, true>;
5034ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
50351a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'.
50361a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const {
503789c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  ArrayType_cannot_be_used_with_getAs<T> at;
503889c49f09b0292dc7c03885f6c765d667a9837597Douglas Gregor  (void)at;
5039ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
50401a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If this is directly a T type, return it.
50411a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  if (const T *Ty = dyn_cast<T>(this))
50421a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return Ty;
50431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50441a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // If the canonical form of this type isn't the right kind, reject it.
50450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  if (!isa<T>(CanonicalType))
50461a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek    return 0;
50471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
50480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  // If this is a typedef for the type, strip the typedef off without
50491a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek  // losing all typedef information.
5050bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  return cast<T>(getUnqualifiedDesugaredType());
50511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump}
505222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner
50533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallinline const ArrayType *Type::getAsArrayTypeUnsafe() const {
50543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is directly an array type, return it.
50553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this))
50563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return arr;
50573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
50583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If the canonical form of this type isn't the right kind, reject it.
50593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  if (!isa<ArrayType>(CanonicalType))
50603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return 0;
50613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
50623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // If this is a typedef for the type, strip the typedef off without
50633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  // losing all typedef information.
50643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
50653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall}
50663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
5067d0370f59e79702ac908c81bf556519f91e9ca297John McCalltemplate <typename T> const T *Type::castAs() const {
5068d0370f59e79702ac908c81bf556519f91e9ca297John McCall  ArrayType_cannot_be_used_with_getAs<T> at;
5069d0370f59e79702ac908c81bf556519f91e9ca297John McCall  (void) at;
5070d0370f59e79702ac908c81bf556519f91e9ca297John McCall
5071d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<T>(CanonicalType));
5072d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const T *ty = dyn_cast<T>(this)) return ty;
5073d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<T>(getUnqualifiedDesugaredType());
5074d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
5075d0370f59e79702ac908c81bf556519f91e9ca297John McCall
5076d0370f59e79702ac908c81bf556519f91e9ca297John McCallinline const ArrayType *Type::castAsArrayTypeUnsafe() const {
5077d0370f59e79702ac908c81bf556519f91e9ca297John McCall  assert(isa<ArrayType>(CanonicalType));
5078d0370f59e79702ac908c81bf556519f91e9ca297John McCall  if (const ArrayType *arr = dyn_cast<ArrayType>(this)) return arr;
5079d0370f59e79702ac908c81bf556519f91e9ca297John McCall  return cast<ArrayType>(getUnqualifiedDesugaredType());
5080d0370f59e79702ac908c81bf556519f91e9ca297John McCall}
5081d0370f59e79702ac908c81bf556519f91e9ca297John McCall
50825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
50835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
50845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
5085