Type.h revision 01c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8
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;
268498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  bool isFunctionPointerType() const;
269a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
270c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
271c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
272c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isStructureType() const;
273498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  bool isUnionType() const;
274c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVectorType() const; // GCC vector type.
275c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isOCUVectorType() const; // OCU vector type.
276c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner
277c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
278c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // specified type, ignoring typedefs, and return a pointer to the best type
279c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // we can.
28077878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  const BuiltinType *getAsBuiltinType() const;
281c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const FunctionType *getAsFunctionType() const;
282befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  const PointerType *getAsPointerType() const;
283a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  const ReferenceType *getAsReferenceType() const;
284c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const ArrayType *getAsArrayType() const;
285d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const ConstantArrayType *getAsConstantArrayType() const;
286d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const VariableArrayType *getAsVariableArrayType() const;
287d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const VariableArrayType *getAsVariablyModifiedType() const;
288c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsRecordType() const;
289c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsStructureType() const;
290c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
291c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const VectorType *getAsVectorType() const; // GCC vector type.
292c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  const ComplexType *getAsComplexType() const;
293c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
299d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
300d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
301d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
305d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
306d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
307d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
309d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// according to the rules of C99 6.7.5p3.  If Loc is non-null, it is set to
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the location of the subexpression that makes it a vla type.  It is not
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// legal to call this on incomplete types.
314590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner  bool isConstantSizeType(ASTContext &Ctx, SourceLocation *Loc = 0) const;
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Compatibility predicates used to check assignment expressions.
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool tagTypesAreCompatible(QualType, QualType); // C99 6.2.7p1
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool pointerTypesAreCompatible(QualType, QualType);  // C99 6.7.5.1p2
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool referenceTypesAreCompatible(QualType, QualType); // C++ 5.17p6
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool functionTypesAreCompatible(QualType, QualType); // C99 6.7.5.3p15
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool arrayTypesAreCompatible(QualType, QualType); // C99 6.7.5.2p6
32377878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  static bool builtinTypesAreCompatible(QualType, QualType);
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getCanonicalTypeInternal() const { return CanonicalType; }
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class QualType;
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const = 0;
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Float, Double, LongDouble
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind TypeKind;
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {}
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind getKind() const { return TypeKind; }
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Complex, CanonicalPtr), ElementType(Element) {
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PointerType - C99 6.7.5.1 - Pointer Declarators.
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PointerType : public Type, public llvm::FoldingSetNode {
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType PointeeType;
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Pointer, CanonicalPtr), PointeeType(Pointee) {
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getPointeeType() const { return PointeeType; }
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ReferenceType - C++ 8.3.2 - Reference Declarators.
4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReferenceType : public Type, public llvm::FoldingSetNode {
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ReferenceeType;
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ReferenceType(QualType Referencee, QualType CanonicalRef) :
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Reference, CanonicalRef), ReferenceeType(Referencee) {
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getReferenceeType() const { return ReferenceeType; }
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getReferenceeType());
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
450fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass ArrayType : public Type {
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an array with a static size (e.g. int X[static 4]), or with a star size
454c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// (e.g. int X[*]). 'static' is only allowed on function parameters.
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
459fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
460fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
461c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
462c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
463c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArraySizeModifier SizeModifier : 2;
464c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
465c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
466c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
467c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned IndexTypeQuals : 3;
468c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
469fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
470c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
471c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff            ArraySizeModifier sm, unsigned tq)
472c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
473fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
474fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
475fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
476c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArraySizeModifier getSizeModifier() const { return SizeModifier; }
477c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
478fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
4797cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  QualType getBaseType() const {
4807cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    const ArrayType *AT;
4817cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    QualType ElmtType = getElementType();
4827cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    // If we have a multi-dimensional array, navigate to the base type.
4837cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    while ((AT = ElmtType->getAsArrayType()))
4847cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff      ElmtType = AT->getElementType();
4857cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    return ElmtType;
4867cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  }
487fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
488fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
489fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff           T->getTypeClass() == VariableArray;
490fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
491fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
492fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
493fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
494fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass ConstantArrayType : public ArrayType, public llvm::FoldingSetNode {
495fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
496fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
497c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ConstantArrayType(QualType et, QualType can, llvm::APInt sz,
498c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
499c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {}
500fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
501fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
502fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt getSize() const { return Size; }
5037cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  int getMaximumElements() const {
5047cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    QualType ElmtType = getElementType();
505124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser    int maxElements = static_cast<int>(getSize().getZExtValue());
506fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
5077cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    const ConstantArrayType *CAT;
5087cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    // If we have a multi-dimensional array, include it's elements.
5097cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    while ((CAT = ElmtType->getAsConstantArrayType())) {
5107cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff      ElmtType = CAT->getElementType();
511124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser      maxElements *= static_cast<int>(CAT->getSize().getZExtValue());
5127cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    }
5137cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    return maxElements;
5147cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  }
515fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
516fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
517fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
518fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Profile(ID, getElementType(), getSize());
519fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
520fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
521fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff                      llvm::APInt ArraySize) {
522fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
523fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
524fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
525fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
526fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray;
527fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
528fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
529fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
530fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
531fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff// FIXME: VariableArrayType's aren't uniqued (since expressions aren't).
532fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffclass VariableArrayType : public ArrayType {
533fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// SizeExpr - An assignment expression. VLA's are only permitted within
534fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// a function block.
5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *SizeExpr;
5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
537c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
538c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
539c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {}
5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5428b9023ba35a86838789e2c9034a6128728c547aaChris Lattner  Expr *getSizeExpr() const { return SizeExpr; }
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
546fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
547fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == VariableArray;
5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
549fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
55273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
55373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in
55473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the
55573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
55773322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumElements - The number of elements in the vector.
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumElements;
5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
56473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
56573322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {}
56673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
56773322924127c873c13101b705dd823f5539ffa5fSteve Naroff    QualType canonType) : Type(tc, canonType), ElementType(vecType),
56873322924127c873c13101b705dd823f5539ffa5fSteve Naroff    NumElements(nElements) {}
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumElements() const { return NumElements; }
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
57873322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Profile(ID, getElementType(), getNumElements(), getTypeClass());
5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
58073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
58173322924127c873c13101b705dd823f5539ffa5fSteve Naroff                      unsigned NumElements, TypeClass TypeClass) {
5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
58473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
58573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
58673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const Type *T) {
58773322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
59273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// OCUVectorType - Extended vector type. This type is created using
59373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((ocu_vector_type(n)), where "n" is the number of elements.
594fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// Unlike vector_size, ocu_vector_type is only allowed on typedef's. This
595fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
596fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
59773322924127c873c13101b705dd823f5539ffa5fSteve Naroffclass OCUVectorType : public VectorType {
59873322924127c873c13101b705dd823f5539ffa5fSteve Naroff  OCUVectorType(QualType vecType, unsigned nElements, QualType canonType) :
59973322924127c873c13101b705dd823f5539ffa5fSteve Naroff    VectorType(OCUVector, vecType, nElements, canonType) {}
60073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
60173322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
60288dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
60388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
60488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
60588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
60688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
60788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
60888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
60988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
610e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
61188dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getColorAccessorIdx(char c) {
61288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
61388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
61488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'r': return 0;
61588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'g': return 1;
61688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'b': return 2;
61788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'a': return 3;
61888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
619e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
62088dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getTextureAccessorIdx(char c) {
62188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
62288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
62388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 's': return 0;
62488dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 't': return 1;
62588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'p': return 2;
62688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'q': return 3;
627e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff    }
62888dca0464804b8b26ae605f89784c927e8493dddChris Lattner  };
629b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
630b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
631b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
632b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getColorAccessorIdx(c)+1) return idx-1;
633b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    return getTextureAccessorIdx(c);
634b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
635b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
63688dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
637b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
63888dca0464804b8b26ae605f89784c927e8493dddChris Lattner      return unsigned(idx-1) < NumElements;
63988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
640e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
64131a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
64231a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
6437064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  static bool classof(const Type *T) {
64473322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == OCUVector;
64573322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
64673322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const OCUVectorType *) { return true; }
64773322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
64873322924127c873c13101b705dd823f5539ffa5fSteve Naroff
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class of FunctionTypeNoProto and FunctionTypeProto.
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SubClassData - This field is owned by the subclass, put here to pack
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tightly with the ivars in Type.
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SubClassData : 1;
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical)
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {}
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getSubClassData() const { return SubClassData; }
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeNoProto(QualType Result, QualType Canonical)
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionNoProto, Result, false, Canonical) {}
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getResultType());
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeNoProto *) { return true; }
6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument.
7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs,
7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                    bool isVariadic, QualType Canonical)
7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionProto, Result, isVariadic, Canonical),
7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      NumArgs(numArgs) {
707942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    // Fill in the trailing argument array.
708942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    for (unsigned i = 0; i != numArgs; ++i)
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ArgInfo[i] = ArgArray[i];
7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
716942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
717942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
723942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
729942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
730942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
731942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
732942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeProto *) { return true; }
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
743942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
744942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      bool isVariadic);
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefType(TypedefDecl *D, QualType can) : Type(TypeName, can), Decl(D) {
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
757a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner
758a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
759a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// potentially looking through *all* consequtive typedefs.  This returns the
760a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// sum of the type qualifiers, so if you have:
761a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef const int A;
762a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef volatile A B;
763a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// looking through the typedefs for B will give you "const volatile A".
764a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType LookThroughTypedefs() const;
7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
772d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfExpr (GCC extension).
773d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfExpr : public Type {
774d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
775d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) {
776d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
777d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
778d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
779d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
780d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
781d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
782d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
783d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
784d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
785d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfExpr *) { return true; }
786d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
787d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
788d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
789d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
790d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
791d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) {
792d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
793d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
794d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
795d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
796d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
797d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
798d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
799d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
800d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
801d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
802d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagDecl *Decl;
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagType(TagDecl *D, QualType can) : Type(Tagged, can), Decl(D) {}
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TagDecl *getDecl() const { return Decl; }
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8183536b443bc50d58a79f14fca9b6842541a434854Steve Naroffclass ObjcInterfaceType : public Type {
8193536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  ObjcInterfaceDecl *Decl;
8203536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  ObjcInterfaceType(ObjcInterfaceDecl *D) :
8213536b443bc50d58a79f14fca9b6842541a434854Steve Naroff    Type(ObjcInterface, QualType()), Decl(D) { }
8223536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  friend class ASTContext;  // ASTContext creates these.
8233536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
8243536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8253536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  ObjcInterfaceDecl *getDecl() const { return Decl; }
8263536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8273536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
8283536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8293536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  static bool classof(const Type *T) {
8303536b443bc50d58a79f14fca9b6842541a434854Steve Naroff    return T->getTypeClass() == ObjcInterface;
8313536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
8323536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  static bool classof(const ObjcInterfaceType *) { return true; }
8333536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
8343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to detect TagType objects of structs/unions/classes.
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass RecordType : public TagType {
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RecordType(); // DO NOT IMPLEMENT
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
841dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  RecordDecl *getDecl() const {
8425d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
8435d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner  }
8445d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // FIXME: This predicate is a helper to QualType/Type. It needs to
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // recursively check all fields for const-ness. If any field is declared
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // const, it needs to return false.
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasConstFields() const { return false; }
8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T);
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const RecordType *) { return true; }
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
855611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getCanonicalType - Return the canonical version of this type, with the
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// appropriate type qualifiers on it.
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline QualType QualType::getCanonicalType() const {
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return QualType(getTypePtr()->getCanonicalTypeInternal().getTypePtr(),
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getQualifiers() |
8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getTypePtr()->getCanonicalTypeInternal().getQualifiers());
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
864611c1fff195d32df97706e0920c92468b2509900Chris Lattner
865611c1fff195d32df97706e0920c92468b2509900Chris Lattner
866611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
867611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<FunctionType>(CanonicalType);
868611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
869611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
870611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<PointerType>(CanonicalType);
871611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
872498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
87301c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek  if (const PointerType* T = getAsPointerType())
874498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
875498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
876498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
877498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
878611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isReferenceType() const {
879611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ReferenceType>(CanonicalType);
880611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
881611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
882611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ArrayType>(CanonicalType);
883611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
884611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
885611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<RecordType>(CanonicalType);
886611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
887611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
888611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<VectorType>(CanonicalType);
889611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
890611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isOCUVectorType() const {
891611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<OCUVectorType>(CanonicalType);
892611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
893611c1fff195d32df97706e0920c92468b2509900Chris Lattner
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
897