Type.h revision cfe6ae592450d8466b4d78b59ff4526266549a9a
1//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the Type interface and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_TYPE_H
15#define LLVM_CLANG_AST_TYPE_H
16
17#include "clang/Basic/Diagnostic.h"
18#include "clang/Basic/IdentifierTable.h"
19#include "clang/AST/NestedNameSpecifier.h"
20#include "clang/AST/TemplateName.h"
21#include "llvm/Support/Casting.h"
22#include "llvm/Support/type_traits.h"
23#include "llvm/ADT/APSInt.h"
24#include "llvm/ADT/FoldingSet.h"
25#include "llvm/ADT/PointerIntPair.h"
26#include "llvm/ADT/PointerUnion.h"
27
28using llvm::isa;
29using llvm::cast;
30using llvm::cast_or_null;
31using llvm::dyn_cast;
32using llvm::dyn_cast_or_null;
33namespace clang { class Type; }
34
35namespace llvm {
36  template <typename T>
37  class PointerLikeTypeTraits;
38  template<>
39  class PointerLikeTypeTraits< ::clang::Type*> {
40  public:
41    static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
42    static inline ::clang::Type *getFromVoidPointer(void *P) {
43      return static_cast< ::clang::Type*>(P);
44    }
45    enum { NumLowBitsAvailable = 3 };
46  };
47}
48
49namespace clang {
50  class ASTContext;
51  class TypedefDecl;
52  class TemplateDecl;
53  class TemplateTypeParmDecl;
54  class NonTypeTemplateParmDecl;
55  class TemplateTemplateParmDecl;
56  class TagDecl;
57  class RecordDecl;
58  class CXXRecordDecl;
59  class EnumDecl;
60  class FieldDecl;
61  class ObjCInterfaceDecl;
62  class ObjCProtocolDecl;
63  class ObjCMethodDecl;
64  class Expr;
65  class Stmt;
66  class SourceLocation;
67  class StmtIteratorBase;
68  class TemplateArgument;
69  class QualifiedNameType;
70  struct PrintingPolicy;
71
72  // Provide forward declarations for all of the *Type classes
73#define TYPE(Class, Base) class Class##Type;
74#include "clang/AST/TypeNodes.def"
75
76/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
77/// their own: instead each reference to a type stores the qualifiers.  This
78/// greatly reduces the number of nodes we need to allocate for types (for
79/// example we only need one for 'int', 'const int', 'volatile int',
80/// 'const volatile int', etc).
81///
82/// As an added efficiency bonus, instead of making this a pair, we just store
83/// the three bits we care about in the low bits of the pointer.  To handle the
84/// packing/unpacking, we make QualType be a simple wrapper class that acts like
85/// a smart pointer.
86class QualType {
87  llvm::PointerIntPair<Type*, 3> Value;
88public:
89  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
90    Const    = 0x1,
91    Restrict = 0x2,
92    Volatile = 0x4,
93    CVRFlags = Const|Restrict|Volatile
94  };
95
96  enum GCAttrTypes {
97    GCNone = 0,
98    Weak,
99    Strong
100  };
101
102  // 24 bits should be enough for anyone.
103  static const unsigned MaxAddressSpace = 0xffffffu;
104
105  QualType() {}
106
107  QualType(const Type *Ptr, unsigned Quals)
108    : Value(const_cast<Type*>(Ptr), Quals) {}
109
110  unsigned getCVRQualifiers() const { return Value.getInt(); }
111  void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); }
112  Type *getTypePtr() const { return Value.getPointer(); }
113
114  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
115  static QualType getFromOpaquePtr(void *Ptr) {
116    QualType T;
117    T.Value.setFromOpaqueValue(Ptr);
118    return T;
119  }
120
121  Type &operator*() const {
122    return *getTypePtr();
123  }
124
125  Type *operator->() const {
126    return getTypePtr();
127  }
128
129  /// isNull - Return true if this QualType doesn't point to a type yet.
130  bool isNull() const {
131    return getTypePtr() == 0;
132  }
133
134  bool isConstQualified() const {
135    return (getCVRQualifiers() & Const) ? true : false;
136  }
137  bool isVolatileQualified() const {
138    return (getCVRQualifiers() & Volatile) ? true : false;
139  }
140  bool isRestrictQualified() const {
141    return (getCVRQualifiers() & Restrict) ? true : false;
142  }
143
144  bool isConstant(ASTContext& Ctx) const;
145
146  /// addConst/addVolatile/addRestrict - add the specified type qual to this
147  /// QualType.
148  void addConst()    { Value.setInt(Value.getInt() | Const); }
149  void addVolatile() { Value.setInt(Value.getInt() | Volatile); }
150  void addRestrict() { Value.setInt(Value.getInt() | Restrict); }
151
152  void removeConst()    { Value.setInt(Value.getInt() & ~Const); }
153  void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); }
154  void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); }
155
156  QualType getQualifiedType(unsigned TQs) const {
157    return QualType(getTypePtr(), TQs);
158  }
159  QualType getWithAdditionalQualifiers(unsigned TQs) const {
160    return QualType(getTypePtr(), TQs|getCVRQualifiers());
161  }
162
163  QualType withConst() const { return getWithAdditionalQualifiers(Const); }
164  QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);}
165  QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);}
166
167  QualType getUnqualifiedType() const;
168  bool isMoreQualifiedThan(QualType Other) const;
169  bool isAtLeastAsQualifiedAs(QualType Other) const;
170  QualType getNonReferenceType() const;
171
172  /// getDesugaredType - Return the specified type with any "sugar" removed from
173  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
174  /// the type is already concrete, it returns it unmodified.  This is similar
175  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
176  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
177  /// concrete.
178  QualType getDesugaredType(bool ForDisplay = false) const;
179
180  /// operator==/!= - Indicate whether the specified types and qualifiers are
181  /// identical.
182  friend bool operator==(const QualType &LHS, const QualType &RHS) {
183    return LHS.Value == RHS.Value;
184  }
185  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
186    return LHS.Value != RHS.Value;
187  }
188  std::string getAsString() const;
189
190  std::string getAsString(const PrintingPolicy &Policy) const {
191    std::string S;
192    getAsStringInternal(S, Policy);
193    return S;
194  }
195  void getAsStringInternal(std::string &Str,
196                           const PrintingPolicy &Policy) const;
197
198  void dump(const char *s) const;
199  void dump() const;
200
201  void Profile(llvm::FoldingSetNodeID &ID) const {
202    ID.AddPointer(getAsOpaquePtr());
203  }
204
205public:
206
207  /// getAddressSpace - Return the address space of this type.
208  inline unsigned getAddressSpace() const;
209
210  /// GCAttrTypesAttr - Returns gc attribute of this type.
211  inline QualType::GCAttrTypes getObjCGCAttr() const;
212
213  /// isObjCGCWeak true when Type is objc's weak.
214  bool isObjCGCWeak() const {
215    return getObjCGCAttr() == Weak;
216  }
217
218  /// isObjCGCStrong true when Type is objc's strong.
219  bool isObjCGCStrong() const {
220    return getObjCGCAttr() == Strong;
221  }
222
223  /// getNoReturnAttr - Returns true if the type has the noreturn attribute,
224  /// false otherwise.
225  bool getNoReturnAttr() const;
226};
227
228} // end clang.
229
230namespace llvm {
231/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
232/// to a specific Type class.
233template<> struct simplify_type<const ::clang::QualType> {
234  typedef ::clang::Type* SimpleType;
235  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
236    return Val.getTypePtr();
237  }
238};
239template<> struct simplify_type< ::clang::QualType>
240  : public simplify_type<const ::clang::QualType> {};
241
242// Teach SmallPtrSet that QualType is "basically a pointer".
243template<>
244class PointerLikeTypeTraits<clang::QualType> {
245public:
246  static inline void *getAsVoidPointer(clang::QualType P) {
247    return P.getAsOpaquePtr();
248  }
249  static inline clang::QualType getFromVoidPointer(void *P) {
250    return clang::QualType::getFromOpaquePtr(P);
251  }
252  // CVR qualifiers go in low bits.
253  enum { NumLowBitsAvailable = 0 };
254};
255
256} // end namespace llvm
257
258namespace clang {
259
260/// Type - This is the base class of the type hierarchy.  A central concept
261/// with types is that each type always has a canonical type.  A canonical type
262/// is the type with any typedef names stripped out of it or the types it
263/// references.  For example, consider:
264///
265///  typedef int  foo;
266///  typedef foo* bar;
267///    'int *'    'foo *'    'bar'
268///
269/// There will be a Type object created for 'int'.  Since int is canonical, its
270/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
271/// TypedefType).  Its CanonicalType pointer points to the 'int' Type.  Next
272/// there is a PointerType that represents 'int*', which, like 'int', is
273/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
274/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
275/// is also 'int*'.
276///
277/// Non-canonical types are useful for emitting diagnostics, without losing
278/// information about typedefs being used.  Canonical types are useful for type
279/// comparisons (they allow by-pointer equality tests) and useful for reasoning
280/// about whether something has a particular form (e.g. is a function type),
281/// because they implicitly, recursively, strip all typedefs out of a type.
282///
283/// Types, once created, are immutable.
284///
285class Type {
286public:
287  enum TypeClass {
288#define TYPE(Class, Base) Class,
289#define ABSTRACT_TYPE(Class, Base)
290#include "clang/AST/TypeNodes.def"
291    TagFirst = Record, TagLast = Enum
292  };
293
294private:
295  QualType CanonicalType;
296
297  /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
298  bool Dependent : 1;
299
300  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
301  /// Note that this should stay at the end of the ivars for Type so that
302  /// subclasses can pack their bitfields into the same word.
303  unsigned TC : 6;
304
305  Type(const Type&);           // DO NOT IMPLEMENT.
306  void operator=(const Type&); // DO NOT IMPLEMENT.
307protected:
308  // silence VC++ warning C4355: 'this' : used in base member initializer list
309  Type *this_() { return this; }
310  Type(TypeClass tc, QualType Canonical, bool dependent)
311    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
312      Dependent(dependent), TC(tc) {}
313  virtual ~Type() {}
314  virtual void Destroy(ASTContext& C);
315  friend class ASTContext;
316
317public:
318  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
319
320  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
321
322  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
323  /// object types, function types, and incomplete types.
324
325  /// \brief Determines whether the type describes an object in memory.
326  ///
327  /// Note that this definition of object type corresponds to the C++
328  /// definition of object type, which includes incomplete types, as
329  /// opposed to the C definition (which does not include incomplete
330  /// types).
331  bool isObjectType() const;
332
333  /// isIncompleteType - Return true if this is an incomplete type.
334  /// A type that can describe objects, but which lacks information needed to
335  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
336  /// routine will need to determine if the size is actually required.
337  bool isIncompleteType() const;
338
339  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
340  /// type, in other words, not a function type.
341  bool isIncompleteOrObjectType() const {
342    return !isFunctionType();
343  }
344
345  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
346  bool isPODType() const;
347
348  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
349  /// types that have a non-constant expression. This does not include "[]".
350  bool isVariablyModifiedType() const;
351
352  /// Helper methods to distinguish type categories. All type predicates
353  /// operate on the canonical type, ignoring typedefs and qualifiers.
354
355  /// isSpecificBuiltinType - Test for a particular builtin type.
356  bool isSpecificBuiltinType(unsigned K) const;
357
358  /// isIntegerType() does *not* include complex integers (a GCC extension).
359  /// isComplexIntegerType() can be used to test for complex integers.
360  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
361  bool isEnumeralType() const;
362  bool isBooleanType() const;
363  bool isCharType() const;
364  bool isWideCharType() const;
365  bool isIntegralType() const;
366
367  /// Floating point categories.
368  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
369  /// isComplexType() does *not* include complex integers (a GCC extension).
370  /// isComplexIntegerType() can be used to test for complex integers.
371  bool isComplexType() const;      // C99 6.2.5p11 (complex)
372  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
373  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
374  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
375  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
376  bool isVoidType() const;         // C99 6.2.5p19
377  bool isDerivedType() const;      // C99 6.2.5p20
378  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
379  bool isAggregateType() const;
380
381  // Type Predicates: Check to see if this type is structurally the specified
382  // type, ignoring typedefs and qualifiers.
383  bool isFunctionType() const;
384  bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; }
385  bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; }
386  bool isPointerType() const;
387  bool isAnyPointerType() const;   // Any C pointer or ObjC object pointer
388  bool isBlockPointerType() const;
389  bool isVoidPointerType() const;
390  bool isReferenceType() const;
391  bool isLValueReferenceType() const;
392  bool isRValueReferenceType() const;
393  bool isFunctionPointerType() const;
394  bool isMemberPointerType() const;
395  bool isMemberFunctionPointerType() const;
396  bool isArrayType() const;
397  bool isConstantArrayType() const;
398  bool isIncompleteArrayType() const;
399  bool isVariableArrayType() const;
400  bool isDependentSizedArrayType() const;
401  bool isRecordType() const;
402  bool isClassType() const;
403  bool isStructureType() const;
404  bool isUnionType() const;
405  bool isComplexIntegerType() const;            // GCC _Complex integer type.
406  bool isVectorType() const;                    // GCC vector type.
407  bool isExtVectorType() const;                 // Extended vector type.
408  bool isObjCObjectPointerType() const;         // Pointer to *any* ObjC object.
409  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
410  // for the common case.
411  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
412  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
413  bool isObjCQualifiedIdType() const;           // id<foo>
414  bool isObjCQualifiedClassType() const;        // Class<foo>
415  bool isObjCIdType() const;                    // id
416  bool isObjCClassType() const;                 // Class
417  bool isObjCBuiltinType() const;               // 'id' or 'Class'
418  bool isTemplateTypeParmType() const;          // C++ template type parameter
419  bool isNullPtrType() const;                   // C++0x nullptr_t
420
421  /// isDependentType - Whether this type is a dependent type, meaning
422  /// that its definition somehow depends on a template parameter
423  /// (C++ [temp.dep.type]).
424  bool isDependentType() const { return Dependent; }
425  bool isOverloadableType() const;
426
427  /// hasPointerRepresentation - Whether this type is represented
428  /// natively as a pointer; this includes pointers, references, block
429  /// pointers, and Objective-C interface, qualified id, and qualified
430  /// interface types, as well as nullptr_t.
431  bool hasPointerRepresentation() const;
432
433  /// hasObjCPointerRepresentation - Whether this type can represent
434  /// an objective pointer type for the purpose of GC'ability
435  bool hasObjCPointerRepresentation() const;
436
437  // Type Checking Functions: Check to see if this type is structurally the
438  // specified type, ignoring typedefs and qualifiers, and return a pointer to
439  // the best type we can.
440  const BuiltinType *getAsBuiltinType() const;
441  const FunctionType *getAsFunctionType() const;
442  const FunctionNoProtoType *getAsFunctionNoProtoType() const;
443  const FunctionProtoType *getAsFunctionProtoType() const;
444  const RecordType *getAsStructureType() const;
445  /// NOTE: getAs*ArrayType are methods on ASTContext.
446  const TypedefType *getAsTypedefType() const;
447  const RecordType *getAsUnionType() const;
448  const EnumType *getAsEnumType() const;
449  const VectorType *getAsVectorType() const; // GCC vector type.
450  const ComplexType *getAsComplexType() const;
451  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
452  const ExtVectorType *getAsExtVectorType() const; // Extended vector type.
453  const ObjCObjectPointerType *getAsObjCObjectPointerType() const;
454  // The following is a convenience method that returns an ObjCObjectPointerType
455  // for object declared using an interface.
456  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
457  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
458  const ObjCInterfaceType *getAsObjCInterfaceType() const;
459  const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const;
460  const TemplateTypeParmType *getAsTemplateTypeParmType() const;
461  const CXXRecordDecl *getCXXRecordDeclForPointerType() const;
462
463  // Member-template getAs<specific type>'.  This scheme will eventually
464  // replace the specific getAsXXXX methods above.
465  template <typename T> const T *getAs() const;
466
467  const TemplateSpecializationType *
468    getAsTemplateSpecializationType() const;
469
470  /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
471  /// interface, return the interface type, otherwise return null.
472  const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
473
474  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
475  /// element type of the array, potentially with type qualifiers missing.
476  /// This method should never be used when type qualifiers are meaningful.
477  const Type *getArrayElementTypeNoTypeQual() const;
478
479  /// getPointeeType - If this is a pointer, ObjC object pointer, or block
480  /// pointer, this returns the respective pointee.
481  QualType getPointeeType() const;
482
483  /// getDesugaredType - Return the specified type with any "sugar" removed from
484  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
485  /// the type is already concrete, it returns it unmodified.  This is similar
486  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
487  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
488  /// concrete.
489  QualType getDesugaredType(bool ForDisplay = false) const;
490
491  /// More type predicates useful for type checking/promotion
492  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
493
494  /// isSignedIntegerType - Return true if this is an integer type that is
495  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
496  /// an enum decl which has a signed representation, or a vector of signed
497  /// integer element type.
498  bool isSignedIntegerType() const;
499
500  /// isUnsignedIntegerType - Return true if this is an integer type that is
501  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
502  /// decl which has an unsigned representation, or a vector of unsigned integer
503  /// element type.
504  bool isUnsignedIntegerType() const;
505
506  /// isConstantSizeType - Return true if this is not a variable sized type,
507  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
508  /// incomplete types.
509  bool isConstantSizeType() const;
510
511  /// isSpecifierType - Returns true if this type can be represented by some
512  /// set of type specifiers.
513  bool isSpecifierType() const;
514
515  QualType getCanonicalTypeInternal() const { return CanonicalType; }
516  void dump() const;
517  virtual void getAsStringInternal(std::string &InnerString,
518                                   const PrintingPolicy &Policy) const = 0;
519  static bool classof(const Type *) { return true; }
520};
521
522/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26
523/// This supports all kinds of type attributes; including,
524/// address space qualified types, objective-c's __weak and
525/// __strong attributes.
526///
527class ExtQualType : public Type, public llvm::FoldingSetNode {
528  /// BaseType - This is the underlying type that this qualifies.  All CVR
529  /// qualifiers are stored on the QualType that references this type, so we
530  /// can't have any here.
531  Type *BaseType;
532
533  /// Address Space ID - The address space ID this type is qualified with.
534  unsigned AddressSpace;
535  /// GC __weak/__strong attributes
536  QualType::GCAttrTypes GCAttrType;
537
538  ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace,
539              QualType::GCAttrTypes gcAttr) :
540      Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base),
541      AddressSpace(AddrSpace), GCAttrType(gcAttr) {
542    assert(!isa<ExtQualType>(BaseType) &&
543           "Cannot have ExtQualType of ExtQualType");
544  }
545  friend class ASTContext;  // ASTContext creates these.
546public:
547  Type *getBaseType() const { return BaseType; }
548  QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; }
549  unsigned getAddressSpace() const { return AddressSpace; }
550
551  virtual void getAsStringInternal(std::string &InnerString,
552                                   const PrintingPolicy &Policy) const;
553
554  void Profile(llvm::FoldingSetNodeID &ID) {
555    Profile(ID, getBaseType(), AddressSpace, GCAttrType);
556  }
557  static void Profile(llvm::FoldingSetNodeID &ID, Type *Base,
558                      unsigned AddrSpace, QualType::GCAttrTypes gcAttr) {
559    ID.AddPointer(Base);
560    ID.AddInteger(AddrSpace);
561    ID.AddInteger(gcAttr);
562  }
563
564  static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; }
565  static bool classof(const ExtQualType *) { return true; }
566};
567
568
569/// QualifierSet - This class is used to collect qualifiers.
570/// Clang supports five independent qualifiers:
571/// * C99: const, volatile, and restrict
572/// * Embedded C (TR18037): address spaces
573/// * Objective C: the GC attributes (none, weak, or strong)
574class QualifierSet {
575public:
576  QualifierSet() : Mask(0) {}
577
578  void removeConst() { removeCVR(QualType::Const); }
579  void removeVolatile() { removeCVR(QualType::Volatile); }
580  void removeRestrict() { removeCVR(QualType::Restrict); }
581  void removeCVR(unsigned mask) { Mask &= ~mask; }
582  void removeAddressSpace() { setAddressSpace(0); }
583  void removeObjCGCAttrType() { setGCAttrType(QualType::GCNone); }
584
585  void addConst() { addCVR(QualType::Const); }
586  void addVolatile() { addCVR(QualType::Volatile); }
587  void addRestrict() { addCVR(QualType::Restrict); }
588  void addCVR(unsigned mask) { Mask |= mask; }
589  void addAddressSpace(unsigned space) {
590    assert(space);
591    setAddressSpace(space);
592  }
593  void addObjCGCAttrType(QualType::GCAttrTypes type) {
594    assert(type);
595    setGCAttrType(type);
596  }
597
598  bool hasConst() const { return Mask & QualType::Const; }
599  bool hasVolatile() const { return Mask & QualType::Volatile; }
600  bool hasRestrict() const { return Mask & QualType::Restrict; }
601  unsigned getCVRMask() const { return Mask & CVRMask; }
602
603  bool hasObjCGCAttrType() const { return Mask & GCAttrMask; }
604  QualType::GCAttrTypes getObjCGCAttrType() const {
605    return QualType::GCAttrTypes((Mask & GCAttrMask) >> GCAttrShift);
606  }
607
608  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
609  unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }
610
611  /// empty() - Return true if there are no qualifiers collected
612  /// in this set.
613  bool empty() {
614    return (Mask == 0);
615  }
616
617  /// Collect any qualifiers on the given type and return an
618  /// unqualified type.
619  const Type *strip(QualType QT) {
620    Mask |= QT.getCVRQualifiers();
621    return strip(QT.getTypePtr());
622  }
623
624  /// Collect any qualifiers on the given type and return an
625  /// unqualified type.
626  const Type *strip(const Type* T);
627
628  /// Apply the collected qualifiers to the given type.
629  QualType apply(QualType QT, ASTContext& C);
630
631  /// Apply the collected qualifiers to the given type.
632  QualType apply(const Type* T, ASTContext& C) {
633    return apply(QualType(T, 0), C);
634  }
635
636  bool operator==(QualifierSet& Other) { return Mask == Other.Mask; }
637
638private:
639  void setAddressSpace(unsigned space) {
640    assert(space <= MaxAddressSpace);
641    Mask = (Mask & ~AddressSpaceMask)
642         | (((uint32_t) space) << AddressSpaceShift);
643  }
644
645  void setGCAttrType(QualType::GCAttrTypes type) {
646    Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
647  }
648
649  // bits:     |0 1 2|3 .. 4|5  ..  31|
650  //           |C R V|GCAttr|AddrSpace|
651  uint32_t Mask;
652
653  static const uint32_t CVRMask = 0x07;
654  static const uint32_t GCAttrMask = 0x18;
655  static const uint32_t GCAttrShift = 3;
656  static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask);
657  static const uint32_t AddressSpaceShift = 5;
658  static const unsigned MaxAddressSpace = QualType::MaxAddressSpace;
659};
660
661
662/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
663/// types are always canonical and have a literal name field.
664class BuiltinType : public Type {
665public:
666  enum Kind {
667    Void,
668
669    Bool,     // This is bool and/or _Bool.
670    Char_U,   // This is 'char' for targets where char is unsigned.
671    UChar,    // This is explicitly qualified unsigned char.
672    Char16,   // This is 'char16_t' for C++.
673    Char32,   // This is 'char32_t' for C++.
674    UShort,
675    UInt,
676    ULong,
677    ULongLong,
678    UInt128,  // __uint128_t
679
680    Char_S,   // This is 'char' for targets where char is signed.
681    SChar,    // This is explicitly qualified signed char.
682    WChar,    // This is 'wchar_t' for C++.
683    Short,
684    Int,
685    Long,
686    LongLong,
687    Int128,   // __int128_t
688
689    Float, Double, LongDouble,
690
691    NullPtr,  // This is the type of C++0x 'nullptr'.
692
693    Overload,  // This represents the type of an overloaded function declaration.
694    Dependent, // This represents the type of a type-dependent expression.
695
696    UndeducedAuto, // In C++0x, this represents the type of an auto variable
697                   // that has not been deduced yet.
698    ObjCId,    // This represents the ObjC 'id' type.
699    ObjCClass  // This represents the ObjC 'Class' type.
700  };
701private:
702  Kind TypeKind;
703public:
704  BuiltinType(Kind K)
705    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
706      TypeKind(K) {}
707
708  Kind getKind() const { return TypeKind; }
709  const char *getName(const LangOptions &LO) const;
710
711  virtual void getAsStringInternal(std::string &InnerString,
712                                   const PrintingPolicy &Policy) const;
713
714  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
715  static bool classof(const BuiltinType *) { return true; }
716};
717
718/// FixedWidthIntType - Used for arbitrary width types that we either don't
719/// want to or can't map to named integer types.  These always have a lower
720/// integer rank than builtin types of the same width.
721class FixedWidthIntType : public Type {
722private:
723  unsigned Width;
724  bool Signed;
725public:
726  FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false),
727                                          Width(W), Signed(S) {}
728
729  unsigned getWidth() const { return Width; }
730  bool isSigned() const { return Signed; }
731  const char *getName() const;
732
733  virtual void getAsStringInternal(std::string &InnerString,
734                                   const PrintingPolicy &Policy) const;
735
736  static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; }
737  static bool classof(const FixedWidthIntType *) { return true; }
738};
739
740/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
741/// types (_Complex float etc) as well as the GCC integer complex extensions.
742///
743class ComplexType : public Type, public llvm::FoldingSetNode {
744  QualType ElementType;
745  ComplexType(QualType Element, QualType CanonicalPtr) :
746    Type(Complex, CanonicalPtr, Element->isDependentType()),
747    ElementType(Element) {
748  }
749  friend class ASTContext;  // ASTContext creates these.
750public:
751  QualType getElementType() const { return ElementType; }
752
753  virtual void getAsStringInternal(std::string &InnerString,
754                                   const PrintingPolicy &Policy) const;
755
756  void Profile(llvm::FoldingSetNodeID &ID) {
757    Profile(ID, getElementType());
758  }
759  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
760    ID.AddPointer(Element.getAsOpaquePtr());
761  }
762
763  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
764  static bool classof(const ComplexType *) { return true; }
765};
766
767/// PointerType - C99 6.7.5.1 - Pointer Declarators.
768///
769class PointerType : public Type, public llvm::FoldingSetNode {
770  QualType PointeeType;
771
772  PointerType(QualType Pointee, QualType CanonicalPtr) :
773    Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
774  }
775  friend class ASTContext;  // ASTContext creates these.
776public:
777
778  virtual void getAsStringInternal(std::string &InnerString,
779                                   const PrintingPolicy &Policy) const;
780
781  QualType getPointeeType() const { return PointeeType; }
782
783  void Profile(llvm::FoldingSetNodeID &ID) {
784    Profile(ID, getPointeeType());
785  }
786  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
787    ID.AddPointer(Pointee.getAsOpaquePtr());
788  }
789
790  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
791  static bool classof(const PointerType *) { return true; }
792};
793
794/// BlockPointerType - pointer to a block type.
795/// This type is to represent types syntactically represented as
796/// "void (^)(int)", etc. Pointee is required to always be a function type.
797///
798class BlockPointerType : public Type, public llvm::FoldingSetNode {
799  QualType PointeeType;  // Block is some kind of pointer type
800  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
801    Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
802    PointeeType(Pointee) {
803  }
804  friend class ASTContext;  // ASTContext creates these.
805public:
806
807  // Get the pointee type. Pointee is required to always be a function type.
808  QualType getPointeeType() const { return PointeeType; }
809
810  virtual void getAsStringInternal(std::string &InnerString,
811                                   const PrintingPolicy &Policy) const;
812
813  void Profile(llvm::FoldingSetNodeID &ID) {
814      Profile(ID, getPointeeType());
815  }
816  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
817      ID.AddPointer(Pointee.getAsOpaquePtr());
818  }
819
820  static bool classof(const Type *T) {
821    return T->getTypeClass() == BlockPointer;
822  }
823  static bool classof(const BlockPointerType *) { return true; }
824};
825
826/// ReferenceType - Base for LValueReferenceType and RValueReferenceType
827///
828class ReferenceType : public Type, public llvm::FoldingSetNode {
829  QualType PointeeType;
830
831protected:
832  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) :
833    Type(tc, CanonicalRef, Referencee->isDependentType()),
834    PointeeType(Referencee) {
835  }
836public:
837  QualType getPointeeType() const { return PointeeType; }
838
839  void Profile(llvm::FoldingSetNodeID &ID) {
840    Profile(ID, getPointeeType());
841  }
842  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
843    ID.AddPointer(Referencee.getAsOpaquePtr());
844  }
845
846  static bool classof(const Type *T) {
847    return T->getTypeClass() == LValueReference ||
848           T->getTypeClass() == RValueReference;
849  }
850  static bool classof(const ReferenceType *) { return true; }
851};
852
853/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference
854///
855class LValueReferenceType : public ReferenceType {
856  LValueReferenceType(QualType Referencee, QualType CanonicalRef) :
857    ReferenceType(LValueReference, Referencee, CanonicalRef) {
858  }
859  friend class ASTContext; // ASTContext creates these
860public:
861  virtual void getAsStringInternal(std::string &InnerString,
862                                   const PrintingPolicy &Policy) const;
863
864  static bool classof(const Type *T) {
865    return T->getTypeClass() == LValueReference;
866  }
867  static bool classof(const LValueReferenceType *) { return true; }
868};
869
870/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference
871///
872class RValueReferenceType : public ReferenceType {
873  RValueReferenceType(QualType Referencee, QualType CanonicalRef) :
874    ReferenceType(RValueReference, Referencee, CanonicalRef) {
875  }
876  friend class ASTContext; // ASTContext creates these
877public:
878  virtual void getAsStringInternal(std::string &InnerString,
879                                   const PrintingPolicy &Policy) const;
880
881  static bool classof(const Type *T) {
882    return T->getTypeClass() == RValueReference;
883  }
884  static bool classof(const RValueReferenceType *) { return true; }
885};
886
887/// MemberPointerType - C++ 8.3.3 - Pointers to members
888///
889class MemberPointerType : public Type, public llvm::FoldingSetNode {
890  QualType PointeeType;
891  /// The class of which the pointee is a member. Must ultimately be a
892  /// RecordType, but could be a typedef or a template parameter too.
893  const Type *Class;
894
895  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
896    Type(MemberPointer, CanonicalPtr,
897         Cls->isDependentType() || Pointee->isDependentType()),
898    PointeeType(Pointee), Class(Cls) {
899  }
900  friend class ASTContext; // ASTContext creates these.
901public:
902
903  QualType getPointeeType() const { return PointeeType; }
904
905  const Type *getClass() const { return Class; }
906
907  virtual void getAsStringInternal(std::string &InnerString,
908                                   const PrintingPolicy &Policy) const;
909
910  void Profile(llvm::FoldingSetNodeID &ID) {
911    Profile(ID, getPointeeType(), getClass());
912  }
913  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
914                      const Type *Class) {
915    ID.AddPointer(Pointee.getAsOpaquePtr());
916    ID.AddPointer(Class);
917  }
918
919  static bool classof(const Type *T) {
920    return T->getTypeClass() == MemberPointer;
921  }
922  static bool classof(const MemberPointerType *) { return true; }
923};
924
925/// ArrayType - C99 6.7.5.2 - Array Declarators.
926///
927class ArrayType : public Type, public llvm::FoldingSetNode {
928public:
929  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
930  /// an array with a static size (e.g. int X[static 4]), or an array
931  /// with a star size (e.g. int X[*]).
932  /// 'static' is only allowed on function parameters.
933  enum ArraySizeModifier {
934    Normal, Static, Star
935  };
936private:
937  /// ElementType - The element type of the array.
938  QualType ElementType;
939
940  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
941  /// NOTE: These fields are packed into the bitfields space in the Type class.
942  unsigned SizeModifier : 2;
943
944  /// IndexTypeQuals - Capture qualifiers in declarations like:
945  /// 'int X[static restrict 4]'. For function parameters only.
946  unsigned IndexTypeQuals : 3;
947
948protected:
949  // C++ [temp.dep.type]p1:
950  //   A type is dependent if it is...
951  //     - an array type constructed from any dependent type or whose
952  //       size is specified by a constant expression that is
953  //       value-dependent,
954  ArrayType(TypeClass tc, QualType et, QualType can,
955            ArraySizeModifier sm, unsigned tq)
956    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
957      ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
958
959  friend class ASTContext;  // ASTContext creates these.
960public:
961  QualType getElementType() const { return ElementType; }
962  ArraySizeModifier getSizeModifier() const {
963    return ArraySizeModifier(SizeModifier);
964  }
965  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
966
967  static bool classof(const Type *T) {
968    return T->getTypeClass() == ConstantArray ||
969           T->getTypeClass() == ConstantArrayWithExpr ||
970           T->getTypeClass() == ConstantArrayWithoutExpr ||
971           T->getTypeClass() == VariableArray ||
972           T->getTypeClass() == IncompleteArray ||
973           T->getTypeClass() == DependentSizedArray;
974  }
975  static bool classof(const ArrayType *) { return true; }
976};
977
978/// ConstantArrayType - This class represents the canonical version of
979/// C arrays with a specified constant size.  For example, the canonical
980/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
981/// type is 'int' and the size is 404.
982class ConstantArrayType : public ArrayType {
983  llvm::APInt Size; // Allows us to unique the type.
984
985  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
986                    ArraySizeModifier sm, unsigned tq)
987    : ArrayType(ConstantArray, et, can, sm, tq),
988      Size(size) {}
989protected:
990  ConstantArrayType(TypeClass tc, QualType et, QualType can,
991                    const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
992    : ArrayType(tc, et, can, sm, tq), Size(size) {}
993  friend class ASTContext;  // ASTContext creates these.
994public:
995  const llvm::APInt &getSize() const { return Size; }
996  virtual void getAsStringInternal(std::string &InnerString,
997                                   const PrintingPolicy &Policy) const;
998
999  void Profile(llvm::FoldingSetNodeID &ID) {
1000    Profile(ID, getElementType(), getSize(),
1001            getSizeModifier(), getIndexTypeQualifier());
1002  }
1003  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
1004                      const llvm::APInt &ArraySize, ArraySizeModifier SizeMod,
1005                      unsigned TypeQuals) {
1006    ID.AddPointer(ET.getAsOpaquePtr());
1007    ID.AddInteger(ArraySize.getZExtValue());
1008    ID.AddInteger(SizeMod);
1009    ID.AddInteger(TypeQuals);
1010  }
1011  static bool classof(const Type *T) {
1012    return T->getTypeClass() == ConstantArray ||
1013           T->getTypeClass() == ConstantArrayWithExpr ||
1014           T->getTypeClass() == ConstantArrayWithoutExpr;
1015  }
1016  static bool classof(const ConstantArrayType *) { return true; }
1017};
1018
1019/// ConstantArrayWithExprType - This class represents C arrays with a
1020/// constant size specified by means of an integer constant expression.
1021/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where
1022/// the element type is 'int' and the size expression is 'sizeof(int)'.
1023/// These types are non-canonical.
1024class ConstantArrayWithExprType : public ConstantArrayType {
1025  /// SizeExpr - The ICE occurring in the concrete syntax.
1026  Expr *SizeExpr;
1027  /// Brackets - The left and right array brackets.
1028  SourceRange Brackets;
1029
1030  ConstantArrayWithExprType(QualType et, QualType can,
1031                            const llvm::APInt &size, Expr *e,
1032                            ArraySizeModifier sm, unsigned tq,
1033                            SourceRange brackets)
1034    : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq),
1035      SizeExpr(e), Brackets(brackets) {}
1036  friend class ASTContext;  // ASTContext creates these.
1037  virtual void Destroy(ASTContext& C);
1038
1039public:
1040  Expr *getSizeExpr() const { return SizeExpr; }
1041  SourceRange getBracketsRange() const { return Brackets; }
1042  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
1043  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
1044
1045  virtual void getAsStringInternal(std::string &InnerString,
1046                                   const PrintingPolicy &Policy) const;
1047
1048  static bool classof(const Type *T) {
1049    return T->getTypeClass() == ConstantArrayWithExpr;
1050  }
1051  static bool classof(const ConstantArrayWithExprType *) { return true; }
1052
1053  void Profile(llvm::FoldingSetNodeID &ID) {
1054    assert(0 && "Cannot unique ConstantArrayWithExprTypes.");
1055  }
1056};
1057
1058/// ConstantArrayWithoutExprType - This class represents C arrays with a
1059/// constant size that was not specified by an integer constant expression,
1060/// but inferred by static semantics.
1061/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType.
1062/// These types are non-canonical: the corresponding canonical type,
1063/// having the size specified in an APInt object, is a ConstantArrayType.
1064class ConstantArrayWithoutExprType : public ConstantArrayType {
1065
1066  ConstantArrayWithoutExprType(QualType et, QualType can,
1067                               const llvm::APInt &size,
1068                               ArraySizeModifier sm, unsigned tq)
1069    : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {}
1070  friend class ASTContext;  // ASTContext creates these.
1071
1072public:
1073  virtual void getAsStringInternal(std::string &InnerString,
1074                                   const PrintingPolicy &Policy) const;
1075
1076  static bool classof(const Type *T) {
1077    return T->getTypeClass() == ConstantArrayWithoutExpr;
1078  }
1079  static bool classof(const ConstantArrayWithoutExprType *) { return true; }
1080
1081  void Profile(llvm::FoldingSetNodeID &ID) {
1082    assert(0 && "Cannot unique ConstantArrayWithoutExprTypes.");
1083  }
1084};
1085
1086/// IncompleteArrayType - This class represents C arrays with an unspecified
1087/// size.  For example 'int A[]' has an IncompleteArrayType where the element
1088/// type is 'int' and the size is unspecified.
1089class IncompleteArrayType : public ArrayType {
1090
1091  IncompleteArrayType(QualType et, QualType can,
1092                      ArraySizeModifier sm, unsigned tq)
1093    : ArrayType(IncompleteArray, et, can, sm, tq) {}
1094  friend class ASTContext;  // ASTContext creates these.
1095public:
1096  virtual void getAsStringInternal(std::string &InnerString,
1097                                   const PrintingPolicy &Policy) const;
1098
1099  static bool classof(const Type *T) {
1100    return T->getTypeClass() == IncompleteArray;
1101  }
1102  static bool classof(const IncompleteArrayType *) { return true; }
1103
1104  friend class StmtIteratorBase;
1105
1106  void Profile(llvm::FoldingSetNodeID &ID) {
1107    Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier());
1108  }
1109
1110  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
1111                      ArraySizeModifier SizeMod, unsigned TypeQuals) {
1112    ID.AddPointer(ET.getAsOpaquePtr());
1113    ID.AddInteger(SizeMod);
1114    ID.AddInteger(TypeQuals);
1115  }
1116};
1117
1118/// VariableArrayType - This class represents C arrays with a specified size
1119/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
1120/// Since the size expression is an arbitrary expression, we store it as such.
1121///
1122/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
1123/// should not be: two lexically equivalent variable array types could mean
1124/// different things, for example, these variables do not have the same type
1125/// dynamically:
1126///
1127/// void foo(int x) {
1128///   int Y[x];
1129///   ++x;
1130///   int Z[x];
1131/// }
1132///
1133class VariableArrayType : public ArrayType {
1134  /// SizeExpr - An assignment expression. VLA's are only permitted within
1135  /// a function block.
1136  Stmt *SizeExpr;
1137  /// Brackets - The left and right array brackets.
1138  SourceRange Brackets;
1139
1140  VariableArrayType(QualType et, QualType can, Expr *e,
1141                    ArraySizeModifier sm, unsigned tq,
1142                    SourceRange brackets)
1143    : ArrayType(VariableArray, et, can, sm, tq),
1144      SizeExpr((Stmt*) e), Brackets(brackets) {}
1145  friend class ASTContext;  // ASTContext creates these.
1146  virtual void Destroy(ASTContext& C);
1147
1148public:
1149  Expr *getSizeExpr() const {
1150    // We use C-style casts instead of cast<> here because we do not wish
1151    // to have a dependency of Type.h on Stmt.h/Expr.h.
1152    return (Expr*) SizeExpr;
1153  }
1154  SourceRange getBracketsRange() const { return Brackets; }
1155  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
1156  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
1157
1158  virtual void getAsStringInternal(std::string &InnerString,
1159                                   const PrintingPolicy &Policy) const;
1160
1161  static bool classof(const Type *T) {
1162    return T->getTypeClass() == VariableArray;
1163  }
1164  static bool classof(const VariableArrayType *) { return true; }
1165
1166  friend class StmtIteratorBase;
1167
1168  void Profile(llvm::FoldingSetNodeID &ID) {
1169    assert(0 && "Cannnot unique VariableArrayTypes.");
1170  }
1171};
1172
1173/// DependentSizedArrayType - This type represents an array type in
1174/// C++ whose size is a value-dependent expression. For example:
1175/// @code
1176/// template<typename T, int Size>
1177/// class array {
1178///   T data[Size];
1179/// };
1180/// @endcode
1181/// For these types, we won't actually know what the array bound is
1182/// until template instantiation occurs, at which point this will
1183/// become either a ConstantArrayType or a VariableArrayType.
1184class DependentSizedArrayType : public ArrayType {
1185  ASTContext &Context;
1186
1187  /// SizeExpr - An assignment expression that will instantiate to the
1188  /// size of the array.
1189  Stmt *SizeExpr;
1190  /// Brackets - The left and right array brackets.
1191  SourceRange Brackets;
1192
1193  DependentSizedArrayType(ASTContext &Context, QualType et, QualType can,
1194                          Expr *e, ArraySizeModifier sm, unsigned tq,
1195                          SourceRange brackets)
1196    : ArrayType(DependentSizedArray, et, can, sm, tq),
1197      Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {}
1198  friend class ASTContext;  // ASTContext creates these.
1199  virtual void Destroy(ASTContext& C);
1200
1201public:
1202  Expr *getSizeExpr() const {
1203    // We use C-style casts instead of cast<> here because we do not wish
1204    // to have a dependency of Type.h on Stmt.h/Expr.h.
1205    return (Expr*) SizeExpr;
1206  }
1207  SourceRange getBracketsRange() const { return Brackets; }
1208  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
1209  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
1210
1211  virtual void getAsStringInternal(std::string &InnerString,
1212                                   const PrintingPolicy &Policy) const;
1213
1214  static bool classof(const Type *T) {
1215    return T->getTypeClass() == DependentSizedArray;
1216  }
1217  static bool classof(const DependentSizedArrayType *) { return true; }
1218
1219  friend class StmtIteratorBase;
1220
1221
1222  void Profile(llvm::FoldingSetNodeID &ID) {
1223    Profile(ID, Context, getElementType(),
1224            getSizeModifier(), getIndexTypeQualifier(), getSizeExpr());
1225  }
1226
1227  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
1228                      QualType ET, ArraySizeModifier SizeMod,
1229                      unsigned TypeQuals, Expr *E);
1230};
1231
1232/// DependentSizedExtVectorType - This type represent an extended vector type
1233/// where either the type or size is dependent. For example:
1234/// @code
1235/// template<typename T, int Size>
1236/// class vector {
1237///   typedef T __attribute__((ext_vector_type(Size))) type;
1238/// }
1239/// @endcode
1240class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
1241  ASTContext &Context;
1242  Expr *SizeExpr;
1243  /// ElementType - The element type of the array.
1244  QualType ElementType;
1245  SourceLocation loc;
1246
1247  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType,
1248                              QualType can, Expr *SizeExpr, SourceLocation loc)
1249    : Type (DependentSizedExtVector, can, true),
1250      Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
1251      loc(loc) {}
1252  friend class ASTContext;
1253  virtual void Destroy(ASTContext& C);
1254
1255public:
1256  Expr *getSizeExpr() const { return SizeExpr; }
1257  QualType getElementType() const { return ElementType; }
1258  SourceLocation getAttributeLoc() const { return loc; }
1259
1260  virtual void getAsStringInternal(std::string &InnerString,
1261                                   const PrintingPolicy &Policy) const;
1262
1263  static bool classof(const Type *T) {
1264    return T->getTypeClass() == DependentSizedExtVector;
1265  }
1266  static bool classof(const DependentSizedExtVectorType *) { return true; }
1267
1268  void Profile(llvm::FoldingSetNodeID &ID) {
1269    Profile(ID, Context, getElementType(), getSizeExpr());
1270  }
1271
1272  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
1273                      QualType ElementType, Expr *SizeExpr);
1274};
1275
1276
1277/// VectorType - GCC generic vector type. This type is created using
1278/// __attribute__((vector_size(n)), where "n" specifies the vector size in
1279/// bytes. Since the constructor takes the number of vector elements, the
1280/// client is responsible for converting the size into the number of elements.
1281class VectorType : public Type, public llvm::FoldingSetNode {
1282protected:
1283  /// ElementType - The element type of the vector.
1284  QualType ElementType;
1285
1286  /// NumElements - The number of elements in the vector.
1287  unsigned NumElements;
1288
1289  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
1290    Type(Vector, canonType, vecType->isDependentType()),
1291    ElementType(vecType), NumElements(nElements) {}
1292  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
1293             QualType canonType)
1294    : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
1295      NumElements(nElements) {}
1296  friend class ASTContext;  // ASTContext creates these.
1297public:
1298
1299  QualType getElementType() const { return ElementType; }
1300  unsigned getNumElements() const { return NumElements; }
1301
1302  virtual void getAsStringInternal(std::string &InnerString,
1303                                   const PrintingPolicy &Policy) const;
1304
1305  void Profile(llvm::FoldingSetNodeID &ID) {
1306    Profile(ID, getElementType(), getNumElements(), getTypeClass());
1307  }
1308  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
1309                      unsigned NumElements, TypeClass TypeClass) {
1310    ID.AddPointer(ElementType.getAsOpaquePtr());
1311    ID.AddInteger(NumElements);
1312    ID.AddInteger(TypeClass);
1313  }
1314  static bool classof(const Type *T) {
1315    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
1316  }
1317  static bool classof(const VectorType *) { return true; }
1318};
1319
1320/// ExtVectorType - Extended vector type. This type is created using
1321/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
1322/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
1323/// class enables syntactic extensions, like Vector Components for accessing
1324/// points, colors, and textures (modeled after OpenGL Shading Language).
1325class ExtVectorType : public VectorType {
1326  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
1327    VectorType(ExtVector, vecType, nElements, canonType) {}
1328  friend class ASTContext;  // ASTContext creates these.
1329public:
1330  static int getPointAccessorIdx(char c) {
1331    switch (c) {
1332    default: return -1;
1333    case 'x': return 0;
1334    case 'y': return 1;
1335    case 'z': return 2;
1336    case 'w': return 3;
1337    }
1338  }
1339  static int getNumericAccessorIdx(char c) {
1340    switch (c) {
1341      default: return -1;
1342      case '0': return 0;
1343      case '1': return 1;
1344      case '2': return 2;
1345      case '3': return 3;
1346      case '4': return 4;
1347      case '5': return 5;
1348      case '6': return 6;
1349      case '7': return 7;
1350      case '8': return 8;
1351      case '9': return 9;
1352      case 'A':
1353      case 'a': return 10;
1354      case 'B':
1355      case 'b': return 11;
1356      case 'C':
1357      case 'c': return 12;
1358      case 'D':
1359      case 'd': return 13;
1360      case 'E':
1361      case 'e': return 14;
1362      case 'F':
1363      case 'f': return 15;
1364    }
1365  }
1366
1367  static int getAccessorIdx(char c) {
1368    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
1369    return getNumericAccessorIdx(c);
1370  }
1371
1372  bool isAccessorWithinNumElements(char c) const {
1373    if (int idx = getAccessorIdx(c)+1)
1374      return unsigned(idx-1) < NumElements;
1375    return false;
1376  }
1377  virtual void getAsStringInternal(std::string &InnerString,
1378                                   const PrintingPolicy &Policy) const;
1379
1380  static bool classof(const Type *T) {
1381    return T->getTypeClass() == ExtVector;
1382  }
1383  static bool classof(const ExtVectorType *) { return true; }
1384};
1385
1386/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
1387/// class of FunctionNoProtoType and FunctionProtoType.
1388///
1389class FunctionType : public Type {
1390  /// SubClassData - This field is owned by the subclass, put here to pack
1391  /// tightly with the ivars in Type.
1392  bool SubClassData : 1;
1393
1394  /// TypeQuals - Used only by FunctionProtoType, put here to pack with the
1395  /// other bitfields.
1396  /// The qualifiers are part of FunctionProtoType because...
1397  ///
1398  /// C++ 8.3.5p4: The return type, the parameter type list and the
1399  /// cv-qualifier-seq, [...], are part of the function type.
1400  ///
1401  unsigned TypeQuals : 3;
1402
1403  /// NoReturn - Indicates if the function type is attribute noreturn.
1404  unsigned NoReturn : 1;
1405
1406  // The type returned by the function.
1407  QualType ResultType;
1408protected:
1409  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
1410               unsigned typeQuals, QualType Canonical, bool Dependent,
1411               bool noReturn = false)
1412    : Type(tc, Canonical, Dependent),
1413      SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn),
1414      ResultType(res) {}
1415  bool getSubClassData() const { return SubClassData; }
1416  unsigned getTypeQuals() const { return TypeQuals; }
1417public:
1418
1419  QualType getResultType() const { return ResultType; }
1420  bool getNoReturnAttr() const { return NoReturn; }
1421
1422
1423  static bool classof(const Type *T) {
1424    return T->getTypeClass() == FunctionNoProto ||
1425           T->getTypeClass() == FunctionProto;
1426  }
1427  static bool classof(const FunctionType *) { return true; }
1428};
1429
1430/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has
1431/// no information available about its arguments.
1432class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
1433  FunctionNoProtoType(QualType Result, QualType Canonical,
1434                      bool NoReturn = false)
1435    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1436                   /*Dependent=*/false, NoReturn) {}
1437  friend class ASTContext;  // ASTContext creates these.
1438public:
1439  // No additional state past what FunctionType provides.
1440
1441  virtual void getAsStringInternal(std::string &InnerString,
1442                                   const PrintingPolicy &Policy) const;
1443
1444  void Profile(llvm::FoldingSetNodeID &ID) {
1445    Profile(ID, getResultType(), getNoReturnAttr());
1446  }
1447  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
1448                      bool NoReturn) {
1449    ID.AddInteger(NoReturn);
1450    ID.AddPointer(ResultType.getAsOpaquePtr());
1451  }
1452
1453  static bool classof(const Type *T) {
1454    return T->getTypeClass() == FunctionNoProto;
1455  }
1456  static bool classof(const FunctionNoProtoType *) { return true; }
1457};
1458
1459/// FunctionProtoType - Represents a prototype with argument type info, e.g.
1460/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
1461/// arguments, not as having a single void argument. Such a type can have an
1462/// exception specification, but this specification is not part of the canonical
1463/// type.
1464class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode {
1465  /// hasAnyDependentType - Determine whether there are any dependent
1466  /// types within the arguments passed in.
1467  static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
1468    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
1469      if (ArgArray[Idx]->isDependentType())
1470    return true;
1471
1472    return false;
1473  }
1474
1475  FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs,
1476                    bool isVariadic, unsigned typeQuals, bool hasExs,
1477                    bool hasAnyExs, const QualType *ExArray,
1478                    unsigned numExs, QualType Canonical, bool NoReturn)
1479    : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
1480                   (Result->isDependentType() ||
1481                    hasAnyDependentType(ArgArray, numArgs)), NoReturn),
1482      NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs),
1483      AnyExceptionSpec(hasAnyExs) {
1484    // Fill in the trailing argument array.
1485    QualType *ArgInfo = reinterpret_cast<QualType*>(this+1);
1486    for (unsigned i = 0; i != numArgs; ++i)
1487      ArgInfo[i] = ArgArray[i];
1488    // Fill in the exception array.
1489    QualType *Ex = ArgInfo + numArgs;
1490    for (unsigned i = 0; i != numExs; ++i)
1491      Ex[i] = ExArray[i];
1492  }
1493
1494  /// NumArgs - The number of arguments this function has, not counting '...'.
1495  unsigned NumArgs : 20;
1496
1497  /// NumExceptions - The number of types in the exception spec, if any.
1498  unsigned NumExceptions : 10;
1499
1500  /// HasExceptionSpec - Whether this function has an exception spec at all.
1501  bool HasExceptionSpec : 1;
1502
1503  /// AnyExceptionSpec - Whether this function has a throw(...) spec.
1504  bool AnyExceptionSpec : 1;
1505
1506  /// ArgInfo - There is an variable size array after the class in memory that
1507  /// holds the argument types.
1508
1509  /// Exceptions - There is another variable size array after ArgInfo that
1510  /// holds the exception types.
1511
1512  friend class ASTContext;  // ASTContext creates these.
1513
1514public:
1515  unsigned getNumArgs() const { return NumArgs; }
1516  QualType getArgType(unsigned i) const {
1517    assert(i < NumArgs && "Invalid argument number!");
1518    return arg_type_begin()[i];
1519  }
1520
1521  bool hasExceptionSpec() const { return HasExceptionSpec; }
1522  bool hasAnyExceptionSpec() const { return AnyExceptionSpec; }
1523  unsigned getNumExceptions() const { return NumExceptions; }
1524  QualType getExceptionType(unsigned i) const {
1525    assert(i < NumExceptions && "Invalid exception number!");
1526    return exception_begin()[i];
1527  }
1528  bool hasEmptyExceptionSpec() const {
1529    return hasExceptionSpec() && !hasAnyExceptionSpec() &&
1530      getNumExceptions() == 0;
1531  }
1532
1533  bool isVariadic() const { return getSubClassData(); }
1534  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
1535
1536  typedef const QualType *arg_type_iterator;
1537  arg_type_iterator arg_type_begin() const {
1538    return reinterpret_cast<const QualType *>(this+1);
1539  }
1540  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
1541
1542  typedef const QualType *exception_iterator;
1543  exception_iterator exception_begin() const {
1544    // exceptions begin where arguments end
1545    return arg_type_end();
1546  }
1547  exception_iterator exception_end() const {
1548    return exception_begin() + NumExceptions;
1549  }
1550
1551  virtual void getAsStringInternal(std::string &InnerString,
1552                                   const PrintingPolicy &Policy) const;
1553
1554  static bool classof(const Type *T) {
1555    return T->getTypeClass() == FunctionProto;
1556  }
1557  static bool classof(const FunctionProtoType *) { return true; }
1558
1559  void Profile(llvm::FoldingSetNodeID &ID);
1560  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
1561                      arg_type_iterator ArgTys, unsigned NumArgs,
1562                      bool isVariadic, unsigned TypeQuals,
1563                      bool hasExceptionSpec, bool anyExceptionSpec,
1564                      unsigned NumExceptions, exception_iterator Exs,
1565                      bool NoReturn);
1566};
1567
1568
1569class TypedefType : public Type {
1570  TypedefDecl *Decl;
1571protected:
1572  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
1573    : Type(tc, can, can->isDependentType()), Decl(D) {
1574    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1575  }
1576  friend class ASTContext;  // ASTContext creates these.
1577public:
1578
1579  TypedefDecl *getDecl() const { return Decl; }
1580
1581  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1582  /// potentially looking through *all* consecutive typedefs.  This returns the
1583  /// sum of the type qualifiers, so if you have:
1584  ///   typedef const int A;
1585  ///   typedef volatile A B;
1586  /// looking through the typedefs for B will give you "const volatile A".
1587  QualType LookThroughTypedefs() const;
1588
1589  virtual void getAsStringInternal(std::string &InnerString,
1590                                   const PrintingPolicy &Policy) const;
1591
1592  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
1593  static bool classof(const TypedefType *) { return true; }
1594};
1595
1596/// TypeOfExprType (GCC extension).
1597class TypeOfExprType : public Type {
1598  Expr *TOExpr;
1599
1600protected:
1601  TypeOfExprType(Expr *E, QualType can = QualType());
1602  friend class ASTContext;  // ASTContext creates these.
1603public:
1604  Expr *getUnderlyingExpr() const { return TOExpr; }
1605
1606  virtual void getAsStringInternal(std::string &InnerString,
1607                                   const PrintingPolicy &Policy) const;
1608
1609  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
1610  static bool classof(const TypeOfExprType *) { return true; }
1611};
1612
1613/// Subclass of TypeOfExprType that is used for canonical, dependent
1614/// typeof(expr) types.
1615class DependentTypeOfExprType
1616  : public TypeOfExprType, public llvm::FoldingSetNode {
1617  ASTContext &Context;
1618
1619public:
1620  DependentTypeOfExprType(ASTContext &Context, Expr *E)
1621    : TypeOfExprType(E), Context(Context) { }
1622
1623  void Profile(llvm::FoldingSetNodeID &ID) {
1624    Profile(ID, Context, getUnderlyingExpr());
1625  }
1626
1627  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
1628                      Expr *E);
1629};
1630
1631/// TypeOfType (GCC extension).
1632class TypeOfType : public Type {
1633  QualType TOType;
1634  TypeOfType(QualType T, QualType can)
1635    : Type(TypeOf, can, T->isDependentType()), TOType(T) {
1636    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1637  }
1638  friend class ASTContext;  // ASTContext creates these.
1639public:
1640  QualType getUnderlyingType() const { return TOType; }
1641
1642  virtual void getAsStringInternal(std::string &InnerString,
1643                                   const PrintingPolicy &Policy) const;
1644
1645  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
1646  static bool classof(const TypeOfType *) { return true; }
1647};
1648
1649/// DecltypeType (C++0x)
1650class DecltypeType : public Type {
1651  Expr *E;
1652
1653  // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to
1654  // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr
1655  // from it.
1656  QualType UnderlyingType;
1657
1658protected:
1659  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
1660  friend class ASTContext;  // ASTContext creates these.
1661public:
1662  Expr *getUnderlyingExpr() const { return E; }
1663  QualType getUnderlyingType() const { return UnderlyingType; }
1664
1665  virtual void getAsStringInternal(std::string &InnerString,
1666                                   const PrintingPolicy &Policy) const;
1667
1668  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
1669  static bool classof(const DecltypeType *) { return true; }
1670};
1671
1672/// Subclass of DecltypeType that is used for canonical, dependent
1673/// C++0x decltype types.
1674class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
1675  ASTContext &Context;
1676
1677public:
1678  DependentDecltypeType(ASTContext &Context, Expr *E);
1679
1680  void Profile(llvm::FoldingSetNodeID &ID) {
1681    Profile(ID, Context, getUnderlyingExpr());
1682  }
1683
1684  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
1685                      Expr *E);
1686};
1687
1688class TagType : public Type {
1689  /// Stores the TagDecl associated with this type. The decl will
1690  /// point to the TagDecl that actually defines the entity (or is a
1691  /// definition in progress), if there is such a definition. The
1692  /// single-bit value will be non-zero when this tag is in the
1693  /// process of being defined.
1694  mutable llvm::PointerIntPair<TagDecl *, 1> decl;
1695  friend class ASTContext;
1696  friend class TagDecl;
1697
1698protected:
1699  TagType(TypeClass TC, TagDecl *D, QualType can);
1700
1701public:
1702  TagDecl *getDecl() const { return decl.getPointer(); }
1703
1704  /// @brief Determines whether this type is in the process of being
1705  /// defined.
1706  bool isBeingDefined() const { return decl.getInt(); }
1707  void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); }
1708
1709  virtual void getAsStringInternal(std::string &InnerString,
1710                                   const PrintingPolicy &Policy) const;
1711
1712  static bool classof(const Type *T) {
1713    return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast;
1714  }
1715  static bool classof(const TagType *) { return true; }
1716  static bool classof(const RecordType *) { return true; }
1717  static bool classof(const EnumType *) { return true; }
1718};
1719
1720/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
1721/// to detect TagType objects of structs/unions/classes.
1722class RecordType : public TagType {
1723protected:
1724  explicit RecordType(RecordDecl *D)
1725    : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { }
1726  explicit RecordType(TypeClass TC, RecordDecl *D)
1727    : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { }
1728  friend class ASTContext;   // ASTContext creates these.
1729public:
1730
1731  RecordDecl *getDecl() const {
1732    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
1733  }
1734
1735  // FIXME: This predicate is a helper to QualType/Type. It needs to
1736  // recursively check all fields for const-ness. If any field is declared
1737  // const, it needs to return false.
1738  bool hasConstFields() const { return false; }
1739
1740  // FIXME: RecordType needs to check when it is created that all fields are in
1741  // the same address space, and return that.
1742  unsigned getAddressSpace() const { return 0; }
1743
1744  static bool classof(const TagType *T);
1745  static bool classof(const Type *T) {
1746    return isa<TagType>(T) && classof(cast<TagType>(T));
1747  }
1748  static bool classof(const RecordType *) { return true; }
1749};
1750
1751/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
1752/// to detect TagType objects of enums.
1753class EnumType : public TagType {
1754  explicit EnumType(EnumDecl *D)
1755    : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { }
1756  friend class ASTContext;   // ASTContext creates these.
1757public:
1758
1759  EnumDecl *getDecl() const {
1760    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
1761  }
1762
1763  static bool classof(const TagType *T);
1764  static bool classof(const Type *T) {
1765    return isa<TagType>(T) && classof(cast<TagType>(T));
1766  }
1767  static bool classof(const EnumType *) { return true; }
1768};
1769
1770class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
1771  unsigned Depth : 15;
1772  unsigned Index : 16;
1773  unsigned ParameterPack : 1;
1774  IdentifierInfo *Name;
1775
1776  TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N,
1777                       QualType Canon)
1778    : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
1779      Depth(D), Index(I), ParameterPack(PP), Name(N) { }
1780
1781  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
1782    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
1783      Depth(D), Index(I), ParameterPack(PP), Name(0) { }
1784
1785  friend class ASTContext;  // ASTContext creates these
1786
1787public:
1788  unsigned getDepth() const { return Depth; }
1789  unsigned getIndex() const { return Index; }
1790  bool isParameterPack() const { return ParameterPack; }
1791  IdentifierInfo *getName() const { return Name; }
1792
1793  virtual void getAsStringInternal(std::string &InnerString,
1794                                   const PrintingPolicy &Policy) const;
1795
1796  void Profile(llvm::FoldingSetNodeID &ID) {
1797    Profile(ID, Depth, Index, ParameterPack, Name);
1798  }
1799
1800  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
1801                      unsigned Index, bool ParameterPack,
1802                      IdentifierInfo *Name) {
1803    ID.AddInteger(Depth);
1804    ID.AddInteger(Index);
1805    ID.AddBoolean(ParameterPack);
1806    ID.AddPointer(Name);
1807  }
1808
1809  static bool classof(const Type *T) {
1810    return T->getTypeClass() == TemplateTypeParm;
1811  }
1812  static bool classof(const TemplateTypeParmType *T) { return true; }
1813};
1814
1815/// \brief Represents the type of a template specialization as written
1816/// in the source code.
1817///
1818/// Template specialization types represent the syntactic form of a
1819/// template-id that refers to a type, e.g., @c vector<int>. Some
1820/// template specialization types are syntactic sugar, whose canonical
1821/// type will point to some other type node that represents the
1822/// instantiation or class template specialization. For example, a
1823/// class template specialization type of @c vector<int> will refer to
1824/// a tag type for the instantiation
1825/// @c std::vector<int, std::allocator<int>>.
1826///
1827/// Other template specialization types, for which the template name
1828/// is dependent, may be canonical types. These types are always
1829/// dependent.
1830class TemplateSpecializationType
1831  : public Type, public llvm::FoldingSetNode {
1832
1833  // FIXME: Currently needed for profiling expressions; can we avoid this?
1834  ASTContext &Context;
1835
1836    /// \brief The name of the template being specialized.
1837  TemplateName Template;
1838
1839  /// \brief - The number of template arguments named in this class
1840  /// template specialization.
1841  unsigned NumArgs;
1842
1843  TemplateSpecializationType(ASTContext &Context,
1844                             TemplateName T,
1845                             const TemplateArgument *Args,
1846                             unsigned NumArgs, QualType Canon);
1847
1848  virtual void Destroy(ASTContext& C);
1849
1850  friend class ASTContext;  // ASTContext creates these
1851
1852public:
1853  /// \brief Determine whether any of the given template arguments are
1854  /// dependent.
1855  static bool anyDependentTemplateArguments(const TemplateArgument *Args,
1856                                            unsigned NumArgs);
1857
1858  /// \brief Print a template argument list, including the '<' and '>'
1859  /// enclosing the template arguments.
1860  static std::string PrintTemplateArgumentList(const TemplateArgument *Args,
1861                                               unsigned NumArgs,
1862                                               const PrintingPolicy &Policy);
1863
1864  typedef const TemplateArgument * iterator;
1865
1866  iterator begin() const { return getArgs(); }
1867  iterator end() const;
1868
1869  /// \brief Retrieve the name of the template that we are specializing.
1870  TemplateName getTemplateName() const { return Template; }
1871
1872  /// \brief Retrieve the template arguments.
1873  const TemplateArgument *getArgs() const {
1874    return reinterpret_cast<const TemplateArgument *>(this + 1);
1875  }
1876
1877  /// \brief Retrieve the number of template arguments.
1878  unsigned getNumArgs() const { return NumArgs; }
1879
1880  /// \brief Retrieve a specific template argument as a type.
1881  /// \precondition @c isArgType(Arg)
1882  const TemplateArgument &getArg(unsigned Idx) const;
1883
1884  virtual void getAsStringInternal(std::string &InnerString,
1885                                   const PrintingPolicy &Policy) const;
1886
1887  void Profile(llvm::FoldingSetNodeID &ID) {
1888    Profile(ID, Template, getArgs(), NumArgs, Context);
1889  }
1890
1891  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
1892                      const TemplateArgument *Args, unsigned NumArgs,
1893                      ASTContext &Context);
1894
1895  static bool classof(const Type *T) {
1896    return T->getTypeClass() == TemplateSpecialization;
1897  }
1898  static bool classof(const TemplateSpecializationType *T) { return true; }
1899};
1900
1901/// \brief Represents a type that was referred to via a qualified
1902/// name, e.g., N::M::type.
1903///
1904/// This type is used to keep track of a type name as written in the
1905/// source code, including any nested-name-specifiers. The type itself
1906/// is always "sugar", used to express what was written in the source
1907/// code but containing no additional semantic information.
1908class QualifiedNameType : public Type, public llvm::FoldingSetNode {
1909  /// \brief The nested name specifier containing the qualifier.
1910  NestedNameSpecifier *NNS;
1911
1912  /// \brief The type that this qualified name refers to.
1913  QualType NamedType;
1914
1915  QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType,
1916                    QualType CanonType)
1917    : Type(QualifiedName, CanonType, NamedType->isDependentType()),
1918      NNS(NNS), NamedType(NamedType) { }
1919
1920  friend class ASTContext;  // ASTContext creates these
1921
1922public:
1923  /// \brief Retrieve the qualification on this type.
1924  NestedNameSpecifier *getQualifier() const { return NNS; }
1925
1926  /// \brief Retrieve the type named by the qualified-id.
1927  QualType getNamedType() const { return NamedType; }
1928
1929  virtual void getAsStringInternal(std::string &InnerString,
1930                                   const PrintingPolicy &Policy) const;
1931
1932  void Profile(llvm::FoldingSetNodeID &ID) {
1933    Profile(ID, NNS, NamedType);
1934  }
1935
1936  static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
1937                      QualType NamedType) {
1938    ID.AddPointer(NNS);
1939    NamedType.Profile(ID);
1940  }
1941
1942  static bool classof(const Type *T) {
1943    return T->getTypeClass() == QualifiedName;
1944  }
1945  static bool classof(const QualifiedNameType *T) { return true; }
1946};
1947
1948/// \brief Represents a 'typename' specifier that names a type within
1949/// a dependent type, e.g., "typename T::type".
1950///
1951/// TypenameType has a very similar structure to QualifiedNameType,
1952/// which also involves a nested-name-specifier following by a type,
1953/// and (FIXME!) both can even be prefixed by the 'typename'
1954/// keyword. However, the two types serve very different roles:
1955/// QualifiedNameType is a non-semantic type that serves only as sugar
1956/// to show how a particular type was written in the source
1957/// code. TypenameType, on the other hand, only occurs when the
1958/// nested-name-specifier is dependent, such that we cannot resolve
1959/// the actual type until after instantiation.
1960class TypenameType : public Type, public llvm::FoldingSetNode {
1961  /// \brief The nested name specifier containing the qualifier.
1962  NestedNameSpecifier *NNS;
1963
1964  typedef llvm::PointerUnion<const IdentifierInfo *,
1965                             const TemplateSpecializationType *> NameType;
1966
1967  /// \brief The type that this typename specifier refers to.
1968  NameType Name;
1969
1970  TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name,
1971               QualType CanonType)
1972    : Type(Typename, CanonType, true), NNS(NNS), Name(Name) {
1973    assert(NNS->isDependent() &&
1974           "TypenameType requires a dependent nested-name-specifier");
1975  }
1976
1977  TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty,
1978               QualType CanonType)
1979    : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) {
1980    assert(NNS->isDependent() &&
1981           "TypenameType requires a dependent nested-name-specifier");
1982  }
1983
1984  friend class ASTContext;  // ASTContext creates these
1985
1986public:
1987  /// \brief Retrieve the qualification on this type.
1988  NestedNameSpecifier *getQualifier() const { return NNS; }
1989
1990  /// \brief Retrieve the type named by the typename specifier as an
1991  /// identifier.
1992  ///
1993  /// This routine will return a non-NULL identifier pointer when the
1994  /// form of the original typename was terminated by an identifier,
1995  /// e.g., "typename T::type".
1996  const IdentifierInfo *getIdentifier() const {
1997    return Name.dyn_cast<const IdentifierInfo *>();
1998  }
1999
2000  /// \brief Retrieve the type named by the typename specifier as a
2001  /// type specialization.
2002  const TemplateSpecializationType *getTemplateId() const {
2003    return Name.dyn_cast<const TemplateSpecializationType *>();
2004  }
2005
2006  virtual void getAsStringInternal(std::string &InnerString,
2007                                   const PrintingPolicy &Policy) const;
2008
2009  void Profile(llvm::FoldingSetNodeID &ID) {
2010    Profile(ID, NNS, Name);
2011  }
2012
2013  static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS,
2014                      NameType Name) {
2015    ID.AddPointer(NNS);
2016    ID.AddPointer(Name.getOpaqueValue());
2017  }
2018
2019  static bool classof(const Type *T) {
2020    return T->getTypeClass() == Typename;
2021  }
2022  static bool classof(const TypenameType *T) { return true; }
2023};
2024
2025/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
2026/// object oriented design.  They basically correspond to C++ classes.  There
2027/// are two kinds of interface types, normal interfaces like "NSString" and
2028/// qualified interfaces, which are qualified with a protocol list like
2029/// "NSString<NSCopyable, NSAmazing>".
2030class ObjCInterfaceType : public Type, public llvm::FoldingSetNode {
2031  ObjCInterfaceDecl *Decl;
2032
2033  // List of protocols for this protocol conforming object type
2034  // List is sorted on protocol name. No protocol is enterred more than once.
2035  llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols;
2036
2037  ObjCInterfaceType(ObjCInterfaceDecl *D,
2038                    ObjCProtocolDecl **Protos, unsigned NumP) :
2039    Type(ObjCInterface, QualType(), /*Dependent=*/false),
2040    Decl(D), Protocols(Protos, Protos+NumP) { }
2041  friend class ASTContext;  // ASTContext creates these.
2042public:
2043  ObjCInterfaceDecl *getDecl() const { return Decl; }
2044
2045  /// getNumProtocols - Return the number of qualifying protocols in this
2046  /// interface type, or 0 if there are none.
2047  unsigned getNumProtocols() const { return Protocols.size(); }
2048
2049  /// qual_iterator and friends: this provides access to the (potentially empty)
2050  /// list of protocols qualifying this interface.
2051  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
2052  qual_iterator qual_begin() const { return Protocols.begin(); }
2053  qual_iterator qual_end() const   { return Protocols.end(); }
2054  bool qual_empty() const { return Protocols.size() == 0; }
2055
2056  virtual void getAsStringInternal(std::string &InnerString,
2057                                   const PrintingPolicy &Policy) const;
2058
2059  void Profile(llvm::FoldingSetNodeID &ID);
2060  static void Profile(llvm::FoldingSetNodeID &ID,
2061                      const ObjCInterfaceDecl *Decl,
2062                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
2063
2064  static bool classof(const Type *T) {
2065    return T->getTypeClass() == ObjCInterface;
2066  }
2067  static bool classof(const ObjCInterfaceType *) { return true; }
2068};
2069
2070/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>',
2071/// and 'Interface <p> *'.
2072///
2073/// Duplicate protocols are removed and protocol list is canonicalized to be in
2074/// alphabetical order.
2075class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
2076  QualType PointeeType; // A builtin or interface type.
2077
2078  // List of protocols for this protocol conforming object type
2079  // List is sorted on protocol name. No protocol is entered more than once.
2080  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
2081
2082  ObjCObjectPointerType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) :
2083    Type(ObjCObjectPointer, QualType(), /*Dependent=*/false),
2084    PointeeType(T), Protocols(Protos, Protos+NumP) { }
2085  friend class ASTContext;  // ASTContext creates these.
2086
2087public:
2088  // Get the pointee type. Pointee will either be:
2089  // - a built-in type (for 'id' and 'Class').
2090  // - an interface type (for user-defined types).
2091  // - a TypedefType whose canonical type is an interface (as in 'T' below).
2092  //   For example: typedef NSObject T; T *var;
2093  QualType getPointeeType() const { return PointeeType; }
2094
2095  const ObjCInterfaceType *getInterfaceType() const {
2096    return PointeeType->getAsObjCInterfaceType();
2097  }
2098  /// getInterfaceDecl - returns an interface decl for user-defined types.
2099  ObjCInterfaceDecl *getInterfaceDecl() const {
2100    return getInterfaceType() ? getInterfaceType()->getDecl() : 0;
2101  }
2102  /// isObjCIdType - true for "id".
2103  bool isObjCIdType() const {
2104    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) &&
2105           !Protocols.size();
2106  }
2107  /// isObjCClassType - true for "Class".
2108  bool isObjCClassType() const {
2109    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) &&
2110           !Protocols.size();
2111  }
2112  /// isObjCQualifiedIdType - true for "id <p>".
2113  bool isObjCQualifiedIdType() const {
2114    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) &&
2115           Protocols.size();
2116  }
2117  /// isObjCQualifiedClassType - true for "Class <p>".
2118  bool isObjCQualifiedClassType() const {
2119    return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) &&
2120           Protocols.size();
2121  }
2122  /// qual_iterator and friends: this provides access to the (potentially empty)
2123  /// list of protocols qualifying this interface.
2124  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
2125
2126  qual_iterator qual_begin() const { return Protocols.begin(); }
2127  qual_iterator qual_end() const   { return Protocols.end(); }
2128  bool qual_empty() const { return Protocols.size() == 0; }
2129
2130  /// getNumProtocols - Return the number of qualifying protocols in this
2131  /// interface type, or 0 if there are none.
2132  unsigned getNumProtocols() const { return Protocols.size(); }
2133
2134  void Profile(llvm::FoldingSetNodeID &ID);
2135  static void Profile(llvm::FoldingSetNodeID &ID, QualType T,
2136                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
2137  virtual void getAsStringInternal(std::string &InnerString,
2138                                   const PrintingPolicy &Policy) const;
2139  static bool classof(const Type *T) {
2140    return T->getTypeClass() == ObjCObjectPointer;
2141  }
2142  static bool classof(const ObjCObjectPointerType *) { return true; }
2143};
2144
2145// Inline function definitions.
2146
2147/// getUnqualifiedType - Return the type without any qualifiers.
2148inline QualType QualType::getUnqualifiedType() const {
2149  Type *TP = getTypePtr();
2150  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP))
2151    TP = EXTQT->getBaseType();
2152  return QualType(TP, 0);
2153}
2154
2155/// getAddressSpace - Return the address space of this type.
2156inline unsigned QualType::getAddressSpace() const {
2157  QualType CT = getTypePtr()->getCanonicalTypeInternal();
2158  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2159    return AT->getElementType().getAddressSpace();
2160  if (const RecordType *RT = dyn_cast<RecordType>(CT))
2161    return RT->getAddressSpace();
2162  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT))
2163    return EXTQT->getAddressSpace();
2164  return 0;
2165}
2166
2167/// getObjCGCAttr - Return the gc attribute of this type.
2168inline QualType::GCAttrTypes QualType::getObjCGCAttr() const {
2169  QualType CT = getTypePtr()->getCanonicalTypeInternal();
2170  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
2171      return AT->getElementType().getObjCGCAttr();
2172  if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT))
2173    return EXTQT->getObjCGCAttr();
2174  if (const ObjCObjectPointerType *PT = CT->getAsObjCObjectPointerType())
2175    return PT->getPointeeType().getObjCGCAttr();
2176  return GCNone;
2177}
2178
2179  /// getNoReturnAttr - Returns true if the type has the noreturn attribute,
2180  /// false otherwise.
2181inline bool QualType::getNoReturnAttr() const {
2182  QualType CT = getTypePtr()->getCanonicalTypeInternal();
2183  if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) {
2184    if (const FunctionType *FT = PT->getPointeeType()->getAsFunctionType())
2185      return FT->getNoReturnAttr();
2186  } else if (const FunctionType *FT = getTypePtr()->getAsFunctionType())
2187    return FT->getNoReturnAttr();
2188
2189  return false;
2190}
2191
2192/// isMoreQualifiedThan - Determine whether this type is more
2193/// qualified than the Other type. For example, "const volatile int"
2194/// is more qualified than "const int", "volatile int", and
2195/// "int". However, it is not more qualified than "const volatile
2196/// int".
2197inline bool QualType::isMoreQualifiedThan(QualType Other) const {
2198  unsigned MyQuals = this->getCVRQualifiers();
2199  unsigned OtherQuals = Other.getCVRQualifiers();
2200  if (getAddressSpace() != Other.getAddressSpace())
2201    return false;
2202  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
2203}
2204
2205/// isAtLeastAsQualifiedAs - Determine whether this type is at last
2206/// as qualified as the Other type. For example, "const volatile
2207/// int" is at least as qualified as "const int", "volatile int",
2208/// "int", and "const volatile int".
2209inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
2210  unsigned MyQuals = this->getCVRQualifiers();
2211  unsigned OtherQuals = Other.getCVRQualifiers();
2212  if (getAddressSpace() != Other.getAddressSpace())
2213    return false;
2214  return (MyQuals | OtherQuals) == MyQuals;
2215}
2216
2217/// getNonReferenceType - If Type is a reference type (e.g., const
2218/// int&), returns the type that the reference refers to ("const
2219/// int"). Otherwise, returns the type itself. This routine is used
2220/// throughout Sema to implement C++ 5p6:
2221///
2222///   If an expression initially has the type "reference to T" (8.3.2,
2223///   8.5.3), the type is adjusted to "T" prior to any further
2224///   analysis, the expression designates the object or function
2225///   denoted by the reference, and the expression is an lvalue.
2226inline QualType QualType::getNonReferenceType() const {
2227  if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>())
2228    return RefType->getPointeeType();
2229  else
2230    return *this;
2231}
2232
2233inline const TypedefType* Type::getAsTypedefType() const {
2234  return dyn_cast<TypedefType>(this);
2235}
2236inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
2237  if (const PointerType *PT = getAs<PointerType>())
2238    return PT->getPointeeType()->getAsObjCInterfaceType();
2239  return 0;
2240}
2241
2242// NOTE: All of these methods use "getUnqualifiedType" to strip off address
2243// space qualifiers if present.
2244inline bool Type::isFunctionType() const {
2245  return isa<FunctionType>(CanonicalType.getUnqualifiedType());
2246}
2247inline bool Type::isPointerType() const {
2248  return isa<PointerType>(CanonicalType.getUnqualifiedType());
2249}
2250inline bool Type::isAnyPointerType() const {
2251  return isPointerType() || isObjCObjectPointerType();
2252}
2253inline bool Type::isBlockPointerType() const {
2254  return isa<BlockPointerType>(CanonicalType.getUnqualifiedType());
2255}
2256inline bool Type::isReferenceType() const {
2257  return isa<ReferenceType>(CanonicalType.getUnqualifiedType());
2258}
2259inline bool Type::isLValueReferenceType() const {
2260  return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType());
2261}
2262inline bool Type::isRValueReferenceType() const {
2263  return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType());
2264}
2265inline bool Type::isFunctionPointerType() const {
2266  if (const PointerType* T = getAs<PointerType>())
2267    return T->getPointeeType()->isFunctionType();
2268  else
2269    return false;
2270}
2271inline bool Type::isMemberPointerType() const {
2272  return isa<MemberPointerType>(CanonicalType.getUnqualifiedType());
2273}
2274inline bool Type::isMemberFunctionPointerType() const {
2275  if (const MemberPointerType* T = getAs<MemberPointerType>())
2276    return T->getPointeeType()->isFunctionType();
2277  else
2278    return false;
2279}
2280inline bool Type::isArrayType() const {
2281  return isa<ArrayType>(CanonicalType.getUnqualifiedType());
2282}
2283inline bool Type::isConstantArrayType() const {
2284  return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType());
2285}
2286inline bool Type::isIncompleteArrayType() const {
2287  return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType());
2288}
2289inline bool Type::isVariableArrayType() const {
2290  return isa<VariableArrayType>(CanonicalType.getUnqualifiedType());
2291}
2292inline bool Type::isDependentSizedArrayType() const {
2293  return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType());
2294}
2295inline bool Type::isRecordType() const {
2296  return isa<RecordType>(CanonicalType.getUnqualifiedType());
2297}
2298inline bool Type::isAnyComplexType() const {
2299  return isa<ComplexType>(CanonicalType.getUnqualifiedType());
2300}
2301inline bool Type::isVectorType() const {
2302  return isa<VectorType>(CanonicalType.getUnqualifiedType());
2303}
2304inline bool Type::isExtVectorType() const {
2305  return isa<ExtVectorType>(CanonicalType.getUnqualifiedType());
2306}
2307inline bool Type::isObjCObjectPointerType() const {
2308  return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType());
2309}
2310inline bool Type::isObjCInterfaceType() const {
2311  return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
2312}
2313inline bool Type::isObjCQualifiedIdType() const {
2314  if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType())
2315    return OPT->isObjCQualifiedIdType();
2316  return false;
2317}
2318inline bool Type::isObjCQualifiedClassType() const {
2319  if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType())
2320    return OPT->isObjCQualifiedClassType();
2321  return false;
2322}
2323inline bool Type::isObjCIdType() const {
2324  if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType())
2325    return OPT->isObjCIdType();
2326  return false;
2327}
2328inline bool Type::isObjCClassType() const {
2329  if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType())
2330    return OPT->isObjCClassType();
2331  return false;
2332}
2333inline bool Type::isObjCBuiltinType() const {
2334  return isObjCIdType() || isObjCClassType();
2335}
2336inline bool Type::isTemplateTypeParmType() const {
2337  return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType());
2338}
2339
2340inline bool Type::isSpecificBuiltinType(unsigned K) const {
2341  if (const BuiltinType *BT = getAsBuiltinType())
2342    if (BT->getKind() == (BuiltinType::Kind) K)
2343      return true;
2344  return false;
2345}
2346
2347/// \brief Determines whether this is a type for which one can define
2348/// an overloaded operator.
2349inline bool Type::isOverloadableType() const {
2350  return isDependentType() || isRecordType() || isEnumeralType();
2351}
2352
2353inline bool Type::hasPointerRepresentation() const {
2354  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
2355          isObjCInterfaceType() || isObjCObjectPointerType() ||
2356          isObjCQualifiedInterfaceType() || isNullPtrType());
2357}
2358
2359inline bool Type::hasObjCPointerRepresentation() const {
2360  return (isObjCInterfaceType() || isObjCObjectPointerType() ||
2361          isObjCQualifiedInterfaceType());
2362}
2363
2364/// Insertion operator for diagnostics.  This allows sending QualType's into a
2365/// diagnostic with <<.
2366inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
2367                                           QualType T) {
2368  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
2369                  Diagnostic::ak_qualtype);
2370  return DB;
2371}
2372
2373/// Member-template getAs<specific type>'.
2374template <typename T> const T *Type::getAs() const {
2375  // If this is directly a T type, return it.
2376  if (const T *Ty = dyn_cast<T>(this))
2377    return Ty;
2378
2379  // If the canonical form of this type isn't the right kind, reject it.
2380  if (!isa<T>(CanonicalType)) {
2381    // Look through type qualifiers
2382    if (isa<T>(CanonicalType.getUnqualifiedType()))
2383      return CanonicalType.getUnqualifiedType()->getAs<T>();
2384    return 0;
2385  }
2386
2387  // If this is a typedef for a pointer type, strip the typedef off without
2388  // losing all typedef information.
2389  return cast<T>(getDesugaredType());
2390}
2391
2392}  // end namespace clang
2393
2394#endif
2395