Type.h revision 124dd7b5777e29ecac006822bd4d4623f0dc4264
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;
343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  class ObjcInterfaceDecl;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
373acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner  class PointerType;
38251dcaf8616c6f04051e214f35cadb7de42aef7eBill Wendling  class ReferenceType;
393acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner  class VectorType;
40700204c74b455746752e851b25565ebf932f5340Steve Naroff  class ArrayType;
41d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  class ConstantArrayType;
42d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  class VariableArrayType;
43dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  class RecordType;
44c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  class ComplexType;
457064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class TagType;
467064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class FunctionType;
477064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class OCUVectorType;
4877878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  class BuiltinType;
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers.  This
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int',
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc).
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer.  To handle the
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer.
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType {
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  uintptr_t ThePtr;
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CVRFlags = Const|Restrict|Volatile
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType() : ThePtr(0) {}
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType(Type *Ptr, unsigned Quals) {
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ThePtr = reinterpret_cast<uintptr_t>(Ptr);
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ThePtr |= Quals;
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getQualifiers() const {
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr & CVRFlags;
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *getTypePtr() const {
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<Type*>(ThePtr & ~CVRFlags);
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void *getAsOpaquePtr() const {
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<void*>(ThePtr);
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr == 0;
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isConstQualified() const {
110b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner    return (ThePtr & Const) ? true : false;
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVolatileQualified() const {
113b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner    return (ThePtr & Volatile) ? true : false;
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRestrictQualified() const {
116b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner    return (ThePtr & Restrict) ? true : false;
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1187effa1aceac1219529af23c776835f855b8d905cChris Lattner
1197effa1aceac1219529af23c776835f855b8d905cChris Lattner  /// addConst/addVolatile/addRestrict - add the specified type qual to this
1207effa1aceac1219529af23c776835f855b8d905cChris Lattner  /// QualType.
1217effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addConst()    { ThePtr |= Const; }
1227effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addVolatile() { ThePtr |= Volatile; }
1237effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addRestrict() { ThePtr |= Restrict; }
1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getQualifiedType(unsigned TQs) const {
1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return QualType(getTypePtr(), TQs);
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getUnqualifiedType() const {
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return QualType(getTypePtr(), 0);
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool operator==(const QualType &RHS) const {
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr == RHS.ThePtr;
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool operator!=(const QualType &RHS) const {
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr != RHS.ThePtr;
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::string getAsString() const {
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    getAsStringInternal(S);
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void getAsStringInternal(std::string &Str) const;
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void dump(const char *s = 0) const;
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getCanonicalType - Return the canonical version of this type, with the
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// appropriate type qualifiers on it.
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  inline QualType getCanonicalType() const;
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Val.getTypePtr();
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// TypeNameType).  Its CanonicalType pointer points to the 'int' Type.  Next
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type {
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
202fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Builtin, Complex, Pointer, Reference,
203fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ConstantArray, VariableArray,
204fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Vector, OCUVector,
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FunctionNoProto, FunctionProto,
206d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    TypeName, Tagged,
2073536b443bc50d58a79f14fca9b6842541a434854Steve Naroff    ObjcInterface,
208d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    TypeOfExp, TypeOfTyp // GNU typeof extension.
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Note that this should stay at the end of the ivars for Type so that
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// subclasses can pack their bitfields into the same word.
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeClass TC : 4;
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
218124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
219124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type(TypeClass tc, QualType Canonical)
221124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser    : CanonicalType(Canonical.isNull() ? QualType(this_(),0) : Canonical), TC(tc){}
2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual ~Type();
2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
2248b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypeClass getTypeClass() const { return TC; }
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isObjectType - types that fully describe objects. An object is a region
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of memory that can be examined and stored into (H&S).
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isObjectType() const;
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// routine will need to determine if the size is actually required.
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
242d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
243d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// types that have a non-constant expression. This does not include "[]".
244d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  bool isVariablyModifiedType() const;
245d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operate on the canonical type, ignoring typedefs.
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
24913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
25013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
25113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
259c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
260c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
261c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
262c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
264c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
265c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // type, ignoring typedefs.
266c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
267befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
268a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
269c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
270c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
271c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isStructureType() const;
272c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isUnionType() const;
273c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVectorType() const; // GCC vector type.
274c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isOCUVectorType() const; // OCU vector type.
275c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner
276c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
277c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // specified type, ignoring typedefs, and return a pointer to the best type
278c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // we can.
27977878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  const BuiltinType *getAsBuiltinType() const;
280c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const FunctionType *getAsFunctionType() const;
281befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  const PointerType *getAsPointerType() const;
282a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  const ReferenceType *getAsReferenceType() const;
283c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const ArrayType *getAsArrayType() const;
284d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const ConstantArrayType *getAsConstantArrayType() const;
285d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const VariableArrayType *getAsVariableArrayType() const;
286d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const VariableArrayType *getAsVariablyModifiedType() const;
287c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsRecordType() const;
288c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsStructureType() const;
289c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
290c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const VectorType *getAsVectorType() const; // GCC vector type.
291c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  const ComplexType *getAsComplexType() const;
292c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
298d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
299d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
300d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
304d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
305d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
306d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
308d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// according to the rules of C99 6.7.5p3.  If Loc is non-null, it is set to
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the location of the subexpression that makes it a vla type.  It is not
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// legal to call this on incomplete types.
313590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isConstantSizeType(ASTContext &Ctx, SourceLocation *Loc = 0) const;
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Compatibility predicates used to check assignment expressions.
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool tagTypesAreCompatible(QualType, QualType); // C99 6.2.7p1
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool pointerTypesAreCompatible(QualType, QualType);  // C99 6.7.5.1p2
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
32277878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  static bool builtinTypesAreCompatible(QualType, QualType);
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getCanonicalTypeInternal() const { return CanonicalType; }
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class QualType;
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const = 0;
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Float, Double, LongDouble
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind TypeKind;
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {}
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind getKind() const { return TypeKind; }
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Complex, CanonicalPtr), ElementType(Element) {
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PointerType - C99 6.7.5.1 - Pointer Declarators.
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PointerType : public Type, public llvm::FoldingSetNode {
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType PointeeType;
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Pointer, CanonicalPtr), PointeeType(Pointee) {
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getPointeeType() const { return PointeeType; }
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ReferenceType - C++ 8.3.2 - Reference Declarators.
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReferenceType : public Type, public llvm::FoldingSetNode {
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ReferenceeType;
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ReferenceType(QualType Referencee, QualType CanonicalRef) :
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Reference, CanonicalRef), ReferenceeType(Referencee) {
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getReferenceeType() const { return ReferenceeType; }
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getReferenceeType());
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
449fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass ArrayType : public Type {
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an array with a static size (e.g. int X[static 4]), or with a star size
453c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// (e.g. int X[*]). 'static' is only allowed on function parameters.
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
458fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
459fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
460c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
461c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
462c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArraySizeModifier SizeModifier : 2;
463c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
464c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
465c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
466c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned IndexTypeQuals : 3;
467c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
468fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
469c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
470c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff            ArraySizeModifier sm, unsigned tq)
471c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
472fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
473fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
474fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
475c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArraySizeModifier getSizeModifier() const { return SizeModifier; }
476c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
477fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
4787cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  QualType getBaseType() const {
4797cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    const ArrayType *AT;
4807cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    QualType ElmtType = getElementType();
4817cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    // If we have a multi-dimensional array, navigate to the base type.
4827cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    while ((AT = ElmtType->getAsArrayType()))
4837cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff      ElmtType = AT->getElementType();
4847cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    return ElmtType;
4857cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  }
486fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
487fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
488fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff           T->getTypeClass() == VariableArray;
489fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
490fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
491fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
492fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
493fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass ConstantArrayType : public ArrayType, public llvm::FoldingSetNode {
494fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
495fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
496c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ConstantArrayType(QualType et, QualType can, llvm::APInt sz,
497c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
498c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {}
499fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
500fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
501fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt getSize() const { return Size; }
5027cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  int getMaximumElements() const {
5037cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    QualType ElmtType = getElementType();
504124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser    int maxElements = static_cast<int>(getSize().getZExtValue());
505fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
5067cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    const ConstantArrayType *CAT;
5077cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    // If we have a multi-dimensional array, include it's elements.
5087cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    while ((CAT = ElmtType->getAsConstantArrayType())) {
5097cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff      ElmtType = CAT->getElementType();
510124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser      maxElements *= static_cast<int>(CAT->getSize().getZExtValue());
5117cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    }
5127cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    return maxElements;
5137cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  }
514fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
515fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
516fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
517fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Profile(ID, getElementType(), getSize());
518fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
519fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
520fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff                      llvm::APInt ArraySize) {
521fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
522fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
523fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
524fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
525fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray;
526fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
527fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
528fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
529fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
530fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff// FIXME: VariableArrayType's aren't uniqued (since expressions aren't).
531fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass VariableArrayType : public ArrayType {
532fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// SizeExpr - An assignment expression. VLA's are only permitted within
533fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// a function block.
5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *SizeExpr;
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
536c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
537c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
538c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {}
5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5418b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  Expr *getSizeExpr() const { return SizeExpr; }
5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
545fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
546fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == VariableArray;
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
548fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
55173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
55273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in
55373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the
55473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
55673322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumElements - The number of elements in the vector.
5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumElements;
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
56373322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
56473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {}
56573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
56673322924127c873c13101b705dd823f5539ffa5fSteve Naroff    QualType canonType) : Type(tc, canonType), ElementType(vecType),
56773322924127c873c13101b705dd823f5539ffa5fSteve Naroff    NumElements(nElements) {}
5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumElements() const { return NumElements; }
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
57773322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Profile(ID, getElementType(), getNumElements(), getTypeClass());
5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
57973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
58073322924127c873c13101b705dd823f5539ffa5fSteve Naroff                      unsigned NumElements, TypeClass TypeClass) {
5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
58373322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
58473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
58573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const Type *T) {
58673322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
59173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// OCUVectorType - Extended vector type. This type is created using
59273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((ocu_vector_type(n)), where "n" is the number of elements.
593fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// Unlike vector_size, ocu_vector_type is only allowed on typedef's. This
594fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
595fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
59673322924127c873c13101b705dd823f5539ffa5fSteve Naroffclass OCUVectorType : public VectorType {
59773322924127c873c13101b705dd823f5539ffa5fSteve Naroff  OCUVectorType(QualType vecType, unsigned nElements, QualType canonType) :
59873322924127c873c13101b705dd823f5539ffa5fSteve Naroff    VectorType(OCUVector, vecType, nElements, canonType) {}
59973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
60073322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
60188dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
60288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
60388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
60488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
60588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
60688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
60788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
60888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
609e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
61088dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getColorAccessorIdx(char c) {
61188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
61288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
61388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'r': return 0;
61488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'g': return 1;
61588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'b': return 2;
61688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'a': return 3;
61788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
618e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
61988dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getTextureAccessorIdx(char c) {
62088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
62188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
62288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 's': return 0;
62388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 't': return 1;
62488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'p': return 2;
62588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'q': return 3;
626e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff    }
62788dca0464804b8b26ae605f89784c927e8493dddChris Lattner  };
628b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
629b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
630b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
631b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getColorAccessorIdx(c)+1) return idx-1;
632b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    return getTextureAccessorIdx(c);
633b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
634b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
63588dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
636b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
63788dca0464804b8b26ae605f89784c927e8493dddChris Lattner      return unsigned(idx-1) < NumElements;
63888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
639e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
64031a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
64131a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
6427064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  static bool classof(const Type *T) {
64373322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == OCUVector;
64473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
64573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const OCUVectorType *) { return true; }
64673322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
64773322924127c873c13101b705dd823f5539ffa5fSteve Naroff
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class of FunctionTypeNoProto and FunctionTypeProto.
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SubClassData - This field is owned by the subclass, put here to pack
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tightly with the ivars in Type.
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SubClassData : 1;
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical)
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {}
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getSubClassData() const { return SubClassData; }
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeNoProto(QualType Result, QualType Canonical)
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionNoProto, Result, false, Canonical) {}
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getResultType());
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeNoProto *) { return true; }
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument.
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs,
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                    bool isVariadic, QualType Canonical)
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionProto, Result, isVariadic, Canonical),
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      NumArgs(numArgs) {
706942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    // Fill in the trailing argument array.
707942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    for (unsigned i = 0; i != numArgs; ++i)
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ArgInfo[i] = ArgArray[i];
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
715942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
716942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
722942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
728942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
729942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
730942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
731942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeProto *) { return true; }
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
742942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
743942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      bool isVariadic);
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefType(TypedefDecl *D, QualType can) : Type(TypeName, can), Decl(D) {
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
756a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner
757a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
758a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// potentially looking through *all* consequtive typedefs.  This returns the
759a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// sum of the type qualifiers, so if you have:
760a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef const int A;
761a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef volatile A B;
762a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// looking through the typedefs for B will give you "const volatile A".
763a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType LookThroughTypedefs() const;
7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
771d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfExpr (GCC extension).
772d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfExpr : public Type {
773d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
774d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) {
775d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
776d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
777d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
778d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
779d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
780d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
781d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
782d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
783d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
784d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfExpr *) { return true; }
785d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
786d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
787d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
788d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
789d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
790d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) {
791d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
792d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
793d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
794d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
795d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
796d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
797d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
798d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
799d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
800d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
801d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagDecl *Decl;
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagType(TagDecl *D, QualType can) : Type(Tagged, can), Decl(D) {}
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagDecl *getDecl() const { return Decl; }
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8173536b443bc50d58a79f14fca9b6842541a434854Steve Naroffclass ObjcInterfaceType : public Type {
8183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  ObjcInterfaceDecl *Decl;
8193536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  ObjcInterfaceType(ObjcInterfaceDecl *D) :
8203536b443bc50d58a79f14fca9b6842541a434854Steve Naroff    Type(ObjcInterface, QualType()), Decl(D) { }
8213536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  friend class ASTContext;  // ASTContext creates these.
8223536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
8233536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8243536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  ObjcInterfaceDecl *getDecl() const { return Decl; }
8253536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8263536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
8273536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8283536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  static bool classof(const Type *T) {
8293536b443bc50d58a79f14fca9b6842541a434854Steve Naroff    return T->getTypeClass() == ObjcInterface;
8303536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
8313536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  static bool classof(const ObjcInterfaceType *) { return true; }
8323536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
8333536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to detect TagType objects of structs/unions/classes.
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass RecordType : public TagType {
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RecordType(); // DO NOT IMPLEMENT
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
840dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  RecordDecl *getDecl() const {
8415d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
8425d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner  }
8435d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // FIXME: This predicate is a helper to QualType/Type. It needs to
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // recursively check all fields for const-ness. If any field is declared
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // const, it needs to return false.
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasConstFields() const { return false; }
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T);
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const RecordType *) { return true; }
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
854611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getCanonicalType - Return the canonical version of this type, with the
8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// appropriate type qualifiers on it.
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline QualType QualType::getCanonicalType() const {
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return QualType(getTypePtr()->getCanonicalTypeInternal().getTypePtr(),
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getQualifiers() |
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getTypePtr()->getCanonicalTypeInternal().getQualifiers());
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
863611c1fff195d32df97706e0920c92468b2509900Chris Lattner
864611c1fff195d32df97706e0920c92468b2509900Chris Lattner
865611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
866611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<FunctionType>(CanonicalType);
867611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
868611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
869611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<PointerType>(CanonicalType);
870611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
871611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isReferenceType() const {
872611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ReferenceType>(CanonicalType);
873611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
874611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
875611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ArrayType>(CanonicalType);
876611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
877611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
878611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<RecordType>(CanonicalType);
879611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
880611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
881611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<VectorType>(CanonicalType);
882611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
883611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isOCUVectorType() const {
884611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<OCUVectorType>(CanonicalType);
885611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
886611c1fff195d32df97706e0920c92468b2509900Chris Lattner
8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
890