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