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