Type.h revision f81d921ec2f5bac3f35a94392fe2b764473884ee
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
366  /// getDesugaredType - Return the specified type with any "sugar" removed from
367  /// the type.  This takes off typedefs, typeof's etc.  If the outer level of
368  /// the type is already concrete, it returns it unmodified.  This is similar
369  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
370  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
371  /// concrete.
372  const Type *getDesugaredType() const;
373
374  /// More type predicates useful for type checking/promotion
375  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
376
377  /// isSignedIntegerType - Return true if this is an integer type that is
378  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
379  /// an enum decl which has a signed representation, or a vector of signed
380  /// integer element type.
381  bool isSignedIntegerType() const;
382
383  /// isUnsignedIntegerType - Return true if this is an integer type that is
384  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
385  /// decl which has an unsigned representation, or a vector of unsigned integer
386  /// element type.
387  bool isUnsignedIntegerType() const;
388
389  /// isConstantSizeType - Return true if this is not a variable sized type,
390  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
391  /// incomplete types.
392  bool isConstantSizeType() const;
393private:
394  QualType getCanonicalTypeInternal() const { return CanonicalType; }
395  friend class QualType;
396public:
397  virtual void getAsStringInternal(std::string &InnerString) const = 0;
398  static bool classof(const Type *) { return true; }
399
400protected:
401  /// Emit - Emit a Type to bitcode.  Used by ASTContext.
402  void Emit(llvm::Serializer& S) const;
403
404  /// Create - Construct a Type from bitcode.  Used by ASTContext.
405  static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S);
406
407  /// EmitImpl - Subclasses must implement this method in order to
408  ///  be serialized.
409  virtual void EmitImpl(llvm::Serializer& S) const;
410};
411
412/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26
413/// This supports address space qualified types.
414///
415class ASQualType : public Type, public llvm::FoldingSetNode {
416  /// BaseType - This is the underlying type that this qualifies.  All CVR
417  /// qualifiers are stored on the QualType that references this type, so we
418  /// can't have any here.
419  Type *BaseType;
420  /// Address Space ID - The address space ID this type is qualified with.
421  unsigned AddressSpace;
422  ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) :
423    Type(ASQual, CanonicalPtr), BaseType(Base), AddressSpace(AddrSpace) {
424  }
425  friend class ASTContext;  // ASTContext creates these.
426public:
427  Type *getBaseType() const { return BaseType; }
428  unsigned getAddressSpace() const { return AddressSpace; }
429
430  virtual void getAsStringInternal(std::string &InnerString) const;
431
432  void Profile(llvm::FoldingSetNodeID &ID) {
433    Profile(ID, getBaseType(), AddressSpace);
434  }
435  static void Profile(llvm::FoldingSetNodeID &ID, Type *Base,
436                      unsigned AddrSpace) {
437    ID.AddPointer(Base);
438    ID.AddInteger(AddrSpace);
439  }
440
441  static bool classof(const Type *T) { return T->getTypeClass() == ASQual; }
442  static bool classof(const ASQualType *) { return true; }
443
444protected:
445  virtual void EmitImpl(llvm::Serializer& S) const;
446  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
447  friend class Type;
448};
449
450
451/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
452/// types are always canonical and have a literal name field.
453class BuiltinType : public Type {
454public:
455  enum Kind {
456    Void,
457
458    Bool,     // This is bool and/or _Bool.
459    Char_U,   // This is 'char' for targets where char is unsigned.
460    UChar,    // This is explicitly qualified unsigned char.
461    UShort,
462    UInt,
463    ULong,
464    ULongLong,
465
466    Char_S,   // This is 'char' for targets where char is signed.
467    SChar,    // This is explicitly qualified signed char.
468    Short,
469    Int,
470    Long,
471    LongLong,
472
473    Float, Double, LongDouble
474  };
475private:
476  Kind TypeKind;
477public:
478  BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {}
479
480  Kind getKind() const { return TypeKind; }
481  const char *getName() const;
482
483  virtual void getAsStringInternal(std::string &InnerString) const;
484
485  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
486  static bool classof(const BuiltinType *) { return true; }
487};
488
489/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
490/// types (_Complex float etc) as well as the GCC integer complex extensions.
491///
492class ComplexType : public Type, public llvm::FoldingSetNode {
493  QualType ElementType;
494  ComplexType(QualType Element, QualType CanonicalPtr) :
495    Type(Complex, CanonicalPtr), ElementType(Element) {
496  }
497  friend class ASTContext;  // ASTContext creates these.
498public:
499  QualType getElementType() const { return ElementType; }
500
501  virtual void getAsStringInternal(std::string &InnerString) const;
502
503  void Profile(llvm::FoldingSetNodeID &ID) {
504    Profile(ID, getElementType());
505  }
506  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
507    ID.AddPointer(Element.getAsOpaquePtr());
508  }
509
510  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
511  static bool classof(const ComplexType *) { return true; }
512
513protected:
514  virtual void EmitImpl(llvm::Serializer& S) const;
515  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
516  friend class Type;
517};
518
519/// PointerLikeType - Common base class for pointers and references.
520///
521class PointerLikeType : public Type {
522  QualType PointeeType;
523protected:
524  PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) :
525    Type(K, CanonicalPtr), PointeeType(Pointee) {
526  }
527public:
528
529  QualType getPointeeType() const { return PointeeType; }
530
531  static bool classof(const Type *T) {
532    return T->getTypeClass() == Pointer || T->getTypeClass() == Reference;
533  }
534  static bool classof(const PointerLikeType *) { return true; }
535};
536
537/// PointerType - C99 6.7.5.1 - Pointer Declarators.
538///
539class PointerType : public PointerLikeType, public llvm::FoldingSetNode {
540  PointerType(QualType Pointee, QualType CanonicalPtr) :
541    PointerLikeType(Pointer, Pointee, CanonicalPtr) {
542  }
543  friend class ASTContext;  // ASTContext creates these.
544public:
545
546  virtual void getAsStringInternal(std::string &InnerString) const;
547
548  void Profile(llvm::FoldingSetNodeID &ID) {
549    Profile(ID, getPointeeType());
550  }
551  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
552    ID.AddPointer(Pointee.getAsOpaquePtr());
553  }
554
555  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
556  static bool classof(const PointerType *) { return true; }
557
558protected:
559  virtual void EmitImpl(llvm::Serializer& S) const;
560  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
561  friend class Type;
562};
563
564/// ReferenceType - C++ 8.3.2 - Reference Declarators.
565///
566class ReferenceType : public PointerLikeType, public llvm::FoldingSetNode {
567  ReferenceType(QualType Referencee, QualType CanonicalRef) :
568    PointerLikeType(Reference, Referencee, CanonicalRef) {
569  }
570  friend class ASTContext;  // ASTContext creates these.
571public:
572  virtual void getAsStringInternal(std::string &InnerString) const;
573
574  void Profile(llvm::FoldingSetNodeID &ID) {
575    Profile(ID, getPointeeType());
576  }
577  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
578    ID.AddPointer(Referencee.getAsOpaquePtr());
579  }
580
581  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
582  static bool classof(const ReferenceType *) { return true; }
583};
584
585/// ArrayType - C99 6.7.5.2 - Array Declarators.
586///
587class ArrayType : public Type, public llvm::FoldingSetNode {
588public:
589  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
590  /// an array with a static size (e.g. int X[static 4]), or with a star size
591  /// (e.g. int X[*]). 'static' is only allowed on function parameters.
592  enum ArraySizeModifier {
593    Normal, Static, Star
594  };
595private:
596  /// ElementType - The element type of the array.
597  QualType ElementType;
598
599  // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum
600  /// NOTE: These fields are packed into the bitfields space in the Type class.
601  unsigned SizeModifier : 2;
602
603  /// IndexTypeQuals - Capture qualifiers in declarations like:
604  /// 'int X[static restrict 4]'. For function parameters only.
605  unsigned IndexTypeQuals : 3;
606
607protected:
608  ArrayType(TypeClass tc, QualType et, QualType can,
609            ArraySizeModifier sm, unsigned tq)
610    : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
611  friend class ASTContext;  // ASTContext creates these.
612public:
613  QualType getElementType() const { return ElementType; }
614  ArraySizeModifier getSizeModifier() const {
615    return ArraySizeModifier(SizeModifier);
616  }
617  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
618
619  QualType getBaseType() const {
620    const ArrayType *AT;
621    QualType ElmtType = getElementType();
622    // If we have a multi-dimensional array, navigate to the base type.
623    while ((AT = ElmtType->getAsArrayType()))
624      ElmtType = AT->getElementType();
625    return ElmtType;
626  }
627  static bool classof(const Type *T) {
628    return T->getTypeClass() == ConstantArray ||
629           T->getTypeClass() == VariableArray ||
630           T->getTypeClass() == IncompleteArray;
631  }
632  static bool classof(const ArrayType *) { return true; }
633};
634
635/// ConstantArrayType - This class represents C arrays with a specified constant
636/// size.  For example 'int A[100]' has ConstantArrayType where the element type
637/// is 'int' and the size is 100.
638class ConstantArrayType : public ArrayType {
639  llvm::APInt Size; // Allows us to unique the type.
640
641  ConstantArrayType(QualType et, QualType can, llvm::APInt sz,
642                    ArraySizeModifier sm, unsigned tq)
643    : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {}
644  friend class ASTContext;  // ASTContext creates these.
645public:
646  llvm::APInt getSize() const { return Size; }
647  int getMaximumElements() const {
648    QualType ElmtType = getElementType();
649    int maxElements = static_cast<int>(getSize().getZExtValue());
650
651    const ConstantArrayType *CAT;
652    // If we have a multi-dimensional array, include it's elements.
653    while ((CAT = ElmtType->getAsConstantArrayType())) {
654      ElmtType = CAT->getElementType();
655      maxElements *= static_cast<int>(CAT->getSize().getZExtValue());
656    }
657    return maxElements;
658  }
659  virtual void getAsStringInternal(std::string &InnerString) const;
660
661  void Profile(llvm::FoldingSetNodeID &ID) {
662    Profile(ID, getElementType(), getSize());
663  }
664  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
665                      llvm::APInt ArraySize) {
666    ID.AddPointer(ET.getAsOpaquePtr());
667    ID.AddInteger(ArraySize.getZExtValue());
668  }
669  static bool classof(const Type *T) {
670    return T->getTypeClass() == ConstantArray;
671  }
672  static bool classof(const ConstantArrayType *) { return true; }
673
674protected:
675  virtual void EmitImpl(llvm::Serializer& S) const;
676  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
677  friend class Type;
678};
679
680/// IncompleteArrayType - This class represents C arrays with an unspecified
681/// size.  For example 'int A[]' has an IncompleteArrayType where the element
682/// type is 'int' and the size is unspecified.
683class IncompleteArrayType : public ArrayType {
684  IncompleteArrayType(QualType et, QualType can,
685                    ArraySizeModifier sm, unsigned tq)
686    : ArrayType(IncompleteArray, et, can, sm, tq) {}
687  friend class ASTContext;  // ASTContext creates these.
688public:
689
690  virtual void getAsStringInternal(std::string &InnerString) const;
691
692  static bool classof(const Type *T) {
693    return T->getTypeClass() == IncompleteArray;
694  }
695  static bool classof(const IncompleteArrayType *) { return true; }
696
697  friend class StmtIteratorBase;
698
699  void Profile(llvm::FoldingSetNodeID &ID) {
700    Profile(ID, getElementType());
701  }
702
703  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) {
704    ID.AddPointer(ET.getAsOpaquePtr());
705  }
706
707protected:
708  virtual void EmitImpl(llvm::Serializer& S) const;
709  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
710  friend class Type;
711};
712
713/// VariableArrayType - This class represents C arrays with a specified size
714/// which is not an integer-constant-expression.  For example, 'int s[x+foo()]'.
715/// Since the size expression is an arbitrary expression, we store it as such.
716///
717/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
718/// should not be: two lexically equivalent variable array types could mean
719/// different things, for example, these variables do not have the same type
720/// dynamically:
721///
722/// void foo(int x) {
723///   int Y[x];
724///   ++x;
725///   int Z[x];
726/// }
727///
728class VariableArrayType : public ArrayType {
729  /// SizeExpr - An assignment expression. VLA's are only permitted within
730  /// a function block.
731  Stmt *SizeExpr;
732
733  VariableArrayType(QualType et, QualType can, Expr *e,
734                    ArraySizeModifier sm, unsigned tq)
735    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
736  friend class ASTContext;  // ASTContext creates these.
737  virtual void Destroy(ASTContext& C);
738
739public:
740  const Expr *getSizeExpr() const {
741    // We use C-style casts instead of cast<> here because we do not wish
742    // to have a dependency of Type.h on Stmt.h/Expr.h.
743    return (Expr*) SizeExpr;
744  }
745
746  virtual void getAsStringInternal(std::string &InnerString) const;
747
748  static bool classof(const Type *T) {
749    return T->getTypeClass() == VariableArray;
750  }
751  static bool classof(const VariableArrayType *) { return true; }
752
753  friend class StmtIteratorBase;
754
755  void Profile(llvm::FoldingSetNodeID &ID) {
756    assert (0 && "Cannnot unique VariableArrayTypes.");
757  }
758
759protected:
760  virtual void EmitImpl(llvm::Serializer& S) const;
761  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
762  friend class Type;
763};
764
765/// VectorType - GCC generic vector type. This type is created using
766/// __attribute__((vector_size(n)), where "n" specifies the vector size in
767/// bytes. Since the constructor takes the number of vector elements, the
768/// client is responsible for converting the size into the number of elements.
769class VectorType : public Type, public llvm::FoldingSetNode {
770protected:
771  /// ElementType - The element type of the vector.
772  QualType ElementType;
773
774  /// NumElements - The number of elements in the vector.
775  unsigned NumElements;
776
777  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
778    Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {}
779  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
780    QualType canonType) : Type(tc, canonType), ElementType(vecType),
781    NumElements(nElements) {}
782  friend class ASTContext;  // ASTContext creates these.
783public:
784
785  QualType getElementType() const { return ElementType; }
786  unsigned getNumElements() const { return NumElements; }
787
788  virtual void getAsStringInternal(std::string &InnerString) const;
789
790  void Profile(llvm::FoldingSetNodeID &ID) {
791    Profile(ID, getElementType(), getNumElements(), getTypeClass());
792  }
793  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
794                      unsigned NumElements, TypeClass TypeClass) {
795    ID.AddPointer(ElementType.getAsOpaquePtr());
796    ID.AddInteger(NumElements);
797    ID.AddInteger(TypeClass);
798  }
799  static bool classof(const Type *T) {
800    return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
801  }
802  static bool classof(const VectorType *) { return true; }
803};
804
805/// ExtVectorType - Extended vector type. This type is created using
806/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
807/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
808/// class enables syntactic extensions, like Vector Components for accessing
809/// points, colors, and textures (modeled after OpenGL Shading Language).
810class ExtVectorType : public VectorType {
811  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) :
812    VectorType(ExtVector, vecType, nElements, canonType) {}
813  friend class ASTContext;  // ASTContext creates these.
814public:
815  static int getPointAccessorIdx(char c) {
816    switch (c) {
817    default: return -1;
818    case 'x': return 0;
819    case 'y': return 1;
820    case 'z': return 2;
821    case 'w': return 3;
822    }
823  }
824  static int getColorAccessorIdx(char c) {
825    switch (c) {
826    default: return -1;
827    case 'r': return 0;
828    case 'g': return 1;
829    case 'b': return 2;
830    case 'a': return 3;
831    }
832  }
833  static int getTextureAccessorIdx(char c) {
834    switch (c) {
835    default: return -1;
836    case 's': return 0;
837    case 't': return 1;
838    case 'p': return 2;
839    case 'q': return 3;
840    }
841  };
842
843  static int getAccessorIdx(char c) {
844    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
845    if (int idx = getColorAccessorIdx(c)+1) return idx-1;
846    return getTextureAccessorIdx(c);
847  }
848
849  bool isAccessorWithinNumElements(char c) const {
850    if (int idx = getAccessorIdx(c)+1)
851      return unsigned(idx-1) < NumElements;
852    return false;
853  }
854  virtual void getAsStringInternal(std::string &InnerString) const;
855
856  static bool classof(const Type *T) {
857    return T->getTypeClass() == ExtVector;
858  }
859  static bool classof(const ExtVectorType *) { return true; }
860};
861
862/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
863/// class of FunctionTypeNoProto and FunctionTypeProto.
864///
865class FunctionType : public Type {
866  /// SubClassData - This field is owned by the subclass, put here to pack
867  /// tightly with the ivars in Type.
868  bool SubClassData : 1;
869
870  // The type returned by the function.
871  QualType ResultType;
872protected:
873  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical)
874    : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {}
875  bool getSubClassData() const { return SubClassData; }
876public:
877
878  QualType getResultType() const { return ResultType; }
879
880
881  static bool classof(const Type *T) {
882    return T->getTypeClass() == FunctionNoProto ||
883           T->getTypeClass() == FunctionProto;
884  }
885  static bool classof(const FunctionType *) { return true; }
886};
887
888/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
889/// no information available about its arguments.
890class FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
891  FunctionTypeNoProto(QualType Result, QualType Canonical)
892    : FunctionType(FunctionNoProto, Result, false, Canonical) {}
893  friend class ASTContext;  // ASTContext creates these.
894public:
895  // No additional state past what FunctionType provides.
896
897  virtual void getAsStringInternal(std::string &InnerString) const;
898
899  void Profile(llvm::FoldingSetNodeID &ID) {
900    Profile(ID, getResultType());
901  }
902  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
903    ID.AddPointer(ResultType.getAsOpaquePtr());
904  }
905
906  static bool classof(const Type *T) {
907    return T->getTypeClass() == FunctionNoProto;
908  }
909  static bool classof(const FunctionTypeNoProto *) { return true; }
910
911protected:
912  virtual void EmitImpl(llvm::Serializer& S) const;
913  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
914  friend class Type;
915};
916
917/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
918/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
919/// arguments, not as having a single void argument.
920class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
921  FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs,
922                    bool isVariadic, QualType Canonical)
923    : FunctionType(FunctionProto, Result, isVariadic, Canonical),
924      NumArgs(numArgs) {
925    // Fill in the trailing argument array.
926    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
927    for (unsigned i = 0; i != numArgs; ++i)
928      ArgInfo[i] = ArgArray[i];
929  }
930
931  /// NumArgs - The number of arguments this function has, not counting '...'.
932  unsigned NumArgs;
933
934  /// ArgInfo - There is an variable size array after the class in memory that
935  /// holds the argument types.
936
937  friend class ASTContext;  // ASTContext creates these.
938  virtual void Destroy(ASTContext& C);
939
940public:
941  unsigned getNumArgs() const { return NumArgs; }
942  QualType getArgType(unsigned i) const {
943    assert(i < NumArgs && "Invalid argument number!");
944    return arg_type_begin()[i];
945  }
946
947  bool isVariadic() const { return getSubClassData(); }
948
949  typedef const QualType *arg_type_iterator;
950  arg_type_iterator arg_type_begin() const {
951    return reinterpret_cast<const QualType *>(this+1);
952  }
953  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
954
955  virtual void getAsStringInternal(std::string &InnerString) const;
956
957  static bool classof(const Type *T) {
958    return T->getTypeClass() == FunctionProto;
959  }
960  static bool classof(const FunctionTypeProto *) { return true; }
961
962  void Profile(llvm::FoldingSetNodeID &ID);
963  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
964                      arg_type_iterator ArgTys, unsigned NumArgs,
965                      bool isVariadic);
966
967protected:
968  virtual void EmitImpl(llvm::Serializer& S) const;
969  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
970  friend class Type;
971};
972
973
974class TypedefType : public Type {
975  TypedefDecl *Decl;
976protected:
977  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
978    : Type(tc, can), Decl(D) {
979    assert(!isa<TypedefType>(can) && "Invalid canonical type");
980  }
981  friend class ASTContext;  // ASTContext creates these.
982public:
983
984  TypedefDecl *getDecl() const { return Decl; }
985
986  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
987  /// potentially looking through *all* consequtive typedefs.  This returns the
988  /// sum of the type qualifiers, so if you have:
989  ///   typedef const int A;
990  ///   typedef volatile A B;
991  /// looking through the typedefs for B will give you "const volatile A".
992  QualType LookThroughTypedefs() const;
993
994  virtual void getAsStringInternal(std::string &InnerString) const;
995
996  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
997  static bool classof(const TypedefType *) { return true; }
998
999protected:
1000  virtual void EmitImpl(llvm::Serializer& S) const;
1001  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
1002  friend class Type;
1003};
1004
1005/// TypeOfExpr (GCC extension).
1006class TypeOfExpr : public Type {
1007  Expr *TOExpr;
1008  TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) {
1009    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1010  }
1011  friend class ASTContext;  // ASTContext creates these.
1012public:
1013  Expr *getUnderlyingExpr() const { return TOExpr; }
1014
1015  virtual void getAsStringInternal(std::string &InnerString) const;
1016
1017  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
1018  static bool classof(const TypeOfExpr *) { return true; }
1019};
1020
1021/// TypeOfType (GCC extension).
1022class TypeOfType : public Type {
1023  QualType TOType;
1024  TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) {
1025    assert(!isa<TypedefType>(can) && "Invalid canonical type");
1026  }
1027  friend class ASTContext;  // ASTContext creates these.
1028public:
1029  QualType getUnderlyingType() const { return TOType; }
1030
1031  virtual void getAsStringInternal(std::string &InnerString) const;
1032
1033  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
1034  static bool classof(const TypeOfType *) { return true; }
1035};
1036
1037class TagType : public Type {
1038  TagDecl *decl;
1039
1040protected:
1041  TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {}
1042
1043public:
1044  TagDecl *getDecl() const { return decl; }
1045
1046  virtual void getAsStringInternal(std::string &InnerString) const;
1047
1048  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
1049  static bool classof(const TagType *) { return true; }
1050
1051protected:
1052  virtual void EmitImpl(llvm::Serializer& S) const;
1053  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
1054  friend class Type;
1055};
1056
1057/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
1058/// to detect TagType objects of structs/unions/classes.
1059class RecordType : public TagType {
1060  explicit RecordType(RecordDecl *D) : TagType(cast<TagDecl>(D), QualType()) { }
1061  friend class ASTContext;   // ASTContext creates these.
1062public:
1063
1064  RecordDecl *getDecl() const {
1065    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
1066  }
1067
1068  // FIXME: This predicate is a helper to QualType/Type. It needs to
1069  // recursively check all fields for const-ness. If any field is declared
1070  // const, it needs to return false.
1071  bool hasConstFields() const { return false; }
1072
1073  // FIXME: RecordType needs to check when it is created that all fields are in
1074  // the same address space, and return that.
1075  unsigned getAddressSpace() const { return 0; }
1076
1077  static bool classof(const TagType *T);
1078  static bool classof(const Type *T) {
1079    return isa<TagType>(T) && classof(cast<TagType>(T));
1080  }
1081  static bool classof(const RecordType *) { return true; }
1082};
1083
1084/// EnumType - This is a helper class that allows the use of isa/cast/dyncast
1085/// to detect TagType objects of enums.
1086class EnumType : public TagType {
1087  explicit EnumType(EnumDecl *D) : TagType(cast<TagDecl>(D), QualType()) { }
1088  friend class ASTContext;   // ASTContext creates these.
1089public:
1090
1091  EnumDecl *getDecl() const {
1092    return reinterpret_cast<EnumDecl*>(TagType::getDecl());
1093  }
1094
1095  static bool classof(const TagType *T);
1096  static bool classof(const Type *T) {
1097    return isa<TagType>(T) && classof(cast<TagType>(T));
1098  }
1099  static bool classof(const EnumType *) { return true; }
1100};
1101
1102
1103
1104/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for
1105/// object oriented design.  They basically correspond to C++ classes.  There
1106/// are two kinds of interface types, normal interfaces like "NSString" and
1107/// qualified interfaces, which are qualified with a protocol list like
1108/// "NSString<NSCopyable, NSAmazing>".  Qualified interface types are instances
1109/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType.
1110class ObjCInterfaceType : public Type {
1111  ObjCInterfaceDecl *Decl;
1112protected:
1113  ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) :
1114    Type(tc, QualType()), Decl(D) { }
1115  friend class ASTContext;  // ASTContext creates these.
1116public:
1117
1118  ObjCInterfaceDecl *getDecl() const { return Decl; }
1119
1120  /// qual_iterator and friends: this provides access to the (potentially empty)
1121  /// list of protocols qualifying this interface.  If this is an instance of
1122  /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an
1123  /// empty list if there are no qualifying protocols.
1124  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1125  inline qual_iterator qual_begin() const;
1126  inline qual_iterator qual_end() const;
1127  bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; }
1128
1129  /// getNumProtocols - Return the number of qualifying protocols in this
1130  /// interface type, or 0 if there are none.
1131  inline unsigned getNumProtocols() const;
1132
1133  /// getProtocols - Return the specified qualifying protocol.
1134  inline ObjCProtocolDecl *getProtocols(unsigned i) const;
1135
1136
1137
1138  virtual void getAsStringInternal(std::string &InnerString) const;
1139  static bool classof(const Type *T) {
1140    return T->getTypeClass() == ObjCInterface ||
1141           T->getTypeClass() == ObjCQualifiedInterface;
1142  }
1143  static bool classof(const ObjCInterfaceType *) { return true; }
1144};
1145
1146/// ObjCQualifiedInterfaceType - This class represents interface types
1147/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>.
1148///
1149/// Duplicate protocols are removed and protocol list is canonicalized to be in
1150/// alphabetical order.
1151class ObjCQualifiedInterfaceType : public ObjCInterfaceType,
1152                                   public llvm::FoldingSetNode {
1153
1154  // List of protocols for this protocol conforming object type
1155  // List is sorted on protocol name. No protocol is enterred more than once.
1156  llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols;
1157
1158  ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
1159                             ObjCProtocolDecl **Protos, unsigned NumP) :
1160    ObjCInterfaceType(ObjCQualifiedInterface, D),
1161    Protocols(Protos, Protos+NumP) { }
1162  friend class ASTContext;  // ASTContext creates these.
1163public:
1164
1165  ObjCProtocolDecl *getProtocols(unsigned i) const {
1166    return Protocols[i];
1167  }
1168  unsigned getNumProtocols() const {
1169    return Protocols.size();
1170  }
1171
1172  qual_iterator qual_begin() const { return Protocols.begin(); }
1173  qual_iterator qual_end() const   { return Protocols.end(); }
1174
1175  virtual void getAsStringInternal(std::string &InnerString) const;
1176
1177  void Profile(llvm::FoldingSetNodeID &ID);
1178  static void Profile(llvm::FoldingSetNodeID &ID,
1179                      const ObjCInterfaceDecl *Decl,
1180                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1181
1182  static bool classof(const Type *T) {
1183    return T->getTypeClass() == ObjCQualifiedInterface;
1184  }
1185  static bool classof(const ObjCQualifiedInterfaceType *) { return true; }
1186};
1187
1188inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const {
1189  if (const ObjCQualifiedInterfaceType *QIT =
1190         dyn_cast<ObjCQualifiedInterfaceType>(this))
1191    return QIT->qual_begin();
1192  return 0;
1193}
1194inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const {
1195  if (const ObjCQualifiedInterfaceType *QIT =
1196         dyn_cast<ObjCQualifiedInterfaceType>(this))
1197    return QIT->qual_end();
1198  return 0;
1199}
1200
1201/// getNumProtocols - Return the number of qualifying protocols in this
1202/// interface type, or 0 if there are none.
1203inline unsigned ObjCInterfaceType::getNumProtocols() const {
1204  if (const ObjCQualifiedInterfaceType *QIT =
1205        dyn_cast<ObjCQualifiedInterfaceType>(this))
1206    return QIT->getNumProtocols();
1207  return 0;
1208}
1209
1210/// getProtocols - Return the specified qualifying protocol.
1211inline ObjCProtocolDecl *ObjCInterfaceType::getProtocols(unsigned i) const {
1212  return cast<ObjCQualifiedInterfaceType>(this)->getProtocols(i);
1213}
1214
1215
1216
1217/// ObjCQualifiedIdType - to represent id<protocol-list>.
1218///
1219/// Duplicate protocols are removed and protocol list is canonicalized to be in
1220/// alphabetical order.
1221class ObjCQualifiedIdType : public Type,
1222                            public llvm::FoldingSetNode {
1223  // List of protocols for this protocol conforming 'id' type
1224  // List is sorted on protocol name. No protocol is enterred more than once.
1225  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
1226
1227  ObjCQualifiedIdType(QualType can, ObjCProtocolDecl **Protos,  unsigned NumP)
1228  : Type(ObjCQualifiedId, can),
1229  Protocols(Protos, Protos+NumP) { }
1230  friend class ASTContext;  // ASTContext creates these.
1231public:
1232
1233  ObjCProtocolDecl *getProtocols(unsigned i) const {
1234    return Protocols[i];
1235  }
1236  unsigned getNumProtocols() const {
1237    return Protocols.size();
1238  }
1239  ObjCProtocolDecl **getReferencedProtocols() {
1240    return &Protocols[0];
1241  }
1242
1243  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
1244  qual_iterator qual_begin() const { return Protocols.begin(); }
1245  qual_iterator qual_end() const   { return Protocols.end(); }
1246
1247  virtual void getAsStringInternal(std::string &InnerString) const;
1248
1249  void Profile(llvm::FoldingSetNodeID &ID);
1250  static void Profile(llvm::FoldingSetNodeID &ID,
1251                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
1252
1253  static bool classof(const Type *T) {
1254    return T->getTypeClass() == ObjCQualifiedId;
1255  }
1256  static bool classof(const ObjCQualifiedIdType *) { return true; }
1257
1258};
1259
1260
1261// Inline function definitions.
1262
1263/// getCanonicalType - Return the canonical version of this type, with the
1264/// appropriate type qualifiers on it.
1265inline QualType QualType::getCanonicalType() const {
1266  QualType CanType = getTypePtr()->getCanonicalTypeInternal();
1267  return QualType(CanType.getTypePtr(),
1268                  getCVRQualifiers() | CanType.getCVRQualifiers());
1269}
1270
1271/// getUnqualifiedType - Return the type without any qualifiers.
1272inline QualType QualType::getUnqualifiedType() const {
1273  Type *TP = getTypePtr();
1274  if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP))
1275    TP = ASQT->getBaseType();
1276  return QualType(TP, 0);
1277}
1278
1279/// getAddressSpace - Return the address space of this type.
1280inline unsigned QualType::getAddressSpace() const {
1281  if (const ArrayType *AT = dyn_cast<ArrayType>(getCanonicalType()))
1282    return AT->getBaseType().getAddressSpace();
1283  if (const RecordType *RT = dyn_cast<RecordType>(getCanonicalType()))
1284    return RT->getAddressSpace();
1285  if (const ASQualType *ASQT = dyn_cast<ASQualType>(getCanonicalType()))
1286    return ASQT->getAddressSpace();
1287  return 0;
1288}
1289
1290inline const TypedefType* Type::getAsTypedefType() const {
1291  return dyn_cast<TypedefType>(this);
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