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