Type.h revision 98cd599ee8a9b259ed7388ee2921a20d97658864
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 "llvm/Support/Casting.h"
18#include "llvm/ADT/FoldingSet.h"
19#include "llvm/ADT/APSInt.h"
20#include "llvm/Bitcode/SerializationFwd.h"
21
22using llvm::isa;
23using llvm::cast;
24using llvm::cast_or_null;
25using llvm::dyn_cast;
26using llvm::dyn_cast_or_null;
27
28namespace clang {
29  class ASTContext;
30  class Type;
31  class TypedefDecl;
32  class TagDecl;
33  class RecordDecl;
34  class CXXRecordDecl;
35  class EnumDecl;
36  class FieldDecl;
37  class ObjCInterfaceDecl;
38  class ObjCProtocolDecl;
39  class ObjCMethodDecl;
40  class Expr;
41  class Stmt;
42  class SourceLocation;
43  class PointerLikeType;
44  class PointerType;
45  class BlockPointerType;
46  class ReferenceType;
47  class VectorType;
48  class ArrayType;
49  class ConstantArrayType;
50  class VariableArrayType;
51  class IncompleteArrayType;
52  class RecordType;
53  class EnumType;
54  class ComplexType;
55  class TagType;
56  class TypedefType;
57  class FunctionType;
58  class FunctionTypeProto;
59  class ExtVectorType;
60  class BuiltinType;
61  class ObjCInterfaceType;
62  class ObjCQualifiedIdType;
63  class ObjCQualifiedInterfaceType;
64  class StmtIteratorBase;
65
66/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
67/// their own: instead each reference to a type stores the qualifiers.  This
68/// greatly reduces the number of nodes we need to allocate for types (for
69/// example we only need one for 'int', 'const int', 'volatile int',
70/// 'const volatile int', etc).
71///
72/// As an added efficiency bonus, instead of making this a pair, we just store
73/// the three bits we care about in the low bits of the pointer.  To handle the
74/// packing/unpacking, we make QualType be a simple wrapper class that acts like
75/// a smart pointer.
76class QualType {
77  uintptr_t ThePtr;
78public:
79  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
80    Const    = 0x1,
81    Restrict = 0x2,
82    Volatile = 0x4,
83    CVRFlags = Const|Restrict|Volatile
84  };
85
86  QualType() : ThePtr(0) {}
87
88  QualType(Type *Ptr, unsigned Quals) {
89    assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
90    ThePtr = reinterpret_cast<uintptr_t>(Ptr);
91    assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
92    ThePtr |= Quals;
93  }
94
95  QualType(const Type *Ptr, unsigned Quals) {
96    assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
97    ThePtr = reinterpret_cast<uintptr_t>(Ptr);
98    assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
99    ThePtr |= Quals;
100  }
101
102  static QualType getFromOpaquePtr(void *Ptr) {
103    QualType T;
104    T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
105    return T;
106  }
107
108  unsigned getCVRQualifiers() const {
109    return ThePtr & CVRFlags;
110  }
111  Type *getTypePtr() const {
112    return reinterpret_cast<Type*>(ThePtr & ~CVRFlags);
113  }
114
115  void *getAsOpaquePtr() const {
116    return reinterpret_cast<void*>(ThePtr);
117  }
118
119  Type &operator*() const {
120    return *getTypePtr();
121  }
122
123  Type *operator->() const {
124    return getTypePtr();
125  }
126
127  /// isNull - Return true if this QualType doesn't point to a type yet.
128  bool isNull() const {
129    return ThePtr == 0;
130  }
131
132  bool isConstQualified() const {
133    return (ThePtr & Const) ? true : false;
134  }
135  bool isVolatileQualified() const {
136    return (ThePtr & Volatile) ? true : false;
137  }
138  bool isRestrictQualified() const {
139    return (ThePtr & Restrict) ? true : false;
140  }
141
142  bool isConstant(ASTContext& Ctx) const;
143
144  /// addConst/addVolatile/addRestrict - add the specified type qual to this
145  /// QualType.
146  void addConst()    { ThePtr |= Const; }
147  void addVolatile() { ThePtr |= Volatile; }
148  void addRestrict() { ThePtr |= Restrict; }
149
150  void removeConst()    { ThePtr &= ~Const; }
151  void removeVolatile() { ThePtr &= ~Volatile; }
152  void removeRestrict() { ThePtr &= ~Restrict; }
153
154  QualType getQualifiedType(unsigned TQs) const {
155    return QualType(getTypePtr(), TQs);
156  }
157  QualType getWithAdditionalQualifiers(unsigned TQs) const {
158    return QualType(getTypePtr(), TQs|getCVRQualifiers());
159  }
160
161  inline QualType getUnqualifiedType() const;
162
163  /// isMoreQualifiedThan - Determine whether this type is more
164  /// qualified than the Other type. For example, "const volatile int"
165  /// is more qualified than "const int", "volatile int", and
166  /// "int". However, it is not more qualified than "const volatile
167  /// int".
168  bool isMoreQualifiedThan(QualType Other) const {
169    unsigned MyQuals = this->getCVRQualifiers();
170    unsigned OtherQuals = Other.getCVRQualifiers();
171    return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
172  }
173
174  /// isAtLeastAsQualifiedAs - Determine whether this type is at last
175  /// as qualified as the Other type. For example, "const volatile
176  /// int" is at least as qualified as "const int", "volatile int",
177  /// "int", and "const volatile int".
178  bool isAtLeastAsQualifiedAs(QualType Other) const {
179    unsigned MyQuals = this->getCVRQualifiers();
180    unsigned OtherQuals = Other.getCVRQualifiers();
181    return MyQuals | OtherQuals == MyQuals;
182  }
183
184  /// operator==/!= - Indicate whether the specified types and qualifiers are
185  /// identical.
186  bool operator==(const QualType &RHS) const {
187    return ThePtr == RHS.ThePtr;
188  }
189  bool operator!=(const QualType &RHS) const {
190    return ThePtr != RHS.ThePtr;
191  }
192  std::string getAsString() const {
193    std::string S;
194    getAsStringInternal(S);
195    return S;
196  }
197  void getAsStringInternal(std::string &Str) const;
198
199  void dump(const char *s) const;
200  void dump() const;
201
202  void Profile(llvm::FoldingSetNodeID &ID) const {
203    ID.AddPointer(getAsOpaquePtr());
204  }
205
206public:
207
208  /// getAddressSpace - Return the address space of this type.
209  inline unsigned getAddressSpace() const;
210
211  /// Emit - Serialize a QualType to Bitcode.
212  void Emit(llvm::Serializer& S) const;
213
214  /// Read - Deserialize a QualType from Bitcode.
215  static QualType ReadVal(llvm::Deserializer& D);
216
217  void ReadBackpatch(llvm::Deserializer& D);
218};
219
220} // end clang.
221
222namespace llvm {
223/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
224/// to a specific Type class.
225template<> struct simplify_type<const ::clang::QualType> {
226  typedef ::clang::Type* SimpleType;
227  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
228    return Val.getTypePtr();
229  }
230};
231template<> struct simplify_type< ::clang::QualType>
232  : public simplify_type<const ::clang::QualType> {};
233
234} // end namespace llvm
235
236namespace clang {
237
238/// Type - This is the base class of the type hierarchy.  A central concept
239/// with types is that each type always has a canonical type.  A canonical type
240/// is the type with any typedef names stripped out of it or the types it
241/// references.  For example, consider:
242///
243///  typedef int  foo;
244///  typedef foo* bar;
245///    'int *'    'foo *'    'bar'
246///
247/// There will be a Type object created for 'int'.  Since int is canonical, its
248/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
249/// TypeNameType).  Its CanonicalType pointer points to the 'int' Type.  Next
250/// there is a PointerType that represents 'int*', which, like 'int', is
251/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
252/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type
253/// is also 'int*'.
254///
255/// Non-canonical types are useful for emitting diagnostics, without losing
256/// information about typedefs being used.  Canonical types are useful for type
257/// comparisons (they allow by-pointer equality tests) and useful for reasoning
258/// about whether something has a particular form (e.g. is a function type),
259/// because they implicitly, recursively, strip all typedefs out of a type.
260///
261/// Types, once created, are immutable.
262///
263class Type {
264public:
265  enum TypeClass {
266    Builtin, Complex, Pointer, Reference,
267    ConstantArray, VariableArray, IncompleteArray,
268    Vector, ExtVector,
269    FunctionNoProto, FunctionProto,
270    TypeName, Tagged, ASQual,
271    ObjCInterface, ObjCQualifiedInterface,
272    ObjCQualifiedId,
273    TypeOfExp, TypeOfTyp, // GNU typeof extension.
274    BlockPointer          // C extension
275  };
276private:
277  QualType CanonicalType;
278
279  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
280  /// Note that this should stay at the end of the ivars for Type so that
281  /// subclasses can pack their bitfields into the same word.
282  unsigned TC : 5;
283protected:
284  // silence VC++ warning C4355: 'this' : used in base member initializer list
285  Type *this_() { return this; }
286  Type(TypeClass tc, QualType Canonical)
287    : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
288      TC(tc) {}
289  virtual ~Type() {};
290  virtual void Destroy(ASTContext& C);
291  friend class ASTContext;
292
293  void EmitTypeInternal(llvm::Serializer& S) const;
294  void ReadTypeInternal(llvm::Deserializer& D);
295
296public:
297  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
298
299  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
300
301  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
302  /// object types, function types, and incomplete types.
303
304  /// isObjectType - types that fully describe objects. An object is a region
305  /// of memory that can be examined and stored into (H&S).
306  bool isObjectType() const;
307
308  /// isIncompleteType - Return true if this is an incomplete type.
309  /// A type that can describe objects, but which lacks information needed to
310  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
311  /// routine will need to determine if the size is actually required.
312  bool isIncompleteType() const;
313
314  /// isIncompleteOrObjectType - Return true if this is an incomplete or object
315  /// type, in other words, not a function type.
316  bool isIncompleteOrObjectType() const {
317    return !isFunctionType();
318  }
319
320  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
321  /// types that have a non-constant expression. This does not include "[]".
322  bool isVariablyModifiedType() const;
323
324  /// Helper methods to distinguish type categories. All type predicates
325  /// operate on the canonical type, ignoring typedefs and qualifiers.
326
327  /// isIntegerType() does *not* include complex integers (a GCC extension).
328  /// isComplexIntegerType() can be used to test for complex integers.
329  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
330  bool isEnumeralType() const;
331  bool isBooleanType() const;
332  bool isCharType() const;
333  bool isWideCharType() const;
334  bool isIntegralType() const;
335
336  /// Floating point categories.
337  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
338  /// isComplexType() does *not* include complex integers (a GCC extension).
339  /// isComplexIntegerType() can be used to test for complex integers.
340  bool isComplexType() const;      // C99 6.2.5p11 (complex)
341  bool isAnyComplexType() const;   // C99 6.2.5p11 (complex) + Complex Int.
342  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
343  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
344  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
345  bool isVoidType() const;         // C99 6.2.5p19
346  bool isDerivedType() const;      // C99 6.2.5p20
347  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
348  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
349
350  // Type Predicates: Check to see if this type is structurally the specified
351  // type, ignoring typedefs and qualifiers.
352  bool isFunctionType() const;
353  bool isPointerLikeType() const; // Pointer or Reference.
354  bool isPointerType() const;
355  bool isBlockPointerType() const;
356  bool isReferenceType() const;
357  bool isFunctionPointerType() const;
358  bool isArrayType() const;
359  bool isConstantArrayType() const;
360  bool isIncompleteArrayType() const;
361  bool isVariableArrayType() const;
362  bool isRecordType() const;
363  bool isClassType() const;
364  bool isStructureType() const;
365  bool isUnionType() const;
366  bool isComplexIntegerType() const;            // GCC _Complex integer type.
367  bool isVectorType() const;                    // GCC vector type.
368  bool isExtVectorType() const;                 // Extended vector type.
369  bool isObjCInterfaceType() const;             // NSString or NSString<foo>
370  bool isObjCQualifiedInterfaceType() const;    // NSString<foo>
371  bool isObjCQualifiedIdType() const;           // id<foo>
372
373  // Type Checking Functions: Check to see if this type is structurally the
374  // specified type, ignoring typedefs and qualifiers, and return a pointer to
375  // the best type we can.
376  const BuiltinType *getAsBuiltinType() const;
377  const FunctionType *getAsFunctionType() const;
378  const FunctionTypeProto *getAsFunctionTypeProto() const;
379  const PointerLikeType *getAsPointerLikeType() const; // Pointer or Reference.
380  const PointerType *getAsPointerType() const;
381  const BlockPointerType *getAsBlockPointerType() const;
382  const ReferenceType *getAsReferenceType() const;
383  const RecordType *getAsRecordType() const;
384  const RecordType *getAsStructureType() const;
385  /// NOTE: getAsArrayType* are methods on ASTContext.
386  const TypedefType *getAsTypedefType() const;
387  const RecordType *getAsUnionType() const;
388  const EnumType *getAsEnumType() const;
389  const VectorType *getAsVectorType() const; // GCC vector type.
390  const ComplexType *getAsComplexType() const;
391  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
392  const ExtVectorType *getAsExtVectorType() const; // Extended vector type.
393  const ObjCInterfaceType *getAsObjCInterfaceType() const;
394  const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const;
395  const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const;
396
397  /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC
398  /// interface, return the interface type, otherwise return null.
399  const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const;
400
401  /// getArrayElementTypeNoTypeQual - If this is an array type, return the
402  /// element type of the array, potentially with type qualifiers missing.
403  /// This method should never be used when type qualifiers are meaningful.
404  const Type *getArrayElementTypeNoTypeQual() const;
405
406
407
408  /// getDesugaredType - Return the specified type with any "sugar" removed from
409  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
410  /// the type is already concrete, it returns it unmodified.  This is similar
411  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
412  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
413  /// concrete.
414  QualType getDesugaredType() const;
415
416  /// More type predicates useful for type checking/promotion
417  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
418
419  /// isSignedIntegerType - Return true if this is an integer type that is
420  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
421  /// an enum decl which has a signed representation, or a vector of signed
422  /// integer element type.
423  bool isSignedIntegerType() const;
424
425  /// isUnsignedIntegerType - Return true if this is an integer type that is
426  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
427  /// decl which has an unsigned representation, or a vector of unsigned integer
428  /// element type.
429  bool isUnsignedIntegerType() const;
430
431  /// isConstantSizeType - Return true if this is not a variable sized type,
432  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
433  /// incomplete types.
434  bool isConstantSizeType() const;
435
436  QualType getCanonicalTypeInternal() const { return CanonicalType; }
437  void dump() const;
438  virtual void getAsStringInternal(std::string &InnerString) const = 0;
439  static bool classof(const Type *) { return true; }
440
441protected:
442  /// Emit - Emit a Type to bitcode.  Used by ASTContext.
443  void Emit(llvm::Serializer& S) const;
444
445  /// Create - Construct a Type from bitcode.  Used by ASTContext.
446  static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S);
447
448  /// EmitImpl - Subclasses must implement this method in order to
449  ///  be serialized.
450  // FIXME: Make this abstract once implemented.
451  virtual void EmitImpl(llvm::Serializer& S) const {
452    assert (false && "Serializization for type not supported.");
453  }
454};
455
456/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26
457/// This supports address space qualified types.
458///
459class ASQualType : public Type, public llvm::FoldingSetNode {
460  /// BaseType - This is the underlying type that this qualifies.  All CVR
461  /// qualifiers are stored on the QualType that references this type, so we
462  /// can't have any here.
463  Type *BaseType;
464  /// Address Space ID - The address space ID this type is qualified with.
465  unsigned AddressSpace;
466  ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) :
467    Type(ASQual, CanonicalPtr), BaseType(Base), AddressSpace(AddrSpace) {
468  }
469  friend class ASTContext;  // ASTContext creates these.
470public:
471  Type *getBaseType() const { return BaseType; }
472  unsigned getAddressSpace() const { return AddressSpace; }
473
474  virtual void getAsStringInternal(std::string &InnerString) const;
475
476  void Profile(llvm::FoldingSetNodeID &ID) {
477    Profile(ID, getBaseType(), AddressSpace);
478  }
479  static void Profile(llvm::FoldingSetNodeID &ID, Type *Base,
480                      unsigned AddrSpace) {
481    ID.AddPointer(Base);
482    ID.AddInteger(AddrSpace);
483  }
484
485  static bool classof(const Type *T) { return T->getTypeClass() == ASQual; }
486  static bool classof(const ASQualType *) { return true; }
487
488protected:
489  virtual void EmitImpl(llvm::Serializer& S) const;
490  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
491  friend class Type;
492};
493
494
495/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
496/// types are always canonical and have a literal name field.
497class BuiltinType : public Type {
498public:
499  enum Kind {
500    Void,
501
502    Bool,     // This is bool and/or _Bool.
503    Char_U,   // This is 'char' for targets where char is unsigned.
504    UChar,    // This is explicitly qualified unsigned char.
505    UShort,
506    UInt,
507    ULong,
508    ULongLong,
509
510    Char_S,   // This is 'char' for targets where char is signed.
511    SChar,    // This is explicitly qualified signed char.
512    WChar,    // This is 'wchar_t' for C++.
513    Short,
514    Int,
515    Long,
516    LongLong,
517
518    Float, Double, LongDouble,
519
520    Overload  // This represents the type of an overloaded function declaration.
521  };
522private:
523  Kind TypeKind;
524public:
525  BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {}
526
527  Kind getKind() const { return TypeKind; }
528  const char *getName() const;
529
530  virtual void getAsStringInternal(std::string &InnerString) const;
531
532  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
533  static bool classof(const BuiltinType *) { return true; }
534};
535
536/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
537/// types (_Complex float etc) as well as the GCC integer complex extensions.
538///
539class ComplexType : public Type, public llvm::FoldingSetNode {
540  QualType ElementType;
541  ComplexType(QualType Element, QualType CanonicalPtr) :
542    Type(Complex, CanonicalPtr), ElementType(Element) {
543  }
544  friend class ASTContext;  // ASTContext creates these.
545public:
546  QualType getElementType() const { return ElementType; }
547
548  virtual void getAsStringInternal(std::string &InnerString) const;
549
550  void Profile(llvm::FoldingSetNodeID &ID) {
551    Profile(ID, getElementType());
552  }
553  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
554    ID.AddPointer(Element.getAsOpaquePtr());
555  }
556
557  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
558  static bool classof(const ComplexType *) { return true; }
559
560protected:
561  virtual void EmitImpl(llvm::Serializer& S) const;
562  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
563  friend class Type;
564};
565
566/// PointerLikeType - Common base class for pointers and references.
567/// FIXME: Add more documentation on this classes design point. For example,
568/// should BlockPointerType inherit from it? Is the concept of a PointerLikeType
569/// in the C++ standard?
570///
571class PointerLikeType : public Type {
572  QualType PointeeType;
573protected:
574  PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) :
575    Type(K, CanonicalPtr), PointeeType(Pointee) {
576  }
577public:
578
579  QualType getPointeeType() const { return PointeeType; }
580
581  static bool classof(const Type *T) {
582    return T->getTypeClass() == Pointer || T->getTypeClass() == Reference;
583  }
584  static bool classof(const PointerLikeType *) { return true; }
585};
586
587/// PointerType - C99 6.7.5.1 - Pointer Declarators.
588///
589class PointerType : public PointerLikeType, public llvm::FoldingSetNode {
590  PointerType(QualType Pointee, QualType CanonicalPtr) :
591    PointerLikeType(Pointer, Pointee, CanonicalPtr) {
592  }
593  friend class ASTContext;  // ASTContext creates these.
594public:
595
596  virtual void getAsStringInternal(std::string &InnerString) const;
597
598  void Profile(llvm::FoldingSetNodeID &ID) {
599    Profile(ID, getPointeeType());
600  }
601  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
602    ID.AddPointer(Pointee.getAsOpaquePtr());
603  }
604
605  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
606  static bool classof(const PointerType *) { return true; }
607
608protected:
609  virtual void EmitImpl(llvm::Serializer& S) const;
610  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
611  friend class Type;
612};
613
614/// BlockPointerType - pointer to a block type.
615/// This type is to represent types syntactically represented as
616/// "void (^)(int)", etc. Pointee is required to always be a function type.
617/// FIXME: Should BlockPointerType inherit from PointerLikeType? It could
618/// simplfy some type checking code, however PointerLikeType doesn't appear
619/// to be used by the type checker.
620///
621class BlockPointerType : public Type, public llvm::FoldingSetNode {
622  QualType PointeeType;  // Block is some kind of pointer type
623  BlockPointerType(QualType Pointee, QualType CanonicalCls) :
624    Type(BlockPointer, CanonicalCls), PointeeType(Pointee) {
625  }
626  friend class ASTContext;  // ASTContext creates these.
627public:
628
629  // Get the pointee type. Pointee is required to always be a function type.
630  QualType getPointeeType() const { return PointeeType; }
631
632  virtual void getAsStringInternal(std::string &InnerString) const;
633
634  void Profile(llvm::FoldingSetNodeID &ID) {
635      Profile(ID, getPointeeType());
636  }
637  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
638      ID.AddPointer(Pointee.getAsOpaquePtr());
639  }
640
641  static bool classof(const Type *T) {
642    return T->getTypeClass() == BlockPointer;
643  }
644  static bool classof(const BlockPointerType *) { return true; }
645
646  protected:
647    virtual void EmitImpl(llvm::Serializer& S) const;
648    static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
649    friend class Type;
650};
651
652/// ReferenceType - C++ 8.3.2 - Reference Declarators.
653///
654class ReferenceType : public PointerLikeType, public llvm::FoldingSetNode {
655  ReferenceType(QualType Referencee, QualType CanonicalRef) :
656    PointerLikeType(Reference, Referencee, CanonicalRef) {
657  }
658  friend class ASTContext;  // ASTContext creates these.
659public:
660  virtual void getAsStringInternal(std::string &InnerString) const;
661
662  void Profile(llvm::FoldingSetNodeID &ID) {
663    Profile(ID, getPointeeType());
664  }
665  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
666    ID.AddPointer(Referencee.getAsOpaquePtr());
667  }
668
669  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
670  static bool classof(const ReferenceType *) { return true; }
671};
672
673/// ArrayType - C99 6.7.5.2 - Array Declarators.
674///
675class ArrayType : public Type, public llvm::FoldingSetNode {
676public:
677  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
678  /// an array with a static size (e.g. int X[static 4]), or with a star size
679  /// (e.g. int X[*]). 'static' is only allowed on function parameters.
680  enum ArraySizeModifier {
681    Normal, Static, Star
682  };
683private:
684  /// ElementType - The element type of the array.
685  QualType ElementType;
686
687  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
688  /// NOTE: These fields are packed into the bitfields space in the Type class.
689  unsigned SizeModifier : 2;
690
691  /// IndexTypeQuals - Capture qualifiers in declarations like:
692  /// 'int X[static restrict 4]'. For function parameters only.
693  unsigned IndexTypeQuals : 3;
694
695protected:
696  ArrayType(TypeClass tc, QualType et, QualType can,
697            ArraySizeModifier sm, unsigned tq)
698    : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
699  friend class ASTContext;  // ASTContext creates these.
700public:
701  QualType getElementType() const { return ElementType; }
702  ArraySizeModifier getSizeModifier() const {
703    return ArraySizeModifier(SizeModifier);
704  }
705  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
706
707  static bool classof(const Type *T) {
708    return T->getTypeClass() == ConstantArray ||
709           T->getTypeClass() == VariableArray ||
710           T->getTypeClass() == IncompleteArray;
711  }
712  static bool classof(const ArrayType *) { return true; }
713};
714
715/// ConstantArrayType - This class represents C arrays with a specified constant
716/// size.  For example 'int A[100]' has ConstantArrayType where the element type
717/// is 'int' and the size is 100.
718class ConstantArrayType : public ArrayType {
719  llvm::APInt Size; // Allows us to unique the type.
720
721  ConstantArrayType(QualType et, QualType can, llvm::APInt sz,
722                    ArraySizeModifier sm, unsigned tq)
723    : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {}
724  friend class ASTContext;  // ASTContext creates these.
725public:
726  const llvm::APInt &getSize() const { return Size; }
727  virtual void getAsStringInternal(std::string &InnerString) const;
728
729  void Profile(llvm::FoldingSetNodeID &ID) {
730    Profile(ID, getElementType(), getSize());
731  }
732  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
733                      llvm::APInt ArraySize) {
734    ID.AddPointer(ET.getAsOpaquePtr());
735    ID.AddInteger(ArraySize.getZExtValue());
736  }
737  static bool classof(const Type *T) {
738    return T->getTypeClass() == ConstantArray;
739  }
740  static bool classof(const ConstantArrayType *) { return true; }
741
742protected:
743  virtual void EmitImpl(llvm::Serializer& S) const;
744  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
745  friend class Type;
746};
747
748/// IncompleteArrayType - This class represents C arrays with an unspecified
749/// size.  For example 'int A[]' has an IncompleteArrayType where the element
750/// type is 'int' and the size is unspecified.
751class IncompleteArrayType : public ArrayType {
752  IncompleteArrayType(QualType et, QualType can,
753                    ArraySizeModifier sm, unsigned tq)
754    : ArrayType(IncompleteArray, et, can, sm, tq) {}
755  friend class ASTContext;  // ASTContext creates these.
756public:
757
758  virtual void getAsStringInternal(std::string &InnerString) const;
759
760  static bool classof(const Type *T) {
761    return T->getTypeClass() == IncompleteArray;
762  }
763  static bool classof(const IncompleteArrayType *) { return true; }
764
765  friend class StmtIteratorBase;
766
767  void Profile(llvm::FoldingSetNodeID &ID) {
768    Profile(ID, getElementType());
769  }
770
771  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) {
772    ID.AddPointer(ET.getAsOpaquePtr());
773  }
774
775protected:
776  virtual void EmitImpl(llvm::Serializer& S) const;
777  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
778  friend class Type;
779};
780
781/// VariableArrayType - This class represents C arrays with a specified size
782/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
783/// Since the size expression is an arbitrary expression, we store it as such.
784///
785/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
786/// should not be: two lexically equivalent variable array types could mean
787/// different things, for example, these variables do not have the same type
788/// dynamically:
789///
790/// void foo(int x) {
791///   int Y[x];
792///   ++x;
793///   int Z[x];
794/// }
795///
796class VariableArrayType : public ArrayType {
797  /// SizeExpr - An assignment expression. VLA's are only permitted within
798  /// a function block.
799  Stmt *SizeExpr;
800
801  VariableArrayType(QualType et, QualType can, Expr *e,
802                    ArraySizeModifier sm, unsigned tq)
803    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
804  friend class ASTContext;  // ASTContext creates these.
805  virtual void Destroy(ASTContext& C);
806
807public:
808  Expr *getSizeExpr() const {
809    // We use C-style casts instead of cast<> here because we do not wish
810    // to have a dependency of Type.h on Stmt.h/Expr.h.
811    return (Expr*) SizeExpr;
812  }
813
814  virtual void getAsStringInternal(std::string &InnerString) const;
815
816  static bool classof(const Type *T) {
817    return T->getTypeClass() == VariableArray;
818  }
819  static bool classof(const VariableArrayType *) { return true; }
820
821  friend class StmtIteratorBase;
822
823  void Profile(llvm::FoldingSetNodeID &ID) {
824    assert (0 && "Cannnot unique VariableArrayTypes.");
825  }
826
827protected:
828  virtual void EmitImpl(llvm::Serializer& S) const;
829  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
830  friend class Type;
831};
832
833/// VectorType - GCC generic vector type. This type is created using
834/// __attribute__((vector_size(n)), where "n" specifies the vector size in
835/// bytes. Since the constructor takes the number of vector elements, the
836/// client is responsible for converting the size into the number of elements.
837class VectorType : public Type, public llvm::FoldingSetNode {
838protected:
839  /// ElementType - The element type of the vector.
840  QualType ElementType;
841
842  /// NumElements - The number of elements in the vector.
843  unsigned NumElements;
844
845  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
846    Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {}
847  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
848    QualType canonType) : Type(tc, canonType), ElementType(vecType),
849    NumElements(nElements) {}
850  friend class ASTContext;  // ASTContext creates these.
851public:
852
853  QualType getElementType() const { return ElementType; }
854  unsigned getNumElements() const { return NumElements; }
855
856  virtual void getAsStringInternal(std::string &InnerString) const;
857
858  void Profile(llvm::FoldingSetNodeID &ID) {
859    Profile(ID, getElementType(), getNumElements(), getTypeClass());
860  }
861  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
862                      unsigned NumElements, TypeClass TypeClass) {
863    ID.AddPointer(ElementType.getAsOpaquePtr());
864    ID.AddInteger(NumElements);
865    ID.AddInteger(TypeClass);
866  }
867  static bool classof(const Type *T) {
868    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
869  }
870  static bool classof(const VectorType *) { return true; }
871};
872
873/// ExtVectorType - Extended vector type. This type is created using
874/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
875/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
876/// class enables syntactic extensions, like Vector Components for accessing
877/// points, colors, and textures (modeled after OpenGL Shading Language).
878class ExtVectorType : public VectorType {
879  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
880    VectorType(ExtVector, vecType, nElements, canonType) {}
881  friend class ASTContext;  // ASTContext creates these.
882public:
883  static int getPointAccessorIdx(char c) {
884    switch (c) {
885    default: return -1;
886    case 'x': return 0;
887    case 'y': return 1;
888    case 'z': return 2;
889    case 'w': return 3;
890    }
891  }
892  static int getColorAccessorIdx(char c) {
893    switch (c) {
894    default: return -1;
895    case 'r': return 0;
896    case 'g': return 1;
897    case 'b': return 2;
898    case 'a': return 3;
899    }
900  }
901  static int getTextureAccessorIdx(char c) {
902    switch (c) {
903    default: return -1;
904    case 's': return 0;
905    case 't': return 1;
906    case 'p': return 2;
907    case 'q': return 3;
908    }
909  };
910
911  static int getAccessorIdx(char c) {
912    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
913    if (int idx = getColorAccessorIdx(c)+1) return idx-1;
914    return getTextureAccessorIdx(c);
915  }
916
917  bool isAccessorWithinNumElements(char c) const {
918    if (int idx = getAccessorIdx(c)+1)
919      return unsigned(idx-1) < NumElements;
920    return false;
921  }
922  virtual void getAsStringInternal(std::string &InnerString) const;
923
924  static bool classof(const Type *T) {
925    return T->getTypeClass() == ExtVector;
926  }
927  static bool classof(const ExtVectorType *) { return true; }
928};
929
930/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
931/// class of FunctionTypeNoProto and FunctionTypeProto.
932///
933class FunctionType : public Type {
934  /// SubClassData - This field is owned by the subclass, put here to pack
935  /// tightly with the ivars in Type.
936  bool SubClassData : 1;
937
938  // The type returned by the function.
939  QualType ResultType;
940protected:
941  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical)
942    : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {}
943  bool getSubClassData() const { return SubClassData; }
944public:
945
946  QualType getResultType() const { return ResultType; }
947
948
949  static bool classof(const Type *T) {
950    return T->getTypeClass() == FunctionNoProto ||
951           T->getTypeClass() == FunctionProto;
952  }
953  static bool classof(const FunctionType *) { return true; }
954};
955
956/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
957/// no information available about its arguments.
958class FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
959  FunctionTypeNoProto(QualType Result, QualType Canonical)
960    : FunctionType(FunctionNoProto, Result, false, Canonical) {}
961  friend class ASTContext;  // ASTContext creates these.
962public:
963  // No additional state past what FunctionType provides.
964
965  virtual void getAsStringInternal(std::string &InnerString) const;
966
967  void Profile(llvm::FoldingSetNodeID &ID) {
968    Profile(ID, getResultType());
969  }
970  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
971    ID.AddPointer(ResultType.getAsOpaquePtr());
972  }
973
974  static bool classof(const Type *T) {
975    return T->getTypeClass() == FunctionNoProto;
976  }
977  static bool classof(const FunctionTypeNoProto *) { return true; }
978
979protected:
980  virtual void EmitImpl(llvm::Serializer& S) const;
981  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
982  friend class Type;
983};
984
985/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
986/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
987/// arguments, not as having a single void argument.
988class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
989  FunctionTypeProto(QualType Result, const QualType *ArgArray, unsigned numArgs,
990                    bool isVariadic, QualType Canonical)
991    : FunctionType(FunctionProto, Result, isVariadic, Canonical),
992      NumArgs(numArgs) {
993    // Fill in the trailing argument array.
994    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
995    for (unsigned i = 0; i != numArgs; ++i)
996      ArgInfo[i] = ArgArray[i];
997  }
998
999  /// NumArgs - The number of arguments this function has, not counting '...'.
1000  unsigned NumArgs;
1001
1002  /// ArgInfo - There is an variable size array after the class in memory that
1003  /// holds the argument types.
1004
1005  friend class ASTContext;  // ASTContext creates these.
1006  virtual void Destroy(ASTContext& C);
1007
1008public:
1009  unsigned getNumArgs() const { return NumArgs; }
1010  QualType getArgType(unsigned i) const {
1011    assert(i < NumArgs && "Invalid argument number!");
1012    return arg_type_begin()[i];
1013  }
1014
1015  bool isVariadic() const { return getSubClassData(); }
1016
1017  typedef const QualType *arg_type_iterator;
1018  arg_type_iterator arg_type_begin() const {
1019    return reinterpret_cast<const QualType *>(this+1);
1020  }
1021  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
1022
1023  virtual void getAsStringInternal(std::string &InnerString) const;
1024
1025  static bool classof(const Type *T) {
1026    return T->getTypeClass() == FunctionProto;
1027  }
1028  static bool classof(const FunctionTypeProto *) { return true; }
1029
1030  void Profile(llvm::FoldingSetNodeID &ID);
1031  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
1032                      arg_type_iterator ArgTys, unsigned NumArgs,
1033                      bool isVariadic);
1034
1035protected:
1036  virtual void EmitImpl(llvm::Serializer& S) const;
1037  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1038  friend class Type;
1039};
1040
1041
1042class TypedefType : public Type {
1043  TypedefDecl *Decl;
1044protected:
1045  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
1046    : Type(tc, can), Decl(D) {
1047    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1048  }
1049  friend class ASTContext;  // ASTContext creates these.
1050public:
1051
1052  TypedefDecl *getDecl() const { return Decl; }
1053
1054  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
1055  /// potentially looking through *all* consequtive typedefs.  This returns the
1056  /// sum of the type qualifiers, so if you have:
1057  ///   typedef const int A;
1058  ///   typedef volatile A B;
1059  /// looking through the typedefs for B will give you "const volatile A".
1060  QualType LookThroughTypedefs() const;
1061
1062  virtual void getAsStringInternal(std::string &InnerString) const;
1063
1064  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
1065  static bool classof(const TypedefType *) { return true; }
1066
1067protected:
1068  virtual void EmitImpl(llvm::Serializer& S) const;
1069  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1070  friend class Type;
1071};
1072
1073/// TypeOfExpr (GCC extension).
1074class TypeOfExpr : public Type {
1075  Expr *TOExpr;
1076  TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) {
1077    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1078  }
1079  friend class ASTContext;  // ASTContext creates these.
1080public:
1081  Expr *getUnderlyingExpr() const { return TOExpr; }
1082
1083  virtual void getAsStringInternal(std::string &InnerString) const;
1084
1085  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
1086  static bool classof(const TypeOfExpr *) { return true; }
1087};
1088
1089/// TypeOfType (GCC extension).
1090class TypeOfType : public Type {
1091  QualType TOType;
1092  TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) {
1093    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1094  }
1095  friend class ASTContext;  // ASTContext creates these.
1096public:
1097  QualType getUnderlyingType() const { return TOType; }
1098
1099  virtual void getAsStringInternal(std::string &InnerString) const;
1100
1101  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
1102  static bool classof(const TypeOfType *) { return true; }
1103};
1104
1105class TagType : public Type {
1106  TagDecl *decl;
1107  friend class ASTContext;
1108
1109protected:
1110  TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {}
1111
1112public:
1113  TagDecl *getDecl() const { return decl; }
1114
1115  virtual void getAsStringInternal(std::string &InnerString) const;
1116
1117  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
1118  static bool classof(const TagType *) { return true; }
1119
1120protected:
1121  virtual void EmitImpl(llvm::Serializer& S) const;
1122  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1123  friend class Type;
1124};
1125
1126/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
1127/// to detect TagType objects of structs/unions/classes.
1128class RecordType : public TagType {
1129protected:
1130  explicit RecordType(RecordDecl *D)
1131    : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { }
1132  friend class ASTContext;   // ASTContext creates these.
1133public:
1134
1135  RecordDecl *getDecl() const {
1136    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
1137  }
1138
1139  // FIXME: This predicate is a helper to QualType/Type. It needs to
1140  // recursively check all fields for const-ness. If any field is declared
1141  // const, it needs to return false.
1142  bool hasConstFields() const { return false; }
1143
1144  // FIXME: RecordType needs to check when it is created that all fields are in
1145  // the same address space, and return that.
1146  unsigned getAddressSpace() const { return 0; }
1147
1148  static bool classof(const TagType *T);
1149  static bool classof(const Type *T) {
1150    return isa<TagType>(T) && classof(cast<TagType>(T));
1151  }
1152  static bool classof(const RecordType *) { return true; }
1153};
1154
1155/// CXXRecordType - This is a helper class that allows the use of
1156/// isa/cast/dyncast to detect TagType objects of C++ structs/unions/classes.
1157class CXXRecordType : public RecordType {
1158  explicit CXXRecordType(CXXRecordDecl *D)
1159    : RecordType(reinterpret_cast<RecordDecl*>(D)) { }
1160  friend class ASTContext;   // ASTContext creates these.
1161public:
1162
1163  CXXRecordDecl *getDecl() const {
1164    return reinterpret_cast<CXXRecordDecl*>(RecordType::getDecl());
1165  }
1166
1167  static bool classof(const TagType *T);
1168  static bool classof(const Type *T) {
1169    return isa<TagType>(T) && classof(cast<TagType>(T));
1170  }
1171  static bool classof(const CXXRecordType *) { return true; }
1172};
1173
1174/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
1175/// to detect TagType objects of enums.
1176class EnumType : public TagType {
1177  explicit EnumType(EnumDecl *D)
1178    : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { }
1179  friend class ASTContext;   // ASTContext creates these.
1180public:
1181
1182  EnumDecl *getDecl() const {
1183    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
1184  }
1185
1186  static bool classof(const TagType *T);
1187  static bool classof(const Type *T) {
1188    return isa<TagType>(T) && classof(cast<TagType>(T));
1189  }
1190  static bool classof(const EnumType *) { return true; }
1191};
1192
1193
1194
1195/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
1196/// object oriented design.  They basically correspond to C++ classes.  There
1197/// are two kinds of interface types, normal interfaces like "NSString" and
1198/// qualified interfaces, which are qualified with a protocol list like
1199/// "NSString<NSCopyable, NSAmazing>".  Qualified interface types are instances
1200/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType.
1201class ObjCInterfaceType : public Type {
1202  ObjCInterfaceDecl *Decl;
1203protected:
1204  ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) :
1205    Type(tc, QualType()), Decl(D) { }
1206  friend class ASTContext;  // ASTContext creates these.
1207public:
1208
1209  ObjCInterfaceDecl *getDecl() const { return Decl; }
1210
1211  /// qual_iterator and friends: this provides access to the (potentially empty)
1212  /// list of protocols qualifying this interface.  If this is an instance of
1213  /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an
1214  /// empty list if there are no qualifying protocols.
1215  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1216  inline qual_iterator qual_begin() const;
1217  inline qual_iterator qual_end() const;
1218  bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; }
1219
1220  /// getNumProtocols - Return the number of qualifying protocols in this
1221  /// interface type, or 0 if there are none.
1222  inline unsigned getNumProtocols() const;
1223
1224  /// getProtocol - Return the specified qualifying protocol.
1225  inline ObjCProtocolDecl *getProtocol(unsigned i) const;
1226
1227
1228  virtual void getAsStringInternal(std::string &InnerString) const;
1229  static bool classof(const Type *T) {
1230    return T->getTypeClass() == ObjCInterface ||
1231           T->getTypeClass() == ObjCQualifiedInterface;
1232  }
1233  static bool classof(const ObjCInterfaceType *) { return true; }
1234};
1235
1236/// ObjCQualifiedInterfaceType - This class represents interface types
1237/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>.
1238///
1239/// Duplicate protocols are removed and protocol list is canonicalized to be in
1240/// alphabetical order.
1241class ObjCQualifiedInterfaceType : public ObjCInterfaceType,
1242                                   public llvm::FoldingSetNode {
1243
1244  // List of protocols for this protocol conforming object type
1245  // List is sorted on protocol name. No protocol is enterred more than once.
1246  llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols;
1247
1248  ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
1249                             ObjCProtocolDecl **Protos, unsigned NumP) :
1250    ObjCInterfaceType(ObjCQualifiedInterface, D),
1251    Protocols(Protos, Protos+NumP) { }
1252  friend class ASTContext;  // ASTContext creates these.
1253public:
1254
1255  ObjCProtocolDecl *getProtocol(unsigned i) const {
1256    return Protocols[i];
1257  }
1258  unsigned getNumProtocols() const {
1259    return Protocols.size();
1260  }
1261
1262  qual_iterator qual_begin() const { return Protocols.begin(); }
1263  qual_iterator qual_end() const   { return Protocols.end(); }
1264
1265  virtual void getAsStringInternal(std::string &InnerString) const;
1266
1267  void Profile(llvm::FoldingSetNodeID &ID);
1268  static void Profile(llvm::FoldingSetNodeID &ID,
1269                      const ObjCInterfaceDecl *Decl,
1270                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1271
1272  static bool classof(const Type *T) {
1273    return T->getTypeClass() == ObjCQualifiedInterface;
1274  }
1275  static bool classof(const ObjCQualifiedInterfaceType *) { return true; }
1276};
1277
1278inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const {
1279  if (const ObjCQualifiedInterfaceType *QIT =
1280         dyn_cast<ObjCQualifiedInterfaceType>(this))
1281    return QIT->qual_begin();
1282  return 0;
1283}
1284inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const {
1285  if (const ObjCQualifiedInterfaceType *QIT =
1286         dyn_cast<ObjCQualifiedInterfaceType>(this))
1287    return QIT->qual_end();
1288  return 0;
1289}
1290
1291/// getNumProtocols - Return the number of qualifying protocols in this
1292/// interface type, or 0 if there are none.
1293inline unsigned ObjCInterfaceType::getNumProtocols() const {
1294  if (const ObjCQualifiedInterfaceType *QIT =
1295        dyn_cast<ObjCQualifiedInterfaceType>(this))
1296    return QIT->getNumProtocols();
1297  return 0;
1298}
1299
1300/// getProtocol - Return the specified qualifying protocol.
1301inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const {
1302  return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i);
1303}
1304
1305
1306
1307/// ObjCQualifiedIdType - to represent id<protocol-list>.
1308///
1309/// Duplicate protocols are removed and protocol list is canonicalized to be in
1310/// alphabetical order.
1311class ObjCQualifiedIdType : public Type,
1312                            public llvm::FoldingSetNode {
1313  // List of protocols for this protocol conforming 'id' type
1314  // List is sorted on protocol name. No protocol is enterred more than once.
1315  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1316
1317  ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP)
1318    : Type(ObjCQualifiedId, QualType()/*these are always canonical*/),
1319  Protocols(Protos, Protos+NumP) { }
1320  friend class ASTContext;  // ASTContext creates these.
1321public:
1322
1323  ObjCProtocolDecl *getProtocols(unsigned i) const {
1324    return Protocols[i];
1325  }
1326  unsigned getNumProtocols() const {
1327    return Protocols.size();
1328  }
1329  ObjCProtocolDecl **getReferencedProtocols() {
1330    return &Protocols[0];
1331  }
1332
1333  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1334  qual_iterator qual_begin() const { return Protocols.begin(); }
1335  qual_iterator qual_end() const   { return Protocols.end(); }
1336
1337  virtual void getAsStringInternal(std::string &InnerString) const;
1338
1339  void Profile(llvm::FoldingSetNodeID &ID);
1340  static void Profile(llvm::FoldingSetNodeID &ID,
1341                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1342
1343  static bool classof(const Type *T) {
1344    return T->getTypeClass() == ObjCQualifiedId;
1345  }
1346  static bool classof(const ObjCQualifiedIdType *) { return true; }
1347
1348};
1349
1350
1351// Inline function definitions.
1352
1353/// getUnqualifiedType - Return the type without any qualifiers.
1354inline QualType QualType::getUnqualifiedType() const {
1355  Type *TP = getTypePtr();
1356  if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP))
1357    TP = ASQT->getBaseType();
1358  return QualType(TP, 0);
1359}
1360
1361/// getAddressSpace - Return the address space of this type.
1362inline unsigned QualType::getAddressSpace() const {
1363  QualType CT = getTypePtr()->getCanonicalTypeInternal();
1364  if (const ArrayType *AT = dyn_cast<ArrayType>(CT))
1365    return AT->getElementType().getAddressSpace();
1366  if (const RecordType *RT = dyn_cast<RecordType>(CT))
1367    return RT->getAddressSpace();
1368  if (const ASQualType *ASQT = dyn_cast<ASQualType>(CT))
1369    return ASQT->getAddressSpace();
1370  return 0;
1371}
1372
1373inline const TypedefType* Type::getAsTypedefType() const {
1374  return dyn_cast<TypedefType>(this);
1375}
1376inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const {
1377  if (const PointerType *PT = getAsPointerType())
1378    return PT->getPointeeType()->getAsObjCInterfaceType();
1379  return 0;
1380}
1381
1382// NOTE: All of these methods use "getUnqualifiedType" to strip off address
1383// space qualifiers if present.
1384inline bool Type::isFunctionType() const {
1385  return isa<FunctionType>(CanonicalType.getUnqualifiedType());
1386}
1387inline bool Type::isPointerType() const {
1388  return isa<PointerType>(CanonicalType.getUnqualifiedType());
1389}
1390inline bool Type::isBlockPointerType() const {
1391    return isa<BlockPointerType>(CanonicalType);
1392}
1393inline bool Type::isReferenceType() const {
1394  return isa<ReferenceType>(CanonicalType.getUnqualifiedType());
1395}
1396inline bool Type::isPointerLikeType() const {
1397  return isa<PointerLikeType>(CanonicalType.getUnqualifiedType());
1398}
1399inline bool Type::isFunctionPointerType() const {
1400  if (const PointerType* T = getAsPointerType())
1401    return T->getPointeeType()->isFunctionType();
1402  else
1403    return false;
1404}
1405inline bool Type::isArrayType() const {
1406  return isa<ArrayType>(CanonicalType.getUnqualifiedType());
1407}
1408inline bool Type::isConstantArrayType() const {
1409  return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType());
1410}
1411inline bool Type::isIncompleteArrayType() const {
1412  return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType());
1413}
1414inline bool Type::isVariableArrayType() const {
1415  return isa<VariableArrayType>(CanonicalType.getUnqualifiedType());
1416}
1417inline bool Type::isRecordType() const {
1418  return isa<RecordType>(CanonicalType.getUnqualifiedType());
1419}
1420inline bool Type::isAnyComplexType() const {
1421  return isa<ComplexType>(CanonicalType.getUnqualifiedType());
1422}
1423inline bool Type::isVectorType() const {
1424  return isa<VectorType>(CanonicalType.getUnqualifiedType());
1425}
1426inline bool Type::isExtVectorType() const {
1427  return isa<ExtVectorType>(CanonicalType.getUnqualifiedType());
1428}
1429inline bool Type::isObjCInterfaceType() const {
1430  return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType());
1431}
1432inline bool Type::isObjCQualifiedInterfaceType() const {
1433  return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType());
1434}
1435inline bool Type::isObjCQualifiedIdType() const {
1436  return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType());
1437}
1438}  // end namespace clang
1439
1440#endif
1441