1ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
2ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//
3ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//                     The LLVM Compiler Infrastructure
4ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//
5ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// This file is distributed under the University of Illinois Open Source
6ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao// License. See LICENSE.TXT for details.
7ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//
8ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//===----------------------------------------------------------------------===//
9ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//
10ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//  This file defines the Type interface and subclasses.
11ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//
12ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao//===----------------------------------------------------------------------===//
13ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
14ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#ifndef LLVM_CLANG_AST_TYPE_H
15ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define LLVM_CLANG_AST_TYPE_H
16ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
1730a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/NestedNameSpecifier.h"
1830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/AST/TemplateName.h"
19ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/Diagnostic.h"
208b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl#include "clang/Basic/ExceptionSpecificationType.h"
2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/LLVM.h"
22ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/Linkage.h"
23ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/Basic/PartialDiagnostic.h"
2482bfa19fe3be324b13fdbcda46304b52c500f0d4Aaron Ballman#include "clang/Basic/Specifiers.h"
2582254439b368de855d1e66440071017a1f2d4f0aJohn McCall#include "clang/Basic/Visibility.h"
266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "llvm/ADT/APInt.h"
27ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/FoldingSet.h"
28651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include "llvm/ADT/iterator_range.h"
29cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor#include "llvm/ADT/Optional.h"
30ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/PointerIntPair.h"
31ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "llvm/ADT/PointerUnion.h"
327ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis#include "llvm/ADT/Twine.h"
3330a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/Support/ErrorHandling.h"
34ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
35ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace clang {
36ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  enum {
37f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    TypeAlignmentInBits = 4,
38ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    TypeAlignment = 1 << TypeAlignmentInBits
39ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  };
40ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class Type;
41ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class ExtQuals;
42ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class QualType;
43ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}
44ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
45ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace llvm {
46ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  template <typename T>
47ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class PointerLikeTypeTraits;
48ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  template<>
49ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class PointerLikeTypeTraits< ::clang::Type*> {
50ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  public:
51ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
52ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    static inline ::clang::Type *getFromVoidPointer(void *P) {
53ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao      return static_cast< ::clang::Type*>(P);
54ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    }
55ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
56ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  };
57ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  template<>
58ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class PointerLikeTypeTraits< ::clang::ExtQuals*> {
59ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  public:
60ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
61ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
62ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao      return static_cast< ::clang::ExtQuals*>(P);
63ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    }
64ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    enum { NumLowBitsAvailable = clang::TypeAlignmentInBits };
65ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  };
66ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
67ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  template <>
68ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  struct isPodLike<clang::QualType> { static const bool value = true; };
69ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao}
70ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
71ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaonamespace clang {
72ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class ASTContext;
73162e1c1b487352434552147967c3dd296ebee2f7Richard Smith  class TypedefNameDecl;
74ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TemplateDecl;
75ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TemplateTypeParmDecl;
76ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class NonTypeTemplateParmDecl;
77ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TemplateTemplateParmDecl;
78ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TagDecl;
79ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class RecordDecl;
80ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class CXXRecordDecl;
81ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class EnumDecl;
82ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class FieldDecl;
83e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith  class FunctionDecl;
84ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class ObjCInterfaceDecl;
85ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class ObjCProtocolDecl;
86ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class ObjCMethodDecl;
87ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class UnresolvedUsingTypenameDecl;
88ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class Expr;
89ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class Stmt;
90ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class SourceLocation;
91ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class StmtIteratorBase;
92ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TemplateArgument;
93ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TemplateArgumentLoc;
94ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  class TemplateArgumentListInfo;
95ab1f1819386bd718899582eb6426b2619b11e2cfAbramo Bagnara  class ElaboratedType;
963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQuals;
973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  class ExtQualsTypeCommonBase;
98ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  struct PrintingPolicy;
99ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
100b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  template <typename> class CanQual;
101ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  typedef CanQual<Type> CanQualType;
102ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
103ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Provide forward declarations for all of the *Type classes
104ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#define TYPE(Class, Base) class Class##Type;
105ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao#include "clang/AST/TypeNodes.def"
106ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
107ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Qualifiers - The collection of all-type qualifiers we support.
108ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// Clang supports five independent qualifiers:
109ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// * C99: const, volatile, and restrict
110ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// * Embedded C (TR18037): address spaces
111ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// * Objective C: the GC attributes (none, weak, or strong)
112ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass Qualifiers {
113ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic:
114ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
115ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Const    = 0x1,
116ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Restrict = 0x2,
117ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Volatile = 0x4,
118ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    CVRMask = Const | Volatile | Restrict
119ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  };
120ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
121ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  enum GC {
122ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    GCNone = 0,
123ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Weak,
124ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Strong
125ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  };
126ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
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
149ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  enum {
150ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    /// The maximum supported address space number.
151ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    /// 24 bits should be enough for anyone.
152ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    MaxAddressSpace = 0xffffffu,
153ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
154ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    /// The width of the "fast" qualifier mask.
155f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    FastWidth = 3,
156ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
157ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    /// The fast qualifier mask.
158ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    FastMask = (1 << FastWidth) - 1
159ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  };
160ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
161ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  Qualifiers() : Mask(0) {}
162ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
163e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  /// \brief Returns the common set of qualifiers while removing them from
164e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  /// the given sets.
165e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) {
166e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    // If both are only CVR-qualified, bit operations are sufficient.
167e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
168e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Qualifiers Q;
169e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.Mask = L.Mask & R.Mask;
170e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.Mask &= ~Q.Mask;
171e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.Mask &= ~Q.Mask;
172e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      return Q;
173e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
174e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
175e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    Qualifiers Q;
176e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
177e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    Q.addCVRQualifiers(CommonCRV);
178e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    L.removeCVRQualifiers(CommonCRV);
179e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    R.removeCVRQualifiers(CommonCRV);
180e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
181e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
182e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.setObjCGCAttr(L.getObjCGCAttr());
183e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.removeObjCGCAttr();
184e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.removeObjCGCAttr();
185e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
186e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
187e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (L.getObjCLifetime() == R.getObjCLifetime()) {
188e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.setObjCLifetime(L.getObjCLifetime());
189e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.removeObjCLifetime();
190e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.removeObjCLifetime();
191e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
192e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
193e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (L.getAddressSpace() == R.getAddressSpace()) {
194e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Q.setAddressSpace(L.getAddressSpace());
195e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      L.removeAddressSpace();
196e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      R.removeAddressSpace();
197e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
198e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    return Q;
199e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  }
200e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
201ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  static Qualifiers fromFastMask(unsigned Mask) {
202ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qualifiers Qs;
203ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qs.addFastQualifiers(Mask);
204ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Qs;
205ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
206ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
207ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  static Qualifiers fromCVRMask(unsigned CVR) {
208ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qualifiers Qs;
209ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qs.addCVRQualifiers(CVR);
210ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Qs;
211ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
212ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
213ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Deserialize qualifiers from an opaque representation.
214ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  static Qualifiers fromOpaqueValue(unsigned opaque) {
215ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qualifiers Qs;
216ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qs.Mask = opaque;
217ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Qs;
218ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
219ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
220ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Serialize these qualifiers into an opaque representation.
221ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getAsOpaqueValue() const {
222ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Mask;
223ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
224ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
225ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasConst() const { return Mask & Const; }
226ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setConst(bool flag) {
227ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~Const) | (flag ? Const : 0);
228ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
229ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeConst() { Mask &= ~Const; }
230ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addConst() { Mask |= Const; }
231ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
232ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasVolatile() const { return Mask & Volatile; }
233ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setVolatile(bool flag) {
234ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~Volatile) | (flag ? Volatile : 0);
235ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
236ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeVolatile() { Mask &= ~Volatile; }
237ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addVolatile() { Mask |= Volatile; }
238ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
239ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasRestrict() const { return Mask & Restrict; }
240ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setRestrict(bool flag) {
241ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~Restrict) | (flag ? Restrict : 0);
242ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
243ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeRestrict() { Mask &= ~Restrict; }
244ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addRestrict() { Mask |= Restrict; }
245ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
246ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
247ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
248ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setCVRQualifiers(unsigned mask) {
249ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
250ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~CVRMask) | mask;
251ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
252ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeCVRQualifiers(unsigned mask) {
253ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
254ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask &= ~mask;
255ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
256ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeCVRQualifiers() {
257ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    removeCVRQualifiers(CVRMask);
258ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
259ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addCVRQualifiers(unsigned mask) {
260ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
261ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask |= mask;
262ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
263ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
264ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
265ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
266ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setObjCGCAttr(GC type) {
267ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
268ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
269ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeObjCGCAttr() { setObjCGCAttr(GCNone); }
270ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addObjCGCAttr(GC type) {
271ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(type);
272ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    setObjCGCAttr(type);
273ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
2742234873111009eb8655d63362cedc422eb9fc517John McCall  Qualifiers withoutObjCGCAttr() const {
2752234873111009eb8655d63362cedc422eb9fc517John McCall    Qualifiers qs = *this;
2762234873111009eb8655d63362cedc422eb9fc517John McCall    qs.removeObjCGCAttr();
2772234873111009eb8655d63362cedc422eb9fc517John McCall    return qs;
2782234873111009eb8655d63362cedc422eb9fc517John McCall  }
279200fa53fd420aa8369586f569dbece04930ad6a3John McCall  Qualifiers withoutObjCLifetime() const {
280f85e193739c953358c865005855253af4f68a497John McCall    Qualifiers qs = *this;
281f85e193739c953358c865005855253af4f68a497John McCall    qs.removeObjCLifetime();
282f85e193739c953358c865005855253af4f68a497John McCall    return qs;
283f85e193739c953358c865005855253af4f68a497John McCall  }
2840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
285f85e193739c953358c865005855253af4f68a497John McCall  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
286f85e193739c953358c865005855253af4f68a497John McCall  ObjCLifetime getObjCLifetime() const {
287f85e193739c953358c865005855253af4f68a497John McCall    return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
288f85e193739c953358c865005855253af4f68a497John McCall  }
289f85e193739c953358c865005855253af4f68a497John McCall  void setObjCLifetime(ObjCLifetime type) {
290f85e193739c953358c865005855253af4f68a497John McCall    Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
291f85e193739c953358c865005855253af4f68a497John McCall  }
292f85e193739c953358c865005855253af4f68a497John McCall  void removeObjCLifetime() { setObjCLifetime(OCL_None); }
293f85e193739c953358c865005855253af4f68a497John McCall  void addObjCLifetime(ObjCLifetime type) {
294f85e193739c953358c865005855253af4f68a497John McCall    assert(type);
295200fa53fd420aa8369586f569dbece04930ad6a3John McCall    assert(!hasObjCLifetime());
296200fa53fd420aa8369586f569dbece04930ad6a3John McCall    Mask |= (type << LifetimeShift);
297f85e193739c953358c865005855253af4f68a497John McCall  }
298f85e193739c953358c865005855253af4f68a497John McCall
299f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is neither None or ExplicitNone.
300f85e193739c953358c865005855253af4f68a497John McCall  bool hasNonTrivialObjCLifetime() const {
301f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
302f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime > OCL_ExplicitNone);
303f85e193739c953358c865005855253af4f68a497John McCall  }
304ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
305f85e193739c953358c865005855253af4f68a497John McCall  /// True if the lifetime is either strong or weak.
306f85e193739c953358c865005855253af4f68a497John McCall  bool hasStrongOrWeakObjCLifetime() const {
307f85e193739c953358c865005855253af4f68a497John McCall    ObjCLifetime lifetime = getObjCLifetime();
308f85e193739c953358c865005855253af4f68a497John McCall    return (lifetime == OCL_Strong || lifetime == OCL_Weak);
309f85e193739c953358c865005855253af4f68a497John McCall  }
310b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
311ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
312ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
313ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setAddressSpace(unsigned space) {
314ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(space <= MaxAddressSpace);
315ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~AddressSpaceMask)
316ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao         | (((uint32_t) space) << AddressSpaceShift);
317ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
318ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeAddressSpace() { setAddressSpace(0); }
319ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addAddressSpace(unsigned space) {
320ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(space);
321ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    setAddressSpace(space);
322ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
323ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
324ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Fast qualifiers are those that can be allocated directly
325ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // on a QualType object.
326ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasFastQualifiers() const { return getFastQualifiers(); }
327ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getFastQualifiers() const { return Mask & FastMask; }
328ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setFastQualifiers(unsigned mask) {
329ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
330ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask = (Mask & ~FastMask) | mask;
331ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
332ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeFastQualifiers(unsigned mask) {
333ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
334ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask &= ~mask;
335ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
336ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void removeFastQualifiers() {
337ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    removeFastQualifiers(FastMask);
338ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
339ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addFastQualifiers(unsigned mask) {
340ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
341ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Mask |= mask;
342ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
343ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
344ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// hasNonFastQualifiers - Return true if the set contains any
345ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// qualifiers which require an ExtQuals node to be allocated.
346ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
347ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  Qualifiers getNonFastQualifiers() const {
348ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Qualifiers Quals = *this;
349ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Quals.setFastQualifiers(0);
350ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Quals;
351ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
352ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
353ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// hasQualifiers - Return true if the set contains any qualifiers.
354ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasQualifiers() const { return Mask; }
355ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool empty() const { return !Mask; }
356ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
357ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Add the qualifiers from the given set to this set.
358ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addQualifiers(Qualifiers Q) {
359ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    // If the other set doesn't have any non-boolean qualifiers, just
360ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    // bit-or it in.
361ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    if (!(Q.Mask & ~CVRMask))
362ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao      Mask |= Q.Mask;
363ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    else {
364ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao      Mask |= (Q.Mask & CVRMask);
365ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao      if (Q.hasAddressSpace())
366ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao        addAddressSpace(Q.getAddressSpace());
367ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao      if (Q.hasObjCGCAttr())
368ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao        addObjCGCAttr(Q.getObjCGCAttr());
369f85e193739c953358c865005855253af4f68a497John McCall      if (Q.hasObjCLifetime())
370f85e193739c953358c865005855253af4f68a497John McCall        addObjCLifetime(Q.getObjCLifetime());
371ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    }
372ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
373ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
374e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  /// \brief Remove the qualifiers from the given set from this set.
375e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  void removeQualifiers(Qualifiers Q) {
376e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    // If the other set doesn't have any non-boolean qualifiers, just
377e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    // bit-and the inverse in.
378e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    if (!(Q.Mask & ~CVRMask))
379e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Mask &= ~Q.Mask;
380e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    else {
381e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      Mask &= ~(Q.Mask & CVRMask);
382e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      if (getObjCGCAttr() == Q.getObjCGCAttr())
383e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu        removeObjCGCAttr();
384e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      if (getObjCLifetime() == Q.getObjCLifetime())
385e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu        removeObjCLifetime();
386e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu      if (getAddressSpace() == Q.getAddressSpace())
387e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu        removeAddressSpace();
388e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    }
389e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu  }
390e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu
39162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Add the qualifiers from the given set to this set, given that
39262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// they don't conflict.
39362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  void addConsistentQualifiers(Qualifiers qs) {
39462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getAddressSpace() == qs.getAddressSpace() ||
39562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasAddressSpace() || !qs.hasAddressSpace());
39662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
39762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall           !hasObjCGCAttr() || !qs.hasObjCGCAttr());
398f85e193739c953358c865005855253af4f68a497John McCall    assert(getObjCLifetime() == qs.getObjCLifetime() ||
399f85e193739c953358c865005855253af4f68a497John McCall           !hasObjCLifetime() || !qs.hasObjCLifetime());
40062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall    Mask |= qs.Mask;
40162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
40262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
40362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Determines if these qualifiers compatibly include another set.
40462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Generally this answers the question of whether an object with the other
40562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers can be safely used as an object with these qualifiers.
40662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  bool compatiblyIncludes(Qualifiers other) const {
407b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie    return
408377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // Address spaces must match exactly.
409377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      getAddressSpace() == other.getAddressSpace() &&
410377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // ObjC GC qualifiers can match, be added, or be removed, but can't be
411377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // changed.
412377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (getObjCGCAttr() == other.getObjCGCAttr() ||
413377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor       !hasObjCGCAttr() || !other.hasObjCGCAttr()) &&
414f85e193739c953358c865005855253af4f68a497John McCall      // ObjC lifetime qualifiers must match exactly.
415f85e193739c953358c865005855253af4f68a497John McCall      getObjCLifetime() == other.getObjCLifetime() &&
416377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      // CVR qualifiers may subset.
417377e1bd6853118c5b1718503569e5179c40f09b7Douglas Gregor      (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
41862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  }
41962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
420f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determines if these qualifiers compatibly include another set of
421f85e193739c953358c865005855253af4f68a497John McCall  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
422f85e193739c953358c865005855253af4f68a497John McCall  ///
423f85e193739c953358c865005855253af4f68a497John McCall  /// One set of Objective-C lifetime qualifiers compatibly includes the other
424b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// if the lifetime qualifiers match, or if both are non-__weak and the
425f85e193739c953358c865005855253af4f68a497John McCall  /// including set also contains the 'const' qualifier.
426f85e193739c953358c865005855253af4f68a497John McCall  bool compatiblyIncludesObjCLifetime(Qualifiers other) const {
427f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == other.getObjCLifetime())
428f85e193739c953358c865005855253af4f68a497John McCall      return true;
429b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
430f85e193739c953358c865005855253af4f68a497John McCall    if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
431f85e193739c953358c865005855253af4f68a497John McCall      return false;
432b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
433f85e193739c953358c865005855253af4f68a497John McCall    return hasConst();
434f85e193739c953358c865005855253af4f68a497John McCall  }
435b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
436769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// \brief Determine whether this set of qualifiers is a strict superset of
437769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  /// another set of qualifiers, not considering qualifier compatibility.
438769d0cc72b1831785596d0e76f327bdb887823beDouglas Gregor  bool isStrictSupersetOf(Qualifiers Other) const;
439b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
440ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
441ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
442ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
4437247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie  LLVM_EXPLICIT operator bool() const { return hasQualifiers(); }
444ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
445ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  Qualifiers &operator+=(Qualifiers R) {
446ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    addQualifiers(R);
447ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return *this;
448ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
449ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
450ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Union two qualifier sets.  If an enumerated qualifier appears
451ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // in both sets, use the one from the right.
452ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  friend Qualifiers operator+(Qualifiers L, Qualifiers R) {
453ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    L += R;
454ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return L;
455ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
456b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
4576b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor  Qualifiers &operator-=(Qualifiers R) {
458e6f18c3e6a28229b5871007858b8c30882494b09Richard Trieu    removeQualifiers(R);
4596b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor    return *this;
4606b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor  }
461ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
4626b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor  /// \brief Compute the difference between two qualifier sets.
4636b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor  friend Qualifiers operator-(Qualifiers L, Qualifiers R) {
4646b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor    L -= R;
4656b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor    return L;
4666b5f410f4ef7d4e2300df3cec8ef30810e10dfc7Douglas Gregor  }
467b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
468ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  std::string getAsString() const;
4697ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  std::string getAsString(const PrintingPolicy &Policy) const;
4707ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
4717ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
4727ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void print(raw_ostream &OS, const PrintingPolicy &Policy,
4737ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis             bool appendSpaceIfNonEmpty = false) const;
474ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
475ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void Profile(llvm::FoldingSetNodeID &ID) const {
476ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    ID.AddInteger(Mask);
477ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
478ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
479ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoprivate:
480ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
481f85e193739c953358c865005855253af4f68a497John McCall  // bits:     |0 1 2|3 .. 4|5  ..  7|8   ...   31|
482f85e193739c953358c865005855253af4f68a497John McCall  //           |C R V|GCAttr|Lifetime|AddressSpace|
483ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  uint32_t Mask;
484ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
485ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  static const uint32_t GCAttrMask = 0x18;
486ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  static const uint32_t GCAttrShift = 3;
487f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeMask = 0xE0;
488f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t LifetimeShift = 5;
489f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
490f85e193739c953358c865005855253af4f68a497John McCall  static const uint32_t AddressSpaceShift = 8;
491ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao};
492ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
493200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// A std::pair-like structure for storing a qualified type split
494200fa53fd420aa8369586f569dbece04930ad6a3John McCall/// into its local qualifiers and its locally-unqualified type.
495200fa53fd420aa8369586f569dbece04930ad6a3John McCallstruct SplitQualType {
496200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// The locally-unqualified type.
497200fa53fd420aa8369586f569dbece04930ad6a3John McCall  const Type *Ty;
498200fa53fd420aa8369586f569dbece04930ad6a3John McCall
499200fa53fd420aa8369586f569dbece04930ad6a3John McCall  /// The local qualifiers.
500200fa53fd420aa8369586f569dbece04930ad6a3John McCall  Qualifiers Quals;
501200fa53fd420aa8369586f569dbece04930ad6a3John McCall
5026bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  SplitQualType() : Ty(nullptr), Quals() {}
503200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
504200fa53fd420aa8369586f569dbece04930ad6a3John McCall
505200fa53fd420aa8369586f569dbece04930ad6a3John McCall  SplitQualType getSingleStepDesugaredType() const; // end of this file
506200fa53fd420aa8369586f569dbece04930ad6a3John McCall
507651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  // Make std::tie work.
508651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::pair<const Type *,Qualifiers> asPair() const {
509651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    return std::pair<const Type *, Qualifiers>(Ty, Quals);
510200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
511200fa53fd420aa8369586f569dbece04930ad6a3John McCall
512200fa53fd420aa8369586f569dbece04930ad6a3John McCall  friend bool operator==(SplitQualType a, SplitQualType b) {
513200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return a.Ty == b.Ty && a.Quals == b.Quals;
514200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
515200fa53fd420aa8369586f569dbece04930ad6a3John McCall  friend bool operator!=(SplitQualType a, SplitQualType b) {
516200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return a.Ty != b.Ty || a.Quals != b.Quals;
517200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
518200fa53fd420aa8369586f569dbece04930ad6a3John McCall};
519ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
520ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// QualType - For efficiency, we don't store CV-qualified types as nodes on
521ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// their own: instead each reference to a type stores the qualifiers.  This
522ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// greatly reduces the number of nodes we need to allocate for types (for
523ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// example we only need one for 'int', 'const int', 'volatile int',
524ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// 'const volatile int', etc).
525ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao///
526ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// As an added efficiency bonus, instead of making this a pair, we
527ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// just store the two bits we care about in the low bits of the
528ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// pointer.  To handle the packing/unpacking, we make QualType be a
529ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// simple wrapper class that acts like a smart pointer.  A third bit
530ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// indicates whether there are extended qualifiers present, in which
531ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao/// case the pointer points to a special structure.
532ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaoclass QualType {
533ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Thankfully, these are efficiently composable.
534ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  llvm::PointerIntPair<llvm::PointerUnion<const Type*,const ExtQuals*>,
535ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao                       Qualifiers::FastWidth> Value;
536ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
537ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  const ExtQuals *getExtQualsUnsafe() const {
538ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Value.getPointer().get<const ExtQuals*>();
539ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
540ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
541ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  const Type *getTypePtrUnsafe() const {
542ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Value.getPointer().get<const Type*>();
543ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
544ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
5453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const ExtQualsTypeCommonBase *getCommonPtr() const {
5463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    assert(!isNull() && "Cannot retrieve a NULL type pointer");
5473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    uintptr_t CommonPtrVal
5483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall      = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
5493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
5503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall    return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
5513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  }
5523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
553ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  friend class QualifierCollector;
554ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liaopublic:
555ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType() {}
556ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
557ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType(const Type *Ptr, unsigned Quals)
558ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    : Value(Ptr, Quals) {}
559ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType(const ExtQuals *Ptr, unsigned Quals)
560ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    : Value(Ptr, Quals) {}
561ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
562ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
563ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
564ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
565ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// Retrieves a pointer to the underlying (unqualified) type.
5661ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  ///
5671ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// This function requires that the type not be NULL. If the type might be
5681ab55e9bb87d98bff1d42c7a0ee502c64755d9f5Douglas Gregor  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
5693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtr() const;
570b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
5713b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  const Type *getTypePtrOrNull() const;
5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5734d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain  /// Retrieves a pointer to the name of the base type.
5744d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain  const IdentifierInfo *getBaseTypeIdentifier() const;
5754d9d157afb35742bc6348defbe45bc6de780ec77Kaelyn Uhrain
57649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// Divides a QualType into its unqualified type and a set of local
57749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  /// qualifiers.
5783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  SplitQualType split() const;
579ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
580ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
581f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  static QualType getFromOpaquePtr(const void *Ptr) {
582ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    QualType T;
583f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall    T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
584ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return T;
585ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
586ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
587f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type &operator*() const {
588ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return *getTypePtr();
589ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
590ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
591f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall  const Type *operator->() const {
592ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return getTypePtr();
593ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
594ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
595ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isCanonical() const;
596ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isCanonicalAsParam() const;
597ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
598ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// isNull - Return true if this QualType doesn't point to a type yet.
599ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isNull() const {
600ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Value.getPointer().isNull();
601ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
602ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
603b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// \brief Determine whether this particular QualType instance has the
604ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// "const" qualifier set, without looking through typedefs that may have
605ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// added "const" at a different level.
606ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isLocalConstQualified() const {
607ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return (getLocalFastQualifiers() & Qualifiers::Const);
608ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
609b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
610ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Determine whether this type is const-qualified.
611ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isConstQualified() const;
612b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
613b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// \brief Determine whether this particular QualType instance has the
614ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// "restrict" qualifier set, without looking through typedefs that may have
615ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// added "restrict" at a different level.
616ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isLocalRestrictQualified() const {
617ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return (getLocalFastQualifiers() & Qualifiers::Restrict);
618ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
619b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
620ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Determine whether this type is restrict-qualified.
621ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isRestrictQualified() const;
622b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
623b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// \brief Determine whether this particular QualType instance has the
624ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// "volatile" qualifier set, without looking through typedefs that may have
625ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// added "volatile" at a different level.
626ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isLocalVolatileQualified() const {
627f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return (getLocalFastQualifiers() & Qualifiers::Volatile);
628ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
629ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
630ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Determine whether this type is volatile-qualified.
631ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isVolatileQualified() const;
632b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
633ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Determine whether this particular QualType instance has any
634b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// qualifiers, without looking through any typedefs that might add
635ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// qualifiers at a different level.
636ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasLocalQualifiers() const {
637ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return getLocalFastQualifiers() || hasLocalNonFastQualifiers();
638ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
639ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
640ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Determine whether this type has any qualifiers.
641ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasQualifiers() const;
642b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
643ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Determine whether this particular QualType instance has any
644ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
645ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// instance.
646ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool hasLocalNonFastQualifiers() const {
647ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return Value.getPointer().is<const ExtQuals*>();
648ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
649ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
650ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Retrieve the set of qualifiers local to this particular QualType
651ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// instance, not including any qualifiers acquired through typedefs or
652ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// other sugar.
6533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  Qualifiers getLocalQualifiers() const;
654ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
655ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Retrieve the set of qualifiers applied to this type.
656ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  Qualifiers getQualifiers() const;
657b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
658b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
659ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// local to this particular QualType instance, not including any qualifiers
660ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// acquired through typedefs or other sugar.
661ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getLocalCVRQualifiers() const {
662f7616b9067790757f4e12e834b216c53c8c04ebeDouglas Gregor    return getLocalFastQualifiers();
663ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
664ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
665b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// \brief Retrieve the set of CVR (const-volatile-restrict) qualifiers
666ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// applied to this type.
667ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  unsigned getCVRQualifiers() const;
668ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
669ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isConstant(ASTContext& Ctx) const {
670ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return QualType::isConstant(*this, Ctx);
671ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
672ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
673f85e193739c953358c865005855253af4f68a497John McCall  /// \brief Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
674f85e193739c953358c865005855253af4f68a497John McCall  bool isPODType(ASTContext &Context) const;
675f85e193739c953358c865005855253af4f68a497John McCall
676152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// isCXX98PODType() - Return true if this is a POD type according to the
677152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// rules of the C++98 standard, regardless of the current compilation's
678152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  /// language.
679152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer  bool isCXX98PODType(ASTContext &Context) const;
680152f6b7be508fbc61543f3736ebd390d7ac84bd1Benjamin Kramer
681f85e193739c953358c865005855253af4f68a497John McCall  /// isCXX11PODType() - Return true if this is a POD type according to the
682f85e193739c953358c865005855253af4f68a497John McCall  /// more relaxed rules of the C++11 standard, regardless of the current
683f85e193739c953358c865005855253af4f68a497John McCall  /// compilation's language.
684f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
685f85e193739c953358c865005855253af4f68a497John McCall  bool isCXX11PODType(ASTContext &Context) const;
686b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
687f85e193739c953358c865005855253af4f68a497John McCall  /// isTrivialType - Return true if this is a trivial type
688f85e193739c953358c865005855253af4f68a497John McCall  /// (C++0x [basic.types]p9)
689b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  bool isTrivialType(ASTContext &Context) const;
690f85e193739c953358c865005855253af4f68a497John McCall
691f85e193739c953358c865005855253af4f68a497John McCall  /// isTriviallyCopyableType - Return true if this is a trivially
692f85e193739c953358c865005855253af4f68a497John McCall  /// copyable type (C++0x [basic.types]p9)
693f85e193739c953358c865005855253af4f68a497John McCall  bool isTriviallyCopyableType(ASTContext &Context) const;
694f85e193739c953358c865005855253af4f68a497John McCall
695ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Don't promise in the API that anything besides 'const' can be
696ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // easily added.
697ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
698b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// addConst - add the specified type qualifier to this QualType.
699ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addConst() {
700ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    addFastQualifiers(Qualifiers::Const);
701ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
702ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType withConst() const {
703ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return withFastQualifiers(Qualifiers::Const);
704ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
705ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
706b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// addVolatile - add the specified type qualifier to this QualType.
707308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  void addVolatile() {
708308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    addFastQualifiers(Qualifiers::Volatile);
709308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
710308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  QualType withVolatile() const {
711308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt    return withFastQualifiers(Qualifiers::Volatile);
712308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt  }
71318932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek
71418932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  /// Add the restrict qualifier to this QualType.
71518932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  void addRestrict() {
71618932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek    addFastQualifiers(Qualifiers::Restrict);
71718932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  }
71818932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  QualType withRestrict() const {
71918932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek    return withFastQualifiers(Qualifiers::Restrict);
72018932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek  }
721308742c87e2311c3f349092e5b823c3821e61b10Sean Hunt
722a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  QualType withCVRQualifiers(unsigned CVR) const {
723a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall    return withFastQualifiers(CVR);
724a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  }
725a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall
726ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  void addFastQualifiers(unsigned TQs) {
727ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(TQs & ~Qualifiers::FastMask)
728ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao           && "non-fast qualifier bits set in mask!");
729ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Value.setInt(Value.getInt() | TQs);
730ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
731ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
73249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalConst();
73349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalVolatile();
73449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalRestrict();
73549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalCVRQualifiers(unsigned Mask);
736ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
73749f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers() { Value.setInt(0); }
73849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  void removeLocalFastQualifiers(unsigned Mask) {
739ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
740ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    Value.setInt(Value.getInt() & ~Mask);
741ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
742ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
743ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Creates a type with the given qualifiers in addition to any
744ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // qualifiers already on this type.
745ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType withFastQualifiers(unsigned TQs) const {
746ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    QualType T = *this;
747ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    T.addFastQualifiers(TQs);
748ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return T;
749ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
750ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
751ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Creates a type with exactly the given fast qualifiers, removing
752ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // any existing fast qualifiers.
75349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withExactLocalFastQualifiers(unsigned TQs) const {
75449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return withoutLocalFastQualifiers().withFastQualifiers(TQs);
755ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
756ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
757ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  // Removes fast qualifiers, but leaves any extended qualifiers in place.
75849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  QualType withoutLocalFastQualifiers() const {
759ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    QualType T = *this;
76049f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    T.removeLocalFastQualifiers();
761ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return T;
762ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
763ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
7643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall  QualType getCanonicalType() const;
7653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall
766ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// \brief Return this type with all of the instance-specific qualifiers
767ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// removed, but without removing any qualifiers that may have been applied
768ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// through typedefs.
769ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); }
770ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
77162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \brief Retrieve the unqualified variant of the given type,
77262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// removing as little sugar as possible.
77362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
77462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// This routine looks through various kinds of sugar to find the
77562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// least-desugared type that is unqualified. For example, given:
77662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
77762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \code
77862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef int Integer;
77962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef const Integer CInteger;
78062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// typedef CInteger DifferenceType;
78162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// \endcode
78262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
78362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
78462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
78562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
786903ef044e5fe8efe5d06f63945f903ae81a262fdRichard Smith  /// The resulting type might still be qualified if it's sugar for an array
787903ef044e5fe8efe5d06f63945f903ae81a262fdRichard Smith  /// type.  To strip qualifiers even from within a sugared array type, use
78862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
78962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline QualType getUnqualifiedType() const;
79062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall
79162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// getSplitUnqualifiedType - Retrieve the unqualified variant of the
79262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// given type, removing as little sugar as possible.
79362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
79462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// Like getUnqualifiedType(), but also returns the set of
79562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// qualifiers that were built up.
79662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  ///
797903ef044e5fe8efe5d06f63945f903ae81a262fdRichard Smith  /// The resulting type might still be qualified if it's sugar for an array
798903ef044e5fe8efe5d06f63945f903ae81a262fdRichard Smith  /// type.  To strip qualifiers even from within a sugared array type, use
79962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  /// ASTContext::getUnqualifiedArrayType.
80062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall  inline SplitQualType getSplitUnqualifiedType() const;
801b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
80261d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is more qualified than the other
80361d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
804ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isMoreQualifiedThan(QualType Other) const;
80561d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor
80661d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// \brief Determine whether this type is at least as qualified as the other
80761d0b6baf47cf411f6c0f6ddb4acffcfeec724f1Douglas Gregor  /// given type, requiring exact equality for non-CVR qualifiers.
808ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  bool isAtLeastAsQualifiedAs(QualType Other) const;
809b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
810ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  QualType getNonReferenceType() const;
811ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
8122350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor  /// \brief Determine the type of a (typically non-lvalue) expression with the
8132350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor  /// specified result type.
814b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  ///
8152350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor  /// This routine should be used for expressions for which the return type is
8162350fb26d59692c6006ec5d33b8215e96055bdb6Douglas Gregor  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
817b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// an lvalue. It removes a top-level reference (since there are no
8188079eee9128444d02bebf24410126f9d55399f84Douglas Gregor  /// expressions of reference type) and deletes top-level cvr-qualifiers
8198079eee9128444d02bebf24410126f9d55399f84Douglas Gregor  /// from non-class types (in C++) or all types (in C).
82032b5a1e82f535d43e94332183cd330f4a39b2dbdCraig Topper  QualType getNonLValueExprType(const ASTContext &Context) const;
821b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
822ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// getDesugaredType - Return the specified type with any "sugar" removed from
823ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
824ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// the type is already concrete, it returns it unmodified.  This is similar
825ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
826ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
827ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// concrete.
828ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  ///
829ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// Qualifiers are left in place.
8304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad  QualType getDesugaredType(const ASTContext &Context) const {
83149f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getDesugaredType(*this, Context);
83249f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
83349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall
83449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  SplitQualType getSplitDesugaredType() const {
83549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getSplitDesugaredType(*this);
836bf1cc05907ceb2081e8158b26f3d3f48b31caad3John McCall  }
83798cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor
838f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// \brief Return the specified type with one level of "sugar" removed from
839b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie  /// the type.
840f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  ///
841f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// This routine takes off the first typedef, typeof, etc. If the outer level
842f1588660c109610e6a79c786b83b7c9bbd6ed31eDouglas Gregor  /// of the type is already concrete, it returns it unmodified.
843200fa53fd420aa8369586f569dbece04930ad6a3John McCall  QualType getSingleStepDesugaredType(const ASTContext &Context) const {
844200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getSingleStepDesugaredTypeImpl(*this, Context);
845200fa53fd420aa8369586f569dbece04930ad6a3John McCall  }
846b5adc4636f653b37891792d2a279e889dab0935fDavid Blaikie
847075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// IgnoreParens - Returns the specified type after dropping any
848075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  /// outer-level parentheses.
849075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara  QualType IgnoreParens() const {
850723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    if (isa<ParenType>(*this))
851723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara      return QualType::IgnoreParens(*this);
852723df245307a530da5433dfb43accf187dc3e243Abramo Bagnara    return *this;
853ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
854ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
855ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// operator==/!= - Indicate whether the specified types and qualifiers are
856ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  /// identical.
857ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  friend bool operator==(const QualType &LHS, const QualType &RHS) {
858ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return LHS.Value == RHS.Value;
859ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
860ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
861ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao    return LHS.Value != RHS.Value;
862ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao  }
86349f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  std::string getAsString() const {
86449f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall    return getAsString(split());
86549f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
86649f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(SplitQualType split) {
867200fa53fd420aa8369586f569dbece04930ad6a3John McCall    return getAsString(split.Ty, split.Quals);
86849f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  }
86949f4e1cbd839da27ff4814b4ea6d85a79f786cbdJohn McCall  static std::string getAsString(const Type *ty, Qualifiers qs);
870ea285162342df160e7860e26528bc7110bc6c0cdShih-wei Liao
8717ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  std::string getAsString(const PrintingPolicy &Policy) const;
8727ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis
8737ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis  void print(raw_ostream &OS, const PrintingPolicy &Policy,
8747ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis             const Twine &PlaceHolder = Twine()) const {
8757ad5c996e9519ed4e9afd1f0166be1cd2be8415aArgyrios Kyrtzidis    print(split(), OS, Policy, PlaceHolder);
876