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