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