Type.h revision 8e6563ba097732dc1fffcfc85f8dbbceac899a80
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 "llvm/Support/Casting.h"
19#include "llvm/ADT/APSInt.h"
20#include "llvm/ADT/FoldingSet.h"
21#include "llvm/ADT/PointerIntPair.h"
22#include "llvm/Bitcode/SerializationFwd.h"
23using llvm::isa;
24using llvm::cast;
25using llvm::cast_or_null;
26using llvm::dyn_cast;
27using llvm::dyn_cast_or_null;
28
29namespace clang {
30  class ASTContext;
31  class Type;
32  class TypedefDecl;
33  class TemplateDecl;
34  class TemplateTypeParmDecl;
35  class NonTypeTemplateParmDecl;
36  class TemplateTemplateParamDecl;
37  class TagDecl;
38  class RecordDecl;
39  class CXXRecordDecl;
40  class EnumDecl;
41  class FieldDecl;
42  class ObjCInterfaceDecl;
43  class ObjCProtocolDecl;
44  class ObjCMethodDecl;
45  class Expr;
46  class Stmt;
47  class SourceLocation;
48  class PointerLikeType;
49  class PointerType;
50  class BlockPointerType;
51  class ReferenceType;
52  class MemberPointerType;
53  class VectorType;
54  class ArrayType;
55  class ConstantArrayType;
56  class VariableArrayType;
57  class IncompleteArrayType;
58  class DependentSizedArrayType;
59  class RecordType;
60  class EnumType;
61  class ComplexType;
62  class TagType;
63  class TypedefType;
64  class TemplateTypeParmType;
65  class FunctionType;
66  class FunctionTypeProto;
67  class ExtVectorType;
68  class BuiltinType;
69  class ObjCInterfaceType;
70  class ObjCQualifiedIdType;
71  class ObjCQualifiedInterfaceType;
72  class StmtIteratorBase;
73  class ClassTemplateSpecializationType;
74
75/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
76/// their own: instead each reference to a type stores the qualifiers.  This
77/// greatly reduces the number of nodes we need to allocate for types (for
78/// example we only need one for 'int', 'const int', 'volatile int',
79/// 'const volatile int', etc).
80///
81/// As an added efficiency bonus, instead of making this a pair, we just store
82/// the three bits we care about in the low bits of the pointer.  To handle the
83/// packing/unpacking, we make QualType be a simple wrapper class that acts like
84/// a smart pointer.
85class QualType {
86  llvm::PointerIntPair<Type*, 3> Value;
87public:
88  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
89    Const    = 0x1,
90    Restrict = 0x2,
91    Volatile = 0x4,
92    CVRFlags = Const|Restrict|Volatile
93  };
94
95  QualType() {}
96
97  QualType(const Type *Ptr, unsigned Quals)
98    : Value(const_cast<Type*>(Ptr), Quals) {}
99
100  unsigned getCVRQualifiers() const { return Value.getInt(); }
101  void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); }
102  Type *getTypePtr() const { return Value.getPointer(); }
103
104  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
105  static QualType getFromOpaquePtr(void *Ptr) {
106    QualType T;
107    T.Value.setFromOpaqueValue(Ptr);
108    return T;
109  }
110
111  Type &operator*() const {
112    return *getTypePtr();
113  }
114
115  Type *operator->() const {
116    return getTypePtr();
117  }
118
119  /// isNull - Return true if this QualType doesn't point to a type yet.
120  bool isNull() const {
121    return getTypePtr() == 0;
122  }
123
124  bool isConstQualified() const {
125    return (getCVRQualifiers() & Const) ? true : false;
126  }
127  bool isVolatileQualified() const {
128    return (getCVRQualifiers() & Volatile) ? true : false;
129  }
130  bool isRestrictQualified() const {
131    return (getCVRQualifiers() & Restrict) ? true : false;
132  }
133
134  bool isConstant(ASTContext& Ctx) const;
135
136  /// addConst/addVolatile/addRestrict - add the specified type qual to this
137  /// QualType.
138  void addConst()    { Value.setInt(Value.getInt() | Const); }
139  void addVolatile() { Value.setInt(Value.getInt() | Volatile); }
140  void addRestrict() { Value.setInt(Value.getInt() | Restrict); }
141
142  void removeConst()    { Value.setInt(Value.getInt() & ~Const); }
143  void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); }
144  void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); }
145
146  QualType getQualifiedType(unsigned TQs) const {
147    return QualType(getTypePtr(), TQs);
148  }
149  QualType getWithAdditionalQualifiers(unsigned TQs) const {
150    return QualType(getTypePtr(), TQs|getCVRQualifiers());
151  }
152
153  QualType withConst() const { return getWithAdditionalQualifiers(Const); }
154  QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);}
155  QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);}
156
157  QualType getUnqualifiedType() const;
158  bool isMoreQualifiedThan(QualType Other) const;
159  bool isAtLeastAsQualifiedAs(QualType Other) const;
160  QualType getNonReferenceType() const;
161
162
163  /// operator==/!= - Indicate whether the specified types and qualifiers are
164  /// identical.
165  bool operator==(const QualType &RHS) const {
166    return Value == RHS.Value;
167  }
168  bool operator!=(const QualType &RHS) const {
169    return Value != RHS.Value;
170  }
171  std::string getAsString() const {
172    std::string S;
173    getAsStringInternal(S);
174    return S;
175  }
176  void getAsStringInternal(std::string &Str) const;
177
178  void dump(const char *s) const;
179  void dump() const;
180
181  void Profile(llvm::FoldingSetNodeID &ID) const {
182    ID.AddPointer(getAsOpaquePtr());
183  }
184
185public:
186
187  /// getAddressSpace - Return the address space of this type.
188  inline unsigned getAddressSpace() const;
189
190  /// Emit - Serialize a QualType to Bitcode.
191  void Emit(llvm::Serializer& S) const;
192
193  /// Read - Deserialize a QualType from Bitcode.
194  static QualType ReadVal(llvm::Deserializer& D);
195
196  void ReadBackpatch(llvm::Deserializer& D);
197};
198
199} // end clang.
200
201namespace llvm {
202/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
203/// to a specific Type class.
204template<> struct simplify_type<const ::clang::QualType> {
205  typedef ::clang::Type* SimpleType;
206  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
207    return Val.getTypePtr();
208  }
209};
210template<> struct simplify_type< ::clang::QualType>
211  : public simplify_type<const ::clang::QualType> {};
212
213} // end namespace llvm
214
215namespace clang {
216
217/// Type - This is the base class of the type hierarchy.  A central concept
218/// with types is that each type always has a canonical type.  A canonical type
219/// is the type with any typedef names stripped out of it or the types it
220/// references.  For example, consider:
221///
222///  typedef int  foo;
223///  typedef foo* bar;
224///    'int *'    'foo *'    'bar'
225///
226/// There will be a Type object created for 'int'.  Since int is canonical, its
227/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
228/// TypeNameType).  Its CanonicalType pointer points to the 'int' Type.  Next
229/// there is a PointerType that represents 'int*', which, like 'int', is
230/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
231/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type
232/// is also 'int*'.
233///
234/// Non-canonical types are useful for emitting diagnostics, without losing
235/// information about typedefs being used.  Canonical types are useful for type
236/// comparisons (they allow by-pointer equality tests) and useful for reasoning
237/// about whether something has a particular form (e.g. is a function type),
238/// because they implicitly, recursively, strip all typedefs out of a type.
239///
240/// Types, once created, are immutable.
241///
242class Type {
243public:
244  enum TypeClass {
245    Builtin, Complex, Pointer, Reference, MemberPointer,
246    ConstantArray, VariableArray, IncompleteArray, DependentSizedArray,
247    Vector, ExtVector,
248    FunctionNoProto, FunctionProto,
249    TypeName, Tagged, ASQual,
250    TemplateTypeParm, ClassTemplateSpecialization,
251    ObjCInterface, ObjCQualifiedInterface,
252    ObjCQualifiedId,
253    TypeOfExp, TypeOfTyp, // GNU typeof extension.
254    BlockPointer          // C extension
255  };
256private:
257  QualType CanonicalType;
258
259  /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]).
260  bool Dependent : 1;
261
262  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
263  /// Note that this should stay at the end of the ivars for Type so that
264  /// subclasses can pack their bitfields into the same word.
265  unsigned TC : 5;
266
267protected:
268  // silence VC++ warning C4355: 'this' : used in base member initializer list
269  Type *this_() { return this; }
270  Type(TypeClass tc, QualType Canonical, bool dependent)
271    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
272      Dependent(dependent), TC(tc) {}
273  virtual ~Type() {}
274  virtual void Destroy(ASTContext& C);
275  friend class ASTContext;
276
277  void EmitTypeInternal(llvm::Serializer& S) const;
278  void ReadTypeInternal(llvm::Deserializer& D);
279
280public:
281  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
282
283  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
284
285  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
286  /// object types, function types, and incomplete types.
287
288  /// isObjectType - types that fully describe objects. An object is a region
289  /// of memory that can be examined and stored into (H&S).
290  bool isObjectType() const;
291
292  /// isIncompleteType - Return true if this is an incomplete type.
293  /// A type that can describe objects, but which lacks information needed to
294  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
295  /// routine will need to determine if the size is actually required.
296  bool isIncompleteType() const;
297
298  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
299  /// type, in other words, not a function type.
300  bool isIncompleteOrObjectType() const {
301    return !isFunctionType();
302  }
303
304  /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10).
305  bool isPODType() const;
306
307  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
308  /// types that have a non-constant expression. This does not include "[]".
309  bool isVariablyModifiedType() const;
310
311  /// Helper methods to distinguish type categories. All type predicates
312  /// operate on the canonical type, ignoring typedefs and qualifiers.
313
314  /// isIntegerType() does *not* include complex integers (a GCC extension).
315  /// isComplexIntegerType() can be used to test for complex integers.
316  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
317  bool isEnumeralType() const;
318  bool isBooleanType() const;
319  bool isCharType() const;
320  bool isWideCharType() const;
321  bool isIntegralType() const;
322
323  /// Floating point categories.
324  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
325  /// isComplexType() does *not* include complex integers (a GCC extension).
326  /// isComplexIntegerType() can be used to test for complex integers.
327  bool isComplexType() const;      // C99 6.2.5p11 (complex)
328  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
329  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
330  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
331  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
332  bool isVoidType() const;         // C99 6.2.5p19
333  bool isDerivedType() const;      // C99 6.2.5p20
334  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
335  bool isAggregateType() const;
336
337  // Type Predicates: Check to see if this type is structurally the specified
338  // type, ignoring typedefs and qualifiers.
339  bool isFunctionType() const;
340  bool isPointerLikeType() const; // Pointer or Reference.
341  bool isPointerType() const;
342  bool isBlockPointerType() const;
343  bool isReferenceType() const;
344  bool isFunctionPointerType() const;
345  bool isMemberPointerType() const;
346  bool isMemberFunctionPointerType() const;
347  bool isArrayType() const;
348  bool isConstantArrayType() const;
349  bool isIncompleteArrayType() const;
350  bool isVariableArrayType() const;
351  bool isDependentSizedArrayType() const;
352  bool isRecordType() const;
353  bool isClassType() const;
354  bool isStructureType() const;
355  bool isUnionType() const;
356  bool isComplexIntegerType() const;            // GCC _Complex integer type.
357  bool isVectorType() const;                    // GCC vector type.
358  bool isExtVectorType() const;                 // Extended vector type.
359  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
360  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
361  bool isObjCQualifiedIdType() const;           // id<foo>
362  bool isTemplateTypeParmType() const;          // C++ template type parameter
363
364  /// isDependentType - Whether this type is a dependent type, meaning
365  /// that its definition somehow depends on a template parameter
366  /// (C++ [temp.dep.type]).
367  bool isDependentType() const { return Dependent; }
368  bool isOverloadType() const;                  // C++ overloaded function
369
370  // Type Checking Functions: Check to see if this type is structurally the
371  // specified type, ignoring typedefs and qualifiers, and return a pointer to
372  // the best type we can.
373  const BuiltinType *getAsBuiltinType() const;
374  const FunctionType *getAsFunctionType() const;
375  const FunctionTypeProto *getAsFunctionTypeProto() const;
376  const PointerLikeType *getAsPointerLikeType() const; // Pointer or Reference.
377  const PointerType *getAsPointerType() const;
378  const BlockPointerType *getAsBlockPointerType() const;
379  const ReferenceType *getAsReferenceType() const;
380  const MemberPointerType *getAsMemberPointerType() const;
381  const RecordType *getAsRecordType() const;
382  const RecordType *getAsStructureType() const;
383  /// NOTE: getAs*ArrayType are methods on ASTContext.
384  const TypedefType *getAsTypedefType() const;
385  const RecordType *getAsUnionType() const;
386  const EnumType *getAsEnumType() const;
387  const VectorType *getAsVectorType() const; // GCC vector type.
388  const ComplexType *getAsComplexType() const;
389  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
390  const ExtVectorType *getAsExtVectorType() const; // Extended vector type.
391  const ObjCInterfaceType *getAsObjCInterfaceType() const;
392  const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const;
393  const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const;
394  const TemplateTypeParmType *getAsTemplateTypeParmType() const;
395
396  const ClassTemplateSpecializationType *
397    getClassTemplateSpecializationType() const;
398
399  /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
400  /// interface, return the interface type, otherwise return null.
401  const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
402
403  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
404  /// element type of the array, potentially with type qualifiers missing.
405  /// This method should never be used when type qualifiers are meaningful.
406  const Type *getArrayElementTypeNoTypeQual() const;
407
408  /// getDesugaredType - Return the specified type with any "sugar" removed from
409  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
410  /// the type is already concrete, it returns it unmodified.  This is similar
411  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
412  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
413  /// concrete.
414  QualType getDesugaredType() const;
415
416  /// More type predicates useful for type checking/promotion
417  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
418
419  /// isSignedIntegerType - Return true if this is an integer type that is
420  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
421  /// an enum decl which has a signed representation, or a vector of signed
422  /// integer element type.
423  bool isSignedIntegerType() const;
424
425  /// isUnsignedIntegerType - Return true if this is an integer type that is
426  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
427  /// decl which has an unsigned representation, or a vector of unsigned integer
428  /// element type.
429  bool isUnsignedIntegerType() const;
430
431  /// isConstantSizeType - Return true if this is not a variable sized type,
432  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
433  /// incomplete types.
434  bool isConstantSizeType() const;
435
436  QualType getCanonicalTypeInternal() const { return CanonicalType; }
437  void dump() const;
438  virtual void getAsStringInternal(std::string &InnerString) const = 0;
439  static bool classof(const Type *) { return true; }
440
441protected:
442  /// Emit - Emit a Type to bitcode.  Used by ASTContext.
443  void Emit(llvm::Serializer& S) const;
444
445  /// Create - Construct a Type from bitcode.  Used by ASTContext.
446  static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S);
447
448  /// EmitImpl - Subclasses must implement this method in order to
449  ///  be serialized.
450  // FIXME: Make this abstract once implemented.
451  virtual void EmitImpl(llvm::Serializer& S) const {
452    assert (false && "Serializization for type not supported.");
453  }
454};
455
456/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26
457/// This supports address space qualified types.
458///
459class ASQualType : public Type, public llvm::FoldingSetNode {
460  /// BaseType - This is the underlying type that this qualifies.  All CVR
461  /// qualifiers are stored on the QualType that references this type, so we
462  /// can't have any here.
463  Type *BaseType;
464  /// Address Space ID - The address space ID this type is qualified with.
465  unsigned AddressSpace;
466  ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) :
467    Type(ASQual, CanonicalPtr, Base->isDependentType()), BaseType(Base),
468    AddressSpace(AddrSpace) {
469  }
470  friend class ASTContext;  // ASTContext creates these.
471public:
472  Type *getBaseType() const { return BaseType; }
473  unsigned getAddressSpace() const { return AddressSpace; }
474
475  virtual void getAsStringInternal(std::string &InnerString) const;
476
477  void Profile(llvm::FoldingSetNodeID &ID) {
478    Profile(ID, getBaseType(), AddressSpace);
479  }
480  static void Profile(llvm::FoldingSetNodeID &ID, Type *Base,
481                      unsigned AddrSpace) {
482    ID.AddPointer(Base);
483    ID.AddInteger(AddrSpace);
484  }
485
486  static bool classof(const Type *T) { return T->getTypeClass() == ASQual; }
487  static bool classof(const ASQualType *) { return true; }
488
489protected:
490  virtual void EmitImpl(llvm::Serializer& S) const;
491  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
492  friend class Type;
493};
494
495
496/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
497/// types are always canonical and have a literal name field.
498class BuiltinType : public Type {
499public:
500  enum Kind {
501    Void,
502
503    Bool,     // This is bool and/or _Bool.
504    Char_U,   // This is 'char' for targets where char is unsigned.
505    UChar,    // This is explicitly qualified unsigned char.
506    UShort,
507    UInt,
508    ULong,
509    ULongLong,
510
511    Char_S,   // This is 'char' for targets where char is signed.
512    SChar,    // This is explicitly qualified signed char.
513    WChar,    // This is 'wchar_t' for C++.
514    Short,
515    Int,
516    Long,
517    LongLong,
518
519    Float, Double, LongDouble,
520
521    Overload,  // This represents the type of an overloaded function declaration.
522    Dependent  // This represents the type of a type-dependent expression.
523  };
524private:
525  Kind TypeKind;
526public:
527  BuiltinType(Kind K)
528    : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)),
529      TypeKind(K) {}
530
531  Kind getKind() const { return TypeKind; }
532  const char *getName() const;
533
534  virtual void getAsStringInternal(std::string &InnerString) const;
535
536  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
537  static bool classof(const BuiltinType *) { return true; }
538};
539
540/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
541/// types (_Complex float etc) as well as the GCC integer complex extensions.
542///
543class ComplexType : public Type, public llvm::FoldingSetNode {
544  QualType ElementType;
545  ComplexType(QualType Element, QualType CanonicalPtr) :
546    Type(Complex, CanonicalPtr, Element->isDependentType()),
547    ElementType(Element) {
548  }
549  friend class ASTContext;  // ASTContext creates these.
550public:
551  QualType getElementType() const { return ElementType; }
552
553  virtual void getAsStringInternal(std::string &InnerString) const;
554
555  void Profile(llvm::FoldingSetNodeID &ID) {
556    Profile(ID, getElementType());
557  }
558  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
559    ID.AddPointer(Element.getAsOpaquePtr());
560  }
561
562  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
563  static bool classof(const ComplexType *) { return true; }
564
565protected:
566  virtual void EmitImpl(llvm::Serializer& S) const;
567  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
568  friend class Type;
569};
570
571/// PointerLikeType - Common base class for pointers and references.
572/// FIXME: Add more documentation on this classes design point. For example,
573/// should BlockPointerType inherit from it? Is the concept of a PointerLikeType
574/// in the C++ standard?
575///
576class PointerLikeType : public Type {
577  QualType PointeeType;
578protected:
579  PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) :
580    Type(K, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) {
581  }
582public:
583
584  QualType getPointeeType() const { return PointeeType; }
585
586  static bool classof(const Type *T) {
587    return T->getTypeClass() == Pointer || T->getTypeClass() == Reference;
588  }
589  static bool classof(const PointerLikeType *) { return true; }
590};
591
592/// PointerType - C99 6.7.5.1 - Pointer Declarators.
593///
594class PointerType : public PointerLikeType, public llvm::FoldingSetNode {
595  PointerType(QualType Pointee, QualType CanonicalPtr) :
596    PointerLikeType(Pointer, Pointee, CanonicalPtr) {
597  }
598  friend class ASTContext;  // ASTContext creates these.
599public:
600
601  virtual void getAsStringInternal(std::string &InnerString) const;
602
603  void Profile(llvm::FoldingSetNodeID &ID) {
604    Profile(ID, getPointeeType());
605  }
606  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
607    ID.AddPointer(Pointee.getAsOpaquePtr());
608  }
609
610  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
611  static bool classof(const PointerType *) { return true; }
612
613protected:
614  virtual void EmitImpl(llvm::Serializer& S) const;
615  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
616  friend class Type;
617};
618
619/// BlockPointerType - pointer to a block type.
620/// This type is to represent types syntactically represented as
621/// "void (^)(int)", etc. Pointee is required to always be a function type.
622/// FIXME: Should BlockPointerType inherit from PointerLikeType? It could
623/// simplfy some type checking code, however PointerLikeType doesn't appear
624/// to be used by the type checker.
625///
626class BlockPointerType : public Type, public llvm::FoldingSetNode {
627  QualType PointeeType;  // Block is some kind of pointer type
628  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
629    Type(BlockPointer, CanonicalCls, Pointee->isDependentType()),
630    PointeeType(Pointee) {
631  }
632  friend class ASTContext;  // ASTContext creates these.
633public:
634
635  // Get the pointee type. Pointee is required to always be a function type.
636  QualType getPointeeType() const { return PointeeType; }
637
638  virtual void getAsStringInternal(std::string &InnerString) const;
639
640  void Profile(llvm::FoldingSetNodeID &ID) {
641      Profile(ID, getPointeeType());
642  }
643  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
644      ID.AddPointer(Pointee.getAsOpaquePtr());
645  }
646
647  static bool classof(const Type *T) {
648    return T->getTypeClass() == BlockPointer;
649  }
650  static bool classof(const BlockPointerType *) { return true; }
651
652  protected:
653    virtual void EmitImpl(llvm::Serializer& S) const;
654    static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
655    friend class Type;
656};
657
658/// ReferenceType - C++ 8.3.2 - Reference Declarators.
659///
660class ReferenceType : public PointerLikeType, public llvm::FoldingSetNode {
661  ReferenceType(QualType Referencee, QualType CanonicalRef) :
662    PointerLikeType(Reference, Referencee, CanonicalRef) {
663  }
664  friend class ASTContext;  // ASTContext creates these.
665public:
666  virtual void getAsStringInternal(std::string &InnerString) const;
667
668  void Profile(llvm::FoldingSetNodeID &ID) {
669    Profile(ID, getPointeeType());
670  }
671  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
672    ID.AddPointer(Referencee.getAsOpaquePtr());
673  }
674
675  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
676  static bool classof(const ReferenceType *) { return true; }
677
678protected:
679  virtual void EmitImpl(llvm::Serializer& S) const;
680  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
681  friend class Type;
682};
683
684/// MemberPointerType - C++ 8.3.3 - Pointers to members
685///
686class MemberPointerType : public Type, public llvm::FoldingSetNode {
687  QualType PointeeType;
688  /// The class of which the pointee is a member. Must ultimately be a
689  /// RecordType, but could be a typedef or a template parameter too.
690  const Type *Class;
691
692  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) :
693    Type(MemberPointer, CanonicalPtr,
694         Cls->isDependentType() || Pointee->isDependentType()),
695    PointeeType(Pointee), Class(Cls) {
696  }
697  friend class ASTContext; // ASTContext creates these.
698public:
699
700  QualType getPointeeType() const { return PointeeType; }
701
702  const Type *getClass() const { return Class; }
703
704  virtual void getAsStringInternal(std::string &InnerString) const;
705
706  void Profile(llvm::FoldingSetNodeID &ID) {
707    Profile(ID, getPointeeType(), getClass());
708  }
709  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
710                      const Type *Class) {
711    ID.AddPointer(Pointee.getAsOpaquePtr());
712    ID.AddPointer(Class);
713  }
714
715  static bool classof(const Type *T) {
716    return T->getTypeClass() == MemberPointer;
717  }
718  static bool classof(const MemberPointerType *) { return true; }
719
720protected:
721  virtual void EmitImpl(llvm::Serializer& S) const;
722  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
723  friend class Type;
724};
725
726/// ArrayType - C99 6.7.5.2 - Array Declarators.
727///
728class ArrayType : public Type, public llvm::FoldingSetNode {
729public:
730  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
731  /// an array with a static size (e.g. int X[static 4]), or an array
732  /// with a star size (e.g. int X[*]).
733  /// 'static' is only allowed on function parameters.
734  enum ArraySizeModifier {
735    Normal, Static, Star
736  };
737private:
738  /// ElementType - The element type of the array.
739  QualType ElementType;
740
741  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
742  /// NOTE: These fields are packed into the bitfields space in the Type class.
743  unsigned SizeModifier : 2;
744
745  /// IndexTypeQuals - Capture qualifiers in declarations like:
746  /// 'int X[static restrict 4]'. For function parameters only.
747  unsigned IndexTypeQuals : 3;
748
749protected:
750  // C++ [temp.dep.type]p1:
751  //   A type is dependent if it is...
752  //     - an array type constructed from any dependent type or whose
753  //       size is specified by a constant expression that is
754  //       value-dependent,
755  ArrayType(TypeClass tc, QualType et, QualType can,
756            ArraySizeModifier sm, unsigned tq)
757    : Type(tc, can, et->isDependentType() || tc == DependentSizedArray),
758      ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
759
760  friend class ASTContext;  // ASTContext creates these.
761public:
762  QualType getElementType() const { return ElementType; }
763  ArraySizeModifier getSizeModifier() const {
764    return ArraySizeModifier(SizeModifier);
765  }
766  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
767
768  static bool classof(const Type *T) {
769    return T->getTypeClass() == ConstantArray ||
770           T->getTypeClass() == VariableArray ||
771           T->getTypeClass() == IncompleteArray ||
772           T->getTypeClass() == DependentSizedArray;
773  }
774  static bool classof(const ArrayType *) { return true; }
775};
776
777/// ConstantArrayType - This class represents C arrays with a specified constant
778/// size.  For example 'int A[100]' has ConstantArrayType where the element type
779/// is 'int' and the size is 100.
780class ConstantArrayType : public ArrayType {
781  llvm::APInt Size; // Allows us to unique the type.
782
783  ConstantArrayType(QualType et, QualType can, llvm::APInt sz,
784                    ArraySizeModifier sm, unsigned tq)
785    : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {}
786  friend class ASTContext;  // ASTContext creates these.
787public:
788  const llvm::APInt &getSize() const { return Size; }
789  virtual void getAsStringInternal(std::string &InnerString) const;
790
791  void Profile(llvm::FoldingSetNodeID &ID) {
792    Profile(ID, getElementType(), getSize());
793  }
794  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
795                      llvm::APInt ArraySize) {
796    ID.AddPointer(ET.getAsOpaquePtr());
797    ID.AddInteger(ArraySize.getZExtValue());
798  }
799  static bool classof(const Type *T) {
800    return T->getTypeClass() == ConstantArray;
801  }
802  static bool classof(const ConstantArrayType *) { return true; }
803
804protected:
805  virtual void EmitImpl(llvm::Serializer& S) const;
806  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
807  friend class Type;
808};
809
810/// IncompleteArrayType - This class represents C arrays with an unspecified
811/// size.  For example 'int A[]' has an IncompleteArrayType where the element
812/// type is 'int' and the size is unspecified.
813class IncompleteArrayType : public ArrayType {
814  IncompleteArrayType(QualType et, QualType can,
815                    ArraySizeModifier sm, unsigned tq)
816    : ArrayType(IncompleteArray, et, can, sm, tq) {}
817  friend class ASTContext;  // ASTContext creates these.
818public:
819
820  virtual void getAsStringInternal(std::string &InnerString) const;
821
822  static bool classof(const Type *T) {
823    return T->getTypeClass() == IncompleteArray;
824  }
825  static bool classof(const IncompleteArrayType *) { return true; }
826
827  friend class StmtIteratorBase;
828
829  void Profile(llvm::FoldingSetNodeID &ID) {
830    Profile(ID, getElementType());
831  }
832
833  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) {
834    ID.AddPointer(ET.getAsOpaquePtr());
835  }
836
837protected:
838  virtual void EmitImpl(llvm::Serializer& S) const;
839  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
840  friend class Type;
841};
842
843/// VariableArrayType - This class represents C arrays with a specified size
844/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
845/// Since the size expression is an arbitrary expression, we store it as such.
846///
847/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
848/// should not be: two lexically equivalent variable array types could mean
849/// different things, for example, these variables do not have the same type
850/// dynamically:
851///
852/// void foo(int x) {
853///   int Y[x];
854///   ++x;
855///   int Z[x];
856/// }
857///
858class VariableArrayType : public ArrayType {
859  /// SizeExpr - An assignment expression. VLA's are only permitted within
860  /// a function block.
861  Stmt *SizeExpr;
862
863  VariableArrayType(QualType et, QualType can, Expr *e,
864                    ArraySizeModifier sm, unsigned tq)
865    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
866  friend class ASTContext;  // ASTContext creates these.
867  virtual void Destroy(ASTContext& C);
868
869public:
870  Expr *getSizeExpr() const {
871    // We use C-style casts instead of cast<> here because we do not wish
872    // to have a dependency of Type.h on Stmt.h/Expr.h.
873    return (Expr*) SizeExpr;
874  }
875
876  virtual void getAsStringInternal(std::string &InnerString) const;
877
878  static bool classof(const Type *T) {
879    return T->getTypeClass() == VariableArray;
880  }
881  static bool classof(const VariableArrayType *) { return true; }
882
883  friend class StmtIteratorBase;
884
885  void Profile(llvm::FoldingSetNodeID &ID) {
886    assert (0 && "Cannnot unique VariableArrayTypes.");
887  }
888
889protected:
890  virtual void EmitImpl(llvm::Serializer& S) const;
891  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
892  friend class Type;
893};
894
895/// DependentSizedArrayType - This type represents an array type in
896/// C++ whose size is a value-dependent expression. For example:
897/// @code
898/// template<typename T, int Size>
899/// class array {
900///   T data[Size];
901/// };
902/// @endcode
903/// For these types, we won't actually know what the array bound is
904/// until template instantiation occurs, at which point this will
905/// become either a ConstantArrayType or a VariableArrayType.
906class DependentSizedArrayType : public ArrayType {
907  /// SizeExpr - An assignment expression that will instantiate to the
908  /// size of the array.
909  Stmt *SizeExpr;
910
911  DependentSizedArrayType(QualType et, QualType can, Expr *e,
912			  ArraySizeModifier sm, unsigned tq)
913    : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
914  friend class ASTContext;  // ASTContext creates these.
915  virtual void Destroy(ASTContext& C);
916
917public:
918  Expr *getSizeExpr() const {
919    // We use C-style casts instead of cast<> here because we do not wish
920    // to have a dependency of Type.h on Stmt.h/Expr.h.
921    return (Expr*) SizeExpr;
922  }
923
924  virtual void getAsStringInternal(std::string &InnerString) const;
925
926  static bool classof(const Type *T) {
927    return T->getTypeClass() == DependentSizedArray;
928  }
929  static bool classof(const DependentSizedArrayType *) { return true; }
930
931  friend class StmtIteratorBase;
932
933  void Profile(llvm::FoldingSetNodeID &ID) {
934    assert (0 && "Cannnot unique DependentSizedArrayTypes.");
935  }
936
937protected:
938  virtual void EmitImpl(llvm::Serializer& S) const;
939  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
940  friend class Type;
941};
942
943/// VectorType - GCC generic vector type. This type is created using
944/// __attribute__((vector_size(n)), where "n" specifies the vector size in
945/// bytes. Since the constructor takes the number of vector elements, the
946/// client is responsible for converting the size into the number of elements.
947class VectorType : public Type, public llvm::FoldingSetNode {
948protected:
949  /// ElementType - The element type of the vector.
950  QualType ElementType;
951
952  /// NumElements - The number of elements in the vector.
953  unsigned NumElements;
954
955  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
956    Type(Vector, canonType, vecType->isDependentType()),
957    ElementType(vecType), NumElements(nElements) {}
958  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
959             QualType canonType)
960    : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType),
961      NumElements(nElements) {}
962  friend class ASTContext;  // ASTContext creates these.
963public:
964
965  QualType getElementType() const { return ElementType; }
966  unsigned getNumElements() const { return NumElements; }
967
968  virtual void getAsStringInternal(std::string &InnerString) const;
969
970  void Profile(llvm::FoldingSetNodeID &ID) {
971    Profile(ID, getElementType(), getNumElements(), getTypeClass());
972  }
973  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
974                      unsigned NumElements, TypeClass TypeClass) {
975    ID.AddPointer(ElementType.getAsOpaquePtr());
976    ID.AddInteger(NumElements);
977    ID.AddInteger(TypeClass);
978  }
979  static bool classof(const Type *T) {
980    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
981  }
982  static bool classof(const VectorType *) { return true; }
983};
984
985/// ExtVectorType - Extended vector type. This type is created using
986/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
987/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
988/// class enables syntactic extensions, like Vector Components for accessing
989/// points, colors, and textures (modeled after OpenGL Shading Language).
990class ExtVectorType : public VectorType {
991  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
992    VectorType(ExtVector, vecType, nElements, canonType) {}
993  friend class ASTContext;  // ASTContext creates these.
994public:
995  static int getPointAccessorIdx(char c) {
996    switch (c) {
997    default: return -1;
998    case 'x': return 0;
999    case 'y': return 1;
1000    case 'z': return 2;
1001    case 'w': return 3;
1002    }
1003  }
1004  static int getNumericAccessorIdx(char c) {
1005    switch (c) {
1006      default: return -1;
1007      case '0': return 0;
1008      case '1': return 1;
1009      case '2': return 2;
1010      case '3': return 3;
1011      case '4': return 4;
1012      case '5': return 5;
1013      case '6': return 6;
1014      case '7': return 7;
1015      case '8': return 8;
1016      case '9': return 9;
1017      case 'a': return 10;
1018      case 'b': return 11;
1019      case 'c': return 12;
1020      case 'd': return 13;
1021      case 'e': return 14;
1022      case 'f': return 15;
1023    }
1024  }
1025
1026  static int getAccessorIdx(char c) {
1027    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
1028    return getNumericAccessorIdx(c);
1029  }
1030
1031  bool isAccessorWithinNumElements(char c) const {
1032    if (int idx = getAccessorIdx(c)+1)
1033      return unsigned(idx-1) < NumElements;
1034    return false;
1035  }
1036  virtual void getAsStringInternal(std::string &InnerString) const;
1037
1038  static bool classof(const Type *T) {
1039    return T->getTypeClass() == ExtVector;
1040  }
1041  static bool classof(const ExtVectorType *) { return true; }
1042};
1043
1044/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
1045/// class of FunctionTypeNoProto and FunctionTypeProto.
1046///
1047class FunctionType : public Type {
1048  /// SubClassData - This field is owned by the subclass, put here to pack
1049  /// tightly with the ivars in Type.
1050  bool SubClassData : 1;
1051
1052  /// TypeQuals - Used only by FunctionTypeProto, put here to pack with the
1053  /// other bitfields.
1054  /// The qualifiers are part of FunctionTypeProto because...
1055  ///
1056  /// C++ 8.3.5p4: The return type, the parameter type list and the
1057  /// cv-qualifier-seq, [...], are part of the function type.
1058  ///
1059  unsigned TypeQuals : 3;
1060
1061  // The type returned by the function.
1062  QualType ResultType;
1063protected:
1064  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,
1065               unsigned typeQuals, QualType Canonical, bool Dependent)
1066    : Type(tc, Canonical, Dependent),
1067      SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {}
1068  bool getSubClassData() const { return SubClassData; }
1069  unsigned getTypeQuals() const { return TypeQuals; }
1070public:
1071
1072  QualType getResultType() const { return ResultType; }
1073
1074
1075  static bool classof(const Type *T) {
1076    return T->getTypeClass() == FunctionNoProto ||
1077           T->getTypeClass() == FunctionProto;
1078  }
1079  static bool classof(const FunctionType *) { return true; }
1080};
1081
1082/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
1083/// no information available about its arguments.
1084class FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
1085  FunctionTypeNoProto(QualType Result, QualType Canonical)
1086    : FunctionType(FunctionNoProto, Result, false, 0, Canonical,
1087                   /*Dependent=*/false) {}
1088  friend class ASTContext;  // ASTContext creates these.
1089public:
1090  // No additional state past what FunctionType provides.
1091
1092  virtual void getAsStringInternal(std::string &InnerString) const;
1093
1094  void Profile(llvm::FoldingSetNodeID &ID) {
1095    Profile(ID, getResultType());
1096  }
1097  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
1098    ID.AddPointer(ResultType.getAsOpaquePtr());
1099  }
1100
1101  static bool classof(const Type *T) {
1102    return T->getTypeClass() == FunctionNoProto;
1103  }
1104  static bool classof(const FunctionTypeNoProto *) { return true; }
1105
1106protected:
1107  virtual void EmitImpl(llvm::Serializer& S) const;
1108  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1109  friend class Type;
1110};
1111
1112/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
1113/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
1114/// arguments, not as having a single void argument.
1115class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
1116  /// hasAnyDependentType - Determine whether there are any dependent
1117  /// types within the arguments passed in.
1118  static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) {
1119    for (unsigned Idx = 0; Idx < numArgs; ++Idx)
1120      if (ArgArray[Idx]->isDependentType())
1121    return true;
1122
1123    return false;
1124  }
1125
1126  FunctionTypeProto(QualType Result, const QualType *ArgArray, unsigned numArgs,
1127                    bool isVariadic, unsigned typeQuals, QualType Canonical)
1128    : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical,
1129                   (Result->isDependentType() ||
1130                    hasAnyDependentType(ArgArray, numArgs))),
1131      NumArgs(numArgs) {
1132    // Fill in the trailing argument array.
1133    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
1134    for (unsigned i = 0; i != numArgs; ++i)
1135      ArgInfo[i] = ArgArray[i];
1136  }
1137
1138  /// NumArgs - The number of arguments this function has, not counting '...'.
1139  unsigned NumArgs;
1140
1141  /// ArgInfo - There is an variable size array after the class in memory that
1142  /// holds the argument types.
1143
1144  friend class ASTContext;  // ASTContext creates these.
1145
1146public:
1147  unsigned getNumArgs() const { return NumArgs; }
1148  QualType getArgType(unsigned i) const {
1149    assert(i < NumArgs && "Invalid argument number!");
1150    return arg_type_begin()[i];
1151  }
1152
1153  bool isVariadic() const { return getSubClassData(); }
1154  unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); }
1155
1156  typedef const QualType *arg_type_iterator;
1157  arg_type_iterator arg_type_begin() const {
1158    return reinterpret_cast<const QualType *>(this+1);
1159  }
1160  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
1161
1162  virtual void getAsStringInternal(std::string &InnerString) const;
1163
1164  static bool classof(const Type *T) {
1165    return T->getTypeClass() == FunctionProto;
1166  }
1167  static bool classof(const FunctionTypeProto *) { return true; }
1168
1169  void Profile(llvm::FoldingSetNodeID &ID);
1170  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
1171                      arg_type_iterator ArgTys, unsigned NumArgs,
1172                      bool isVariadic, unsigned TypeQuals);
1173
1174protected:
1175  virtual void EmitImpl(llvm::Serializer& S) const;
1176  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1177  friend class Type;
1178};
1179
1180
1181class TypedefType : public Type {
1182  TypedefDecl *Decl;
1183protected:
1184  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
1185    : Type(tc, can, can->isDependentType()), Decl(D) {
1186    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1187  }
1188  friend class ASTContext;  // ASTContext creates these.
1189public:
1190
1191  TypedefDecl *getDecl() const { return Decl; }
1192
1193  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1194  /// potentially looking through *all* consecutive typedefs.  This returns the
1195  /// sum of the type qualifiers, so if you have:
1196  ///   typedef const int A;
1197  ///   typedef volatile A B;
1198  /// looking through the typedefs for B will give you "const volatile A".
1199  QualType LookThroughTypedefs() const;
1200
1201  virtual void getAsStringInternal(std::string &InnerString) const;
1202
1203  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
1204  static bool classof(const TypedefType *) { return true; }
1205
1206protected:
1207  virtual void EmitImpl(llvm::Serializer& S) const;
1208  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1209  friend class Type;
1210};
1211
1212/// TypeOfExpr (GCC extension).
1213class TypeOfExpr : public Type {
1214  Expr *TOExpr;
1215  TypeOfExpr(Expr *E, QualType can);
1216  friend class ASTContext;  // ASTContext creates these.
1217public:
1218  Expr *getUnderlyingExpr() const { return TOExpr; }
1219
1220  virtual void getAsStringInternal(std::string &InnerString) const;
1221
1222  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
1223  static bool classof(const TypeOfExpr *) { return true; }
1224
1225protected:
1226  virtual void EmitImpl(llvm::Serializer& S) const;
1227  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1228  friend class Type;
1229};
1230
1231/// TypeOfType (GCC extension).
1232class TypeOfType : public Type {
1233  QualType TOType;
1234  TypeOfType(QualType T, QualType can)
1235    : Type(TypeOfTyp, can, T->isDependentType()), TOType(T) {
1236    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1237  }
1238  friend class ASTContext;  // ASTContext creates these.
1239public:
1240  QualType getUnderlyingType() const { return TOType; }
1241
1242  virtual void getAsStringInternal(std::string &InnerString) const;
1243
1244  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
1245  static bool classof(const TypeOfType *) { return true; }
1246
1247protected:
1248  virtual void EmitImpl(llvm::Serializer& S) const;
1249  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1250  friend class Type;
1251};
1252
1253class TagType : public Type {
1254  /// Stores the TagDecl associated with this type. The decl will
1255  /// point to the TagDecl that actually defines the entity (or is a
1256  /// definition in progress), if there is such a definition. The
1257  /// single-bit value will be non-zero when this tag is in the
1258  /// process of being defined.
1259  llvm::PointerIntPair<TagDecl *, 1> decl;
1260  friend class ASTContext;
1261  friend class TagDecl;
1262
1263protected:
1264  // FIXME: We'll need the user to pass in information about whether
1265  // this type is dependent or not, because we don't have enough
1266  // information to compute it here.
1267  TagType(TagDecl *D, QualType can)
1268    : Type(Tagged, can, /*Dependent=*/false), decl(D, 0) {}
1269
1270public:
1271  TagDecl *getDecl() const { return decl.getPointer(); }
1272
1273  /// @brief Determines whether this type is in the process of being
1274  /// defined.
1275  bool isBeingDefined() const { return decl.getInt(); }
1276  void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); }
1277
1278  virtual void getAsStringInternal(std::string &InnerString) const;
1279
1280  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
1281  static bool classof(const TagType *) { return true; }
1282
1283protected:
1284  virtual void EmitImpl(llvm::Serializer& S) const;
1285  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1286  friend class Type;
1287};
1288
1289/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
1290/// to detect TagType objects of structs/unions/classes.
1291class RecordType : public TagType {
1292protected:
1293  explicit RecordType(RecordDecl *D)
1294    : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { }
1295  friend class ASTContext;   // ASTContext creates these.
1296public:
1297
1298  RecordDecl *getDecl() const {
1299    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
1300  }
1301
1302  // FIXME: This predicate is a helper to QualType/Type. It needs to
1303  // recursively check all fields for const-ness. If any field is declared
1304  // const, it needs to return false.
1305  bool hasConstFields() const { return false; }
1306
1307  // FIXME: RecordType needs to check when it is created that all fields are in
1308  // the same address space, and return that.
1309  unsigned getAddressSpace() const { return 0; }
1310
1311  static bool classof(const TagType *T);
1312  static bool classof(const Type *T) {
1313    return isa<TagType>(T) && classof(cast<TagType>(T));
1314  }
1315  static bool classof(const RecordType *) { return true; }
1316};
1317
1318/// CXXRecordType - This is a helper class that allows the use of
1319/// isa/cast/dyncast to detect TagType objects of C++ structs/unions/classes.
1320class CXXRecordType : public RecordType {
1321  explicit CXXRecordType(CXXRecordDecl *D)
1322    : RecordType(reinterpret_cast<RecordDecl*>(D)) { }
1323  friend class ASTContext;   // ASTContext creates these.
1324public:
1325
1326  CXXRecordDecl *getDecl() const {
1327    return reinterpret_cast<CXXRecordDecl*>(RecordType::getDecl());
1328  }
1329
1330  static bool classof(const TagType *T);
1331  static bool classof(const Type *T) {
1332    return isa<TagType>(T) && classof(cast<TagType>(T));
1333  }
1334  static bool classof(const CXXRecordType *) { return true; }
1335};
1336
1337/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
1338/// to detect TagType objects of enums.
1339class EnumType : public TagType {
1340  explicit EnumType(EnumDecl *D)
1341    : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { }
1342  friend class ASTContext;   // ASTContext creates these.
1343public:
1344
1345  EnumDecl *getDecl() const {
1346    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
1347  }
1348
1349  static bool classof(const TagType *T);
1350  static bool classof(const Type *T) {
1351    return isa<TagType>(T) && classof(cast<TagType>(T));
1352  }
1353  static bool classof(const EnumType *) { return true; }
1354};
1355
1356class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
1357  unsigned Depth : 16;
1358  unsigned Index : 16;
1359  IdentifierInfo *Name;
1360
1361  TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N,
1362                       QualType Canon)
1363    : Type(TemplateTypeParm, Canon, /*Dependent=*/true),
1364      Depth(D), Index(I), Name(N) { }
1365
1366  TemplateTypeParmType(unsigned D, unsigned I)
1367    : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true),
1368      Depth(D), Index(I), Name(0) { }
1369
1370  friend class ASTContext;  // ASTContext creates these
1371
1372public:
1373  unsigned getDepth() const { return Depth; }
1374  unsigned getIndex() const { return Index; }
1375  IdentifierInfo *getName() const { return Name; }
1376
1377  virtual void getAsStringInternal(std::string &InnerString) const;
1378
1379  void Profile(llvm::FoldingSetNodeID &ID) {
1380    Profile(ID, Depth, Index, Name);
1381  }
1382
1383  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
1384                      unsigned Index, IdentifierInfo *Name) {
1385    ID.AddInteger(Depth);
1386    ID.AddInteger(Index);
1387    ID.AddPointer(Name);
1388  }
1389
1390  static bool classof(const Type *T) {
1391    return T->getTypeClass() == TemplateTypeParm;
1392  }
1393  static bool classof(const TemplateTypeParmType *T) { return true; }
1394
1395protected:
1396  virtual void EmitImpl(llvm::Serializer& S) const;
1397  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1398  friend class Type;
1399};
1400
1401/// \brief Represents the type of a class template specialization as
1402/// written in the source code.
1403///
1404/// Class template specialization types represent the syntactic form
1405/// of a template-id that refers to a type, e.g., @c vector<int>. All
1406/// class template specialization types are syntactic sugar, whose
1407/// canonical type will point to some other type node that represents
1408/// the instantiation or class template specialization. For example, a
1409/// class template specialization type of @c vector<int> will refer to
1410/// a tag type for the instantiation
1411/// @c std::vector<int, std::allocator<int>>.
1412class ClassTemplateSpecializationType
1413  : public Type, public llvm::FoldingSetNode {
1414
1415  // FIXME: Do we want templates to have a representation in the type
1416  // system? It will probably help with dependent templates and
1417  // possibly with template-names preceded by a nested-name-specifier.
1418  TemplateDecl *Template;
1419
1420  unsigned NumArgs;
1421
1422  ClassTemplateSpecializationType(TemplateDecl *T, unsigned NumArgs,
1423                                  uintptr_t *Args, bool *ArgIsType,
1424                                  QualType Canon);
1425
1426  /// \brief Retrieve the number of packed words that precede the
1427  /// actual arguments.
1428  ///
1429  /// The flags that specify whether each argument is a type or an
1430  /// expression are packed into the
1431  /// ClassTemplateSpecializationType. This routine computes the
1432  /// number of pointer-sized words we need to store this information,
1433  /// based on the number of template arguments
1434  static unsigned getNumPackedWords(unsigned NumArgs) {
1435    const unsigned BitsPerWord = sizeof(uintptr_t) * 8;
1436    return NumArgs / BitsPerWord + (NumArgs % BitsPerWord > 0);
1437  }
1438
1439  /// \brief Pack the given boolean values into words.
1440  static void
1441  packBooleanValues(unsigned NumArgs, bool *Values, uintptr_t *Words);
1442
1443  virtual void Destroy(ASTContext& C);
1444
1445  friend class ASTContext;  // ASTContext creates these
1446
1447public:
1448  /// \brief Retrieve the template that we are specializing.
1449  TemplateDecl *getTemplate() const { return Template; }
1450
1451  /// \briefe Retrieve the number of template arguments.
1452  unsigned getNumArgs() const { return NumArgs; }
1453
1454  /// \brief Retrieve a specific template argument as a type.
1455  /// \precondition @c isArgType(Arg)
1456  QualType getArgAsType(unsigned Arg) const {
1457    assert(isArgType(Arg) && "Argument is not a type");
1458    return QualType::getFromOpaquePtr(
1459                          reinterpret_cast<void *>(getArgAsOpaqueValue(Arg)));
1460  }
1461
1462  /// \brief Retrieve a specific template argument as an expression.
1463  /// \precondition @c !isArgType(Arg)
1464  Expr *getArgAsExpr(unsigned Arg) const {
1465    assert(!isArgType(Arg) && "Argument is not an expression");
1466    return reinterpret_cast<Expr *>(getArgAsOpaqueValue(Arg));
1467  }
1468
1469  /// \brief Retrieve the specified template argument as an opaque value.
1470  uintptr_t getArgAsOpaqueValue(unsigned Arg) const;
1471
1472  /// \brief Determine whether the given template argument is a type.
1473  bool isArgType(unsigned Arg) const;
1474
1475  virtual void getAsStringInternal(std::string &InnerString) const;
1476
1477  void Profile(llvm::FoldingSetNodeID &ID) {
1478    // Add the template
1479    ID.AddPointer(Template);
1480
1481    // Add the packed words describing what kind of template arguments
1482    // we have.
1483    uintptr_t *Data = reinterpret_cast<uintptr_t *>(this + 1);
1484    for (unsigned Packed = 0, NumPacked = getNumPackedWords(NumArgs);
1485         Packed != NumPacked; ++Packed)
1486      ID.AddInteger(Data[Packed]);
1487
1488    // Add the template arguments themselves.
1489    for (unsigned Arg = 0; Arg < NumArgs; ++Arg)
1490      ID.AddInteger(getArgAsOpaqueValue(Arg));
1491  }
1492
1493  static void Profile(llvm::FoldingSetNodeID &ID, TemplateDecl *T,
1494                      unsigned NumArgs, uintptr_t *Args, bool *ArgIsType) {
1495    // Add the template
1496    ID.AddPointer(T);
1497
1498    // Add the packed words describing what kind of template arguments
1499    // we have.
1500    unsigned NumPackedWords = getNumPackedWords(NumArgs);
1501    unsigned NumPackedBytes = NumPackedWords * sizeof(uintptr_t);
1502    uintptr_t *PackedWords
1503      = reinterpret_cast<uintptr_t *>(alloca(NumPackedBytes));
1504    packBooleanValues(NumArgs, ArgIsType, PackedWords);
1505    for (unsigned Packed = 0; Packed != NumPackedWords; ++Packed)
1506      ID.AddInteger(PackedWords[Packed]);
1507
1508    // Add the template arguments themselves.
1509    for (unsigned Arg = 0; Arg < NumArgs; ++Arg)
1510      ID.AddInteger(Args[Arg]);
1511  }
1512
1513  static bool classof(const Type *T) {
1514    return T->getTypeClass() == ClassTemplateSpecialization;
1515  }
1516  static bool classof(const ClassTemplateSpecializationType *T) { return true; }
1517
1518protected:
1519  virtual void EmitImpl(llvm::Serializer& S) const;
1520  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1521  friend class Type;
1522};
1523
1524/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
1525/// object oriented design.  They basically correspond to C++ classes.  There
1526/// are two kinds of interface types, normal interfaces like "NSString" and
1527/// qualified interfaces, which are qualified with a protocol list like
1528/// "NSString<NSCopyable, NSAmazing>".  Qualified interface types are instances
1529/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType.
1530class ObjCInterfaceType : public Type {
1531  ObjCInterfaceDecl *Decl;
1532protected:
1533  ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) :
1534    Type(tc, QualType(), /*Dependent=*/false), Decl(D) { }
1535  friend class ASTContext;  // ASTContext creates these.
1536public:
1537
1538  ObjCInterfaceDecl *getDecl() const { return Decl; }
1539
1540  /// qual_iterator and friends: this provides access to the (potentially empty)
1541  /// list of protocols qualifying this interface.  If this is an instance of
1542  /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an
1543  /// empty list if there are no qualifying protocols.
1544  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1545  inline qual_iterator qual_begin() const;
1546  inline qual_iterator qual_end() const;
1547  bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; }
1548
1549  /// getNumProtocols - Return the number of qualifying protocols in this
1550  /// interface type, or 0 if there are none.
1551  inline unsigned getNumProtocols() const;
1552
1553  /// getProtocol - Return the specified qualifying protocol.
1554  inline ObjCProtocolDecl *getProtocol(unsigned i) const;
1555
1556
1557  virtual void getAsStringInternal(std::string &InnerString) const;
1558  static bool classof(const Type *T) {
1559    return T->getTypeClass() == ObjCInterface ||
1560           T->getTypeClass() == ObjCQualifiedInterface;
1561  }
1562  static bool classof(const ObjCInterfaceType *) { return true; }
1563};
1564
1565/// ObjCQualifiedInterfaceType - This class represents interface types
1566/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>.
1567///
1568/// Duplicate protocols are removed and protocol list is canonicalized to be in
1569/// alphabetical order.
1570class ObjCQualifiedInterfaceType : public ObjCInterfaceType,
1571                                   public llvm::FoldingSetNode {
1572
1573  // List of protocols for this protocol conforming object type
1574  // List is sorted on protocol name. No protocol is enterred more than once.
1575  llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols;
1576
1577  ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
1578                             ObjCProtocolDecl **Protos, unsigned NumP) :
1579    ObjCInterfaceType(ObjCQualifiedInterface, D),
1580    Protocols(Protos, Protos+NumP) { }
1581  friend class ASTContext;  // ASTContext creates these.
1582public:
1583
1584  ObjCProtocolDecl *getProtocol(unsigned i) const {
1585    return Protocols[i];
1586  }
1587  unsigned getNumProtocols() const {
1588    return Protocols.size();
1589  }
1590
1591  qual_iterator qual_begin() const { return Protocols.begin(); }
1592  qual_iterator qual_end() const   { return Protocols.end(); }
1593
1594  virtual void getAsStringInternal(std::string &InnerString) const;
1595
1596  void Profile(llvm::FoldingSetNodeID &ID);
1597  static void Profile(llvm::FoldingSetNodeID &ID,
1598                      const ObjCInterfaceDecl *Decl,
1599                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1600
1601  static bool classof(const Type *T) {
1602    return T->getTypeClass() == ObjCQualifiedInterface;
1603  }
1604  static bool classof(const ObjCQualifiedInterfaceType *) { return true; }
1605};
1606
1607inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const {
1608  if (const ObjCQualifiedInterfaceType *QIT =
1609         dyn_cast<ObjCQualifiedInterfaceType>(this))
1610    return QIT->qual_begin();
1611  return 0;
1612}
1613inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const {
1614  if (const ObjCQualifiedInterfaceType *QIT =
1615         dyn_cast<ObjCQualifiedInterfaceType>(this))
1616    return QIT->qual_end();
1617  return 0;
1618}
1619
1620/// getNumProtocols - Return the number of qualifying protocols in this
1621/// interface type, or 0 if there are none.
1622inline unsigned ObjCInterfaceType::getNumProtocols() const {
1623  if (const ObjCQualifiedInterfaceType *QIT =
1624        dyn_cast<ObjCQualifiedInterfaceType>(this))
1625    return QIT->getNumProtocols();
1626  return 0;
1627}
1628
1629/// getProtocol - Return the specified qualifying protocol.
1630inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const {
1631  return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i);
1632}
1633
1634
1635
1636/// ObjCQualifiedIdType - to represent id<protocol-list>.
1637///
1638/// Duplicate protocols are removed and protocol list is canonicalized to be in
1639/// alphabetical order.
1640class ObjCQualifiedIdType : public Type,
1641                            public llvm::FoldingSetNode {
1642  // List of protocols for this protocol conforming 'id' type
1643  // List is sorted on protocol name. No protocol is enterred more than once.
1644  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1645
1646  ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP)
1647    : Type(ObjCQualifiedId, QualType()/*these are always canonical*/,
1648           /*Dependent=*/false),
1649  Protocols(Protos, Protos+NumP) { }
1650  friend class ASTContext;  // ASTContext creates these.
1651public:
1652
1653  ObjCProtocolDecl *getProtocols(unsigned i) const {
1654    return Protocols[i];
1655  }
1656  unsigned getNumProtocols() const {
1657    return Protocols.size();
1658  }
1659  ObjCProtocolDecl **getReferencedProtocols() {
1660    return &Protocols[0];
1661  }
1662
1663  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1664  qual_iterator qual_begin() const { return Protocols.begin(); }
1665  qual_iterator qual_end() const   { return Protocols.end(); }
1666
1667  virtual void getAsStringInternal(std::string &InnerString) const;
1668
1669  void Profile(llvm::FoldingSetNodeID &ID);
1670  static void Profile(llvm::FoldingSetNodeID &ID,
1671                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1672
1673  static bool classof(const Type *T) {
1674    return T->getTypeClass() == ObjCQualifiedId;
1675  }
1676  static bool classof(const ObjCQualifiedIdType *) { return true; }
1677
1678};
1679
1680
1681// Inline function definitions.
1682
1683/// getUnqualifiedType - Return the type without any qualifiers.
1684inline QualType QualType::getUnqualifiedType() const {
1685  Type *TP = getTypePtr();
1686  if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP))
1687    TP = ASQT->getBaseType();
1688  return QualType(TP, 0);
1689}
1690
1691/// getAddressSpace - Return the address space of this type.
1692inline unsigned QualType::getAddressSpace() const {
1693  QualType CT = getTypePtr()->getCanonicalTypeInternal();
1694  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
1695    return AT->getElementType().getAddressSpace();
1696  if (const RecordType *RT = dyn_cast<RecordType>(CT))
1697    return RT->getAddressSpace();
1698  if (const ASQualType *ASQT = dyn_cast<ASQualType>(CT))
1699    return ASQT->getAddressSpace();
1700  return 0;
1701}
1702
1703/// isMoreQualifiedThan - Determine whether this type is more
1704/// qualified than the Other type. For example, "const volatile int"
1705/// is more qualified than "const int", "volatile int", and
1706/// "int". However, it is not more qualified than "const volatile
1707/// int".
1708inline bool QualType::isMoreQualifiedThan(QualType Other) const {
1709  // FIXME: Handle address spaces
1710  unsigned MyQuals = this->getCVRQualifiers();
1711  unsigned OtherQuals = Other.getCVRQualifiers();
1712  assert(this->getAddressSpace() == 0 && "Address space not checked");
1713  assert(Other.getAddressSpace() == 0 && "Address space not checked");
1714  return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
1715}
1716
1717/// isAtLeastAsQualifiedAs - Determine whether this type is at last
1718/// as qualified as the Other type. For example, "const volatile
1719/// int" is at least as qualified as "const int", "volatile int",
1720/// "int", and "const volatile int".
1721inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
1722  // FIXME: Handle address spaces
1723  unsigned MyQuals = this->getCVRQualifiers();
1724  unsigned OtherQuals = Other.getCVRQualifiers();
1725  assert(this->getAddressSpace() == 0 && "Address space not checked");
1726  assert(Other.getAddressSpace() == 0 && "Address space not checked");
1727  return (MyQuals | OtherQuals) == MyQuals;
1728}
1729
1730/// getNonReferenceType - If Type is a reference type (e.g., const
1731/// int&), returns the type that the reference refers to ("const
1732/// int"). Otherwise, returns the type itself. This routine is used
1733/// throughout Sema to implement C++ 5p6:
1734///
1735///   If an expression initially has the type "reference to T" (8.3.2,
1736///   8.5.3), the type is adjusted to "T" prior to any further
1737///   analysis, the expression designates the object or function
1738///   denoted by the reference, and the expression is an lvalue.
1739inline QualType QualType::getNonReferenceType() const {
1740  if (const ReferenceType *RefType = (*this)->getAsReferenceType())
1741    return RefType->getPointeeType();
1742  else
1743    return *this;
1744}
1745
1746inline const TypedefType* Type::getAsTypedefType() const {
1747  return dyn_cast<TypedefType>(this);
1748}
1749inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
1750  if (const PointerType *PT = getAsPointerType())
1751    return PT->getPointeeType()->getAsObjCInterfaceType();
1752  return 0;
1753}
1754
1755// NOTE: All of these methods use "getUnqualifiedType" to strip off address
1756// space qualifiers if present.
1757inline bool Type::isFunctionType() const {
1758  return isa<FunctionType>(CanonicalType.getUnqualifiedType());
1759}
1760inline bool Type::isPointerType() const {
1761  return isa<PointerType>(CanonicalType.getUnqualifiedType());
1762}
1763inline bool Type::isBlockPointerType() const {
1764    return isa<BlockPointerType>(CanonicalType);
1765}
1766inline bool Type::isReferenceType() const {
1767  return isa<ReferenceType>(CanonicalType.getUnqualifiedType());
1768}
1769inline bool Type::isPointerLikeType() const {
1770  return isa<PointerLikeType>(CanonicalType.getUnqualifiedType());
1771}
1772inline bool Type::isFunctionPointerType() const {
1773  if (const PointerType* T = getAsPointerType())
1774    return T->getPointeeType()->isFunctionType();
1775  else
1776    return false;
1777}
1778inline bool Type::isMemberPointerType() const {
1779  return isa<MemberPointerType>(CanonicalType.getUnqualifiedType());
1780}
1781inline bool Type::isMemberFunctionPointerType() const {
1782  if (const MemberPointerType* T = getAsMemberPointerType())
1783    return T->getPointeeType()->isFunctionType();
1784  else
1785    return false;
1786}
1787inline bool Type::isArrayType() const {
1788  return isa<ArrayType>(CanonicalType.getUnqualifiedType());
1789}
1790inline bool Type::isConstantArrayType() const {
1791  return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType());
1792}
1793inline bool Type::isIncompleteArrayType() const {
1794  return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType());
1795}
1796inline bool Type::isVariableArrayType() const {
1797  return isa<VariableArrayType>(CanonicalType.getUnqualifiedType());
1798}
1799inline bool Type::isDependentSizedArrayType() const {
1800  return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType());
1801}
1802inline bool Type::isRecordType() const {
1803  return isa<RecordType>(CanonicalType.getUnqualifiedType());
1804}
1805inline bool Type::isAnyComplexType() const {
1806  return isa<ComplexType>(CanonicalType.getUnqualifiedType());
1807}
1808inline bool Type::isVectorType() const {
1809  return isa<VectorType>(CanonicalType.getUnqualifiedType());
1810}
1811inline bool Type::isExtVectorType() const {
1812  return isa<ExtVectorType>(CanonicalType.getUnqualifiedType());
1813}
1814inline bool Type::isObjCInterfaceType() const {
1815  return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
1816}
1817inline bool Type::isObjCQualifiedInterfaceType() const {
1818  return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType());
1819}
1820inline bool Type::isObjCQualifiedIdType() const {
1821  return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType());
1822}
1823inline bool Type::isTemplateTypeParmType() const {
1824  return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType());
1825}
1826
1827inline bool Type::isOverloadType() const {
1828  if (const BuiltinType *BT = getAsBuiltinType())
1829    return BT->getKind() == BuiltinType::Overload;
1830  else
1831    return false;
1832}
1833
1834/// Insertion operator for diagnostics.  This allows sending QualType's into a
1835/// diagnostic with <<.
1836inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
1837                                           QualType T) {
1838  DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
1839                  Diagnostic::ak_qualtype);
1840  return DB;
1841}
1842
1843}  // end namespace clang
1844
1845#endif
1846