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