Type.h revision fb22d96692c5240fb8d611290dbf7eeed3759c73
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
55f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file was developed by Chris Lattner and is distributed under
65f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// the University of Illinois Open Source License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Type interface and subclasses.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/FoldingSet.h"
19fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h"
205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Type;
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
363acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner  class PointerType;
37251dcaf8616c6f04051e214f35cadb7de42aef7eBill Wendling  class ReferenceType;
383acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner  class VectorType;
39700204c74b455746752e851b25565ebf932f5340Steve Naroff  class ArrayType;
40dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  class RecordType;
41c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  class ComplexType;
427064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class TagType;
437064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class FunctionType;
447064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class OCUVectorType;
4577878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  class BuiltinType;
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers.  This
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int',
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc).
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer.  To handle the
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer.
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType {
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  uintptr_t ThePtr;
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CVRFlags = Const|Restrict|Volatile
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType() : ThePtr(0) {}
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType(Type *Ptr, unsigned Quals) {
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ThePtr = reinterpret_cast<uintptr_t>(Ptr);
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ThePtr |= Quals;
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getQualifiers() const {
835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr & CVRFlags;
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *getTypePtr() const {
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<Type*>(ThePtr & ~CVRFlags);
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void *getAsOpaquePtr() const {
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<void*>(ThePtr);
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr == 0;
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isConstQualified() const {
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr & Const;
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVolatileQualified() const {
1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr & Volatile;
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRestrictQualified() const {
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr & Restrict;
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1157effa1aceac1219529af23c776835f855b8d905cChris Lattner
1167effa1aceac1219529af23c776835f855b8d905cChris Lattner  /// addConst/addVolatile/addRestrict - add the specified type qual to this
1177effa1aceac1219529af23c776835f855b8d905cChris Lattner  /// QualType.
1187effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addConst()    { ThePtr |= Const; }
1197effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addVolatile() { ThePtr |= Volatile; }
1207effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addRestrict() { ThePtr |= Restrict; }
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getQualifiedType(unsigned TQs) const {
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return QualType(getTypePtr(), TQs);
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getUnqualifiedType() const {
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return QualType(getTypePtr(), 0);
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool operator==(const QualType &RHS) const {
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr == RHS.ThePtr;
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool operator!=(const QualType &RHS) const {
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr != RHS.ThePtr;
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::string getAsString() const {
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    getAsStringInternal(S);
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void getAsStringInternal(std::string &Str) const;
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void dump(const char *s = 0) const;
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getCanonicalType - Return the canonical version of this type, with the
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// appropriate type qualifiers on it.
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  inline QualType getCanonicalType() const;
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Val.getTypePtr();
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// TypeNameType).  Its CanonicalType pointer points to the 'int' Type.  Next
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type {
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
199fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Builtin, Complex, Pointer, Reference,
200fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ConstantArray, VariableArray,
201fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Vector, OCUVector,
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FunctionNoProto, FunctionProto,
203d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    TypeName, Tagged,
204d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    TypeOfExp, TypeOfTyp // GNU typeof extension.
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Note that this should stay at the end of the ivars for Type so that
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// subclasses can pack their bitfields into the same word.
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeClass TC : 4;
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type(TypeClass tc, QualType Canonical)
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : CanonicalType(Canonical.isNull() ? QualType(this,0) : Canonical), TC(tc){}
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual ~Type();
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
2188b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeClass getTypeClass() const { return TC; }
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isObjectType - types that fully describe objects. An object is a region
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of memory that can be examined and stored into (H&S).
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isObjectType() const;
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// routine will need to determine if the size is actually required.
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operate on the canonical type, ignoring typedefs.
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
23913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
24013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
24113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
249c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
250c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
251c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
252c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
254c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
255c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // type, ignoring typedefs.
256c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
257befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
258a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
259c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
260c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
261c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isStructureType() const;
262c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isUnionType() const;
263c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVectorType() const; // GCC vector type.
264c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isOCUVectorType() const; // OCU vector type.
265c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner
266c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
267c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // specified type, ignoring typedefs, and return a pointer to the best type
268c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // we can.
26977878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  const BuiltinType *getAsBuiltinType() const;
270c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const FunctionType *getAsFunctionType() const;
271befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  const PointerType *getAsPointerType() const;
272a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  const ReferenceType *getAsReferenceType() const;
273c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const ArrayType *getAsArrayType() const;
274c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsRecordType() const;
275c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsStructureType() const;
276c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
277c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const VectorType *getAsVectorType() const; // GCC vector type.
278c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  const ComplexType *getAsComplexType() const;
279c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
285d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
286d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
287d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
291d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
292d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
293d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
295d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// according to the rules of C99 6.7.5p3.  If Loc is non-null, it is set to
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the location of the subexpression that makes it a vla type.  It is not
2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// legal to call this on incomplete types.
300590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isConstantSizeType(ASTContext &Ctx, SourceLocation *Loc = 0) const;
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Compatibility predicates used to check assignment expressions.
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool tagTypesAreCompatible(QualType, QualType); // C99 6.2.7p1
3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool pointerTypesAreCompatible(QualType, QualType);  // C99 6.7.5.1p2
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
30977878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  static bool builtinTypesAreCompatible(QualType, QualType);
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getCanonicalTypeInternal() const { return CanonicalType; }
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class QualType;
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const = 0;
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Float, Double, LongDouble
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind TypeKind;
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {}
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind getKind() const { return TypeKind; }
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Complex, CanonicalPtr), ElementType(Element) {
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PointerType - C99 6.7.5.1 - Pointer Declarators.
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PointerType : public Type, public llvm::FoldingSetNode {
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType PointeeType;
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Pointer, CanonicalPtr), PointeeType(Pointee) {
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getPointeeType() const { return PointeeType; }
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ReferenceType - C++ 8.3.2 - Reference Declarators.
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReferenceType : public Type, public llvm::FoldingSetNode {
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ReferenceeType;
4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ReferenceType(QualType Referencee, QualType CanonicalRef) :
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Reference, CanonicalRef), ReferenceeType(Referencee) {
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getReferenceeType() const { return ReferenceeType; }
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getReferenceeType());
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
436fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass ArrayType : public Type {
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an array with a static size (e.g. int X[static 4]), or with a star size
440fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// (e.g. int X[*]). FIXME: consider moving this down to VLAArayType.
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
445fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
446fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
447fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
448fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can)
449fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    : Type(tc, can), ElementType(et) {}
450fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
451fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
452fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
453fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
454fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
455fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
456fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff           T->getTypeClass() == VariableArray;
457fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
458fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
459fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
460fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
461fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass ConstantArrayType : public ArrayType, public llvm::FoldingSetNode {
462fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
463fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
464fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  ConstantArrayType(QualType et, QualType can, llvm::APInt sz)
465fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    : ArrayType(ConstantArray, et, can), Size(sz) {}
466fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
467fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
468fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt getSize() const { return Size; }
469fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
470fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
471fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
472fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
473fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Profile(ID, getElementType(), getSize());
474fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
475fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
476fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff                      llvm::APInt ArraySize) {
477fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
478fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
479fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
480fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
481fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray;
482fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
483fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
484fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
485fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
486fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff// FIXME: VariableArrayType's aren't uniqued (since expressions aren't).
487fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass VariableArrayType : public ArrayType {
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NOTE: These fields are packed into the bitfields space in the Type class.
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ArraySizeModifier SizeModifier : 2;
4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// IndexTypeQuals - Capture qualifiers in declarations like:
4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// 'int X[static restrict 4]'.
4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned IndexTypeQuals : 3;
4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
495fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// SizeExpr - An assignment expression. VLA's are only permitted within
496fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// a function block.
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *SizeExpr;
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
499fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  VariableArrayType(QualType et, ArraySizeModifier sm, unsigned tq,
500fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff                          QualType can, Expr *e)
501fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    : ArrayType(VariableArray, et, can),
502fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff      SizeModifier(sm), IndexTypeQuals(tq), SizeExpr(e) {}
5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ArraySizeModifier getSizeModifier() const { return SizeModifier; }
5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
5078b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  Expr *getSizeExpr() const { return SizeExpr; }
5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
511fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
512fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == VariableArray;
5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
514fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
51773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
51873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in
51973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the
52073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
52273322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumElements - The number of elements in the vector.
5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumElements;
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
52973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
53073322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {}
53173322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
53273322924127c873c13101b705dd823f5539ffa5fSteve Naroff    QualType canonType) : Type(tc, canonType), ElementType(vecType),
53373322924127c873c13101b705dd823f5539ffa5fSteve Naroff    NumElements(nElements) {}
5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumElements() const { return NumElements; }
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
54373322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Profile(ID, getElementType(), getNumElements(), getTypeClass());
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
54573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
54673322924127c873c13101b705dd823f5539ffa5fSteve Naroff                      unsigned NumElements, TypeClass TypeClass) {
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
54973322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
55073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
55173322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const Type *T) {
55273322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
55773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// OCUVectorType - Extended vector type. This type is created using
55873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((ocu_vector_type(n)), where "n" is the number of elements.
559fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// Unlike vector_size, ocu_vector_type is only allowed on typedef's. This
560fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
561fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
56273322924127c873c13101b705dd823f5539ffa5fSteve Naroffclass OCUVectorType : public VectorType {
56373322924127c873c13101b705dd823f5539ffa5fSteve Naroff  OCUVectorType(QualType vecType, unsigned nElements, QualType canonType) :
56473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    VectorType(OCUVector, vecType, nElements, canonType) {}
56573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
56673322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
56788dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
56888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
56988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
57088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
57188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
57288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
57388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
57488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
575e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
57688dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getColorAccessorIdx(char c) {
57788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
57888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
57988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'r': return 0;
58088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'g': return 1;
58188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'b': return 2;
58288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'a': return 3;
58388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
584e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
58588dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getTextureAccessorIdx(char c) {
58688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
58788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
58888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 's': return 0;
58988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 't': return 1;
59088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'p': return 2;
59188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'q': return 3;
592e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff    }
59388dca0464804b8b26ae605f89784c927e8493dddChris Lattner  };
594b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
595b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
596b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
597b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getColorAccessorIdx(c)+1) return idx-1;
598b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    return getTextureAccessorIdx(c);
599b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
600b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
60188dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
602b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
60388dca0464804b8b26ae605f89784c927e8493dddChris Lattner      return unsigned(idx-1) < NumElements;
60488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
605e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
60631a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
60731a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
6087064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  static bool classof(const Type *T) {
60973322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == OCUVector;
61073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
61173322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const OCUVectorType *) { return true; }
61273322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
61373322924127c873c13101b705dd823f5539ffa5fSteve Naroff
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class of FunctionTypeNoProto and FunctionTypeProto.
6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SubClassData - This field is owned by the subclass, put here to pack
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tightly with the ivars in Type.
6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SubClassData : 1;
6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical)
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {}
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getSubClassData() const { return SubClassData; }
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeNoProto(QualType Result, QualType Canonical)
6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionNoProto, Result, false, Canonical) {}
6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getResultType());
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeNoProto *) { return true; }
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument.
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs,
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                    bool isVariadic, QualType Canonical)
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionProto, Result, isVariadic, Canonical),
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      NumArgs(numArgs) {
672942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    // Fill in the trailing argument array.
673942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    for (unsigned i = 0; i != numArgs; ++i)
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ArgInfo[i] = ArgArray[i];
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
681942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
682942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
688942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
694942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
695942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
696942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
697942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeProto *) { return true; }
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
708942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
709942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      bool isVariadic);
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefType(TypedefDecl *D, QualType can) : Type(TypeName, can), Decl(D) {
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
722a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner
723a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
724a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// potentially looking through *all* consequtive typedefs.  This returns the
725a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// sum of the type qualifiers, so if you have:
726a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef const int A;
727a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef volatile A B;
728a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// looking through the typedefs for B will give you "const volatile A".
729a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType LookThroughTypedefs() const;
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
737d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfExpr (GCC extension).
738d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfExpr : public Type {
739d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
740d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) {
741d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
742d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
743d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
744d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
745d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
746d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
747d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
748d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
749d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
750d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfExpr *) { return true; }
751d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
752d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
753d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
754d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
755d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
756d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) {
757d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
758d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
759d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
760d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
761d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
762d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
763d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
764d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
765d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
766d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
767d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagDecl *Decl;
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagType(TagDecl *D, QualType can) : Type(Tagged, can), Decl(D) {}
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagDecl *getDecl() const { return Decl; }
7765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to detect TagType objects of structs/unions/classes.
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass RecordType : public TagType {
7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RecordType(); // DO NOT IMPLEMENT
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
789dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  RecordDecl *getDecl() const {
7905d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
7915d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner  }
7925d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // FIXME: This predicate is a helper to QualType/Type. It needs to
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // recursively check all fields for const-ness. If any field is declared
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // const, it needs to return false.
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasConstFields() const { return false; }
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T);
7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const RecordType *) { return true; }
8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
803611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getCanonicalType - Return the canonical version of this type, with the
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// appropriate type qualifiers on it.
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline QualType QualType::getCanonicalType() const {
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return QualType(getTypePtr()->getCanonicalTypeInternal().getTypePtr(),
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getQualifiers() |
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getTypePtr()->getCanonicalTypeInternal().getQualifiers());
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
812611c1fff195d32df97706e0920c92468b2509900Chris Lattner
813611c1fff195d32df97706e0920c92468b2509900Chris Lattner
814611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
815611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<FunctionType>(CanonicalType);
816611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
817611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
818611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<PointerType>(CanonicalType);
819611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
820611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isReferenceType() const {
821611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ReferenceType>(CanonicalType);
822611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
823611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
824611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ArrayType>(CanonicalType);
825611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
826611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
827611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<RecordType>(CanonicalType);
828611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
829611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
830611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<VectorType>(CanonicalType);
831611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
832611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isOCUVectorType() const {
833611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<OCUVectorType>(CanonicalType);
834611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
835611c1fff195d32df97706e0920c92468b2509900Chris Lattner
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
839