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