Type.h revision a526c5c67e5a0473c340903ee542ce570119665f
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// 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"
2073af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek#include "llvm/Bitcode/SerializationFwd.h"
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa;
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast;
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null;
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast;
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null;
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Type;
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TypedefDecl;
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TagDecl;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class RecordDecl;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class EnumDecl;
3521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  class FieldDecl;
36a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCInterfaceDecl;
37a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCProtocolDecl;
38a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCMethodDecl;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Expr;
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class SourceLocation;
413acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner  class PointerType;
42251dcaf8616c6f04051e214f35cadb7de42aef7eBill Wendling  class ReferenceType;
433acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner  class VectorType;
44700204c74b455746752e851b25565ebf932f5340Steve Naroff  class ArrayType;
45d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  class ConstantArrayType;
46d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  class VariableArrayType;
47dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  class RecordType;
48c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  class ComplexType;
497064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class TagType;
507064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class FunctionType;
517064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  class OCUVectorType;
5277878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  class BuiltinType;
53a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  class ObjCQualifiedInterfaceType;
5492866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  class StmtIteratorBase;
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers.  This
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int',
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc).
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer.  To handle the
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer.
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType {
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  uintptr_t ThePtr;
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TQ {   // NOTE: These flags must be kept in sync with DeclSpec::TQ.
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Const    = 0x1,
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Restrict = 0x2,
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Volatile = 0x4,
735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    CVRFlags = Const|Restrict|Volatile
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType() : ThePtr(0) {}
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType(Type *Ptr, unsigned Quals) {
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!");
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ThePtr = reinterpret_cast<uintptr_t>(Ptr);
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?");
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ThePtr |= Quals;
835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static QualType getFromOpaquePtr(void *Ptr) {
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    QualType T;
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    T.ThePtr = reinterpret_cast<uintptr_t>(Ptr);
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T;
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getQualifiers() const {
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr & CVRFlags;
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *getTypePtr() const {
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<Type*>(ThePtr & ~CVRFlags);
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void *getAsOpaquePtr() const {
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return reinterpret_cast<void*>(ThePtr);
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type &operator*() const {
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return *getTypePtr();
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type *operator->() const {
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getTypePtr();
1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isNull - Return true if this QualType doesn't point to a type yet.
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isNull() const {
1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr == 0;
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isConstQualified() const {
116b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner    return (ThePtr & Const) ? true : false;
1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVolatileQualified() const {
119b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner    return (ThePtr & Volatile) ? true : false;
1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRestrictQualified() const {
122b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner    return (ThePtr & Restrict) ? true : false;
1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1247effa1aceac1219529af23c776835f855b8d905cChris Lattner
1257effa1aceac1219529af23c776835f855b8d905cChris Lattner  /// addConst/addVolatile/addRestrict - add the specified type qual to this
1267effa1aceac1219529af23c776835f855b8d905cChris Lattner  /// QualType.
1277effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addConst()    { ThePtr |= Const; }
1287effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addVolatile() { ThePtr |= Volatile; }
1297effa1aceac1219529af23c776835f855b8d905cChris Lattner  void addRestrict() { ThePtr |= Restrict; }
1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getQualifiedType(unsigned TQs) const {
1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return QualType(getTypePtr(), TQs);
1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getUnqualifiedType() const {
1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return QualType(getTypePtr(), 0);
1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operator==/!= - Indicate whether the specified types and qualifiers are
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// identical.
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool operator==(const QualType &RHS) const {
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr == RHS.ThePtr;
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool operator!=(const QualType &RHS) const {
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return ThePtr != RHS.ThePtr;
1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  std::string getAsString() const {
1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    std::string S;
1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    getAsStringInternal(S);
1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return S;
1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void getAsStringInternal(std::string &Str) const;
1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void dump(const char *s = 0) const;
1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getCanonicalType - Return the canonical version of this type, with the
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// appropriate type qualifiers on it.
1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  inline QualType getCanonicalType() const;
1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  /// Emit - Serialize a QualType to Bitcode.
16173af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek  void Emit(llvm::Serializer& S) const;
16273af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek
16303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  /// Read - Deserialize a QualType from Bitcode.
16403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  static QualType ReadVal(llvm::Deserializer& D);
16521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek
16621d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenekprivate:
16721d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  void ReadBackpatch(llvm::Deserializer& D);
16821d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  friend class FieldDecl;
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang.
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class.
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> {
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef ::clang::Type* SimpleType;
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static SimpleType getSimplifiedValue(const ::clang::QualType &Val) {
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return Val.getTypePtr();
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType>
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  : public simplify_type<const ::clang::QualType> {};
18473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek
18573af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy.  A central concept
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type.  A canonical type
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references.  For example, consider:
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef int  foo;
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  typedef foo* bar;
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///    'int *'    'foo *'    'bar'
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'.  Since int is canonical, its
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself.  There is also a Type for 'foo' (a
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// TypeNameType).  Its CanonicalType pointer points to the 'int' Type.  Next
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical.  Finally, there is a PointerType type for 'foo*' whose canonical
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'.
2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing
2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used.  Canonical types are useful for type
2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning
2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type),
2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type.
2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable.
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type {
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum TypeClass {
217fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Builtin, Complex, Pointer, Reference,
218fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ConstantArray, VariableArray,
219fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Vector, OCUVector,
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    FunctionNoProto, FunctionProto,
221d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    TypeName, Tagged,
222a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    ObjCInterface, ObjCQualifiedInterface,
223a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    ObjCQualifiedId,
224d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    TypeOfExp, TypeOfTyp // GNU typeof extension.
2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType CanonicalType;
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Note that this should stay at the end of the ivars for Type so that
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// subclasses can pack their bitfields into the same word.
232a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser  unsigned TC : 4;
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
234124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  // silence VC++ warning C4355: 'this' : used in base member initializer list
235124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser  Type *this_() { return this; }
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Type(TypeClass tc, QualType Canonical)
237124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser    : CanonicalType(Canonical.isNull() ? QualType(this_(),0) : Canonical), TC(tc){}
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual ~Type();
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;
24073af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek
24173af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek  void EmitTypeInternal(llvm::Serializer& S) const;
24273af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek  void ReadTypeInternal(llvm::Deserializer& D);
24373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek
2448b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic:
245a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser  TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isCanonical() const { return CanonicalType.getTypePtr() == this; }
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object types, function types, and incomplete types.
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isObjectType - types that fully describe objects. An object is a region
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of memory that can be examined and stored into (H&S).
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isObjectType() const;
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isIncompleteType - Return true if this is an incomplete type.
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// A type that can describe objects, but which lacks information needed to
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// routine will need to determine if the size is actually required.
2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIncompleteType() const;
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
262d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array
263d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  /// types that have a non-constant expression. This does not include "[]".
264d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  bool isVariablyModifiedType() const;
265d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff
2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Helper methods to distinguish type categories. All type predicates
2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// operate on the canonical type, ignoring typedefs.
2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
26913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isEnumeralType() const;
27013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isBooleanType() const;
27113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  bool isCharType() const;
27233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian  bool isIntegralType() const;
2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// Floating point categories.
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isComplexType() const;      // C99 6.2.5p11 (complex)
2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isFloatingType() const;     // C99 6.2.5p11 (real floating + complex)
2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
280c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVoidType() const;         // C99 6.2.5p19
281c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isDerivedType() const;      // C99 6.2.5p20
282c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
283c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
285c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Predicates: Check to see if this type is structurally the specified
286c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // type, ignoring typedefs.
287c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isFunctionType() const;
288befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  bool isPointerType() const;
289498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  bool isFunctionPointerType() const;
290a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  bool isReferenceType() const;
291c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isArrayType() const;
292c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isRecordType() const;
293c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isStructureType() const;
294498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  bool isUnionType() const;
295c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isVectorType() const; // GCC vector type.
296c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  bool isOCUVectorType() const; // OCU vector type.
297a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  bool isObjCInterfaceType() const; // includes conforming protocol type
298a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  bool isObjCQualifiedIdType() const; // id includes conforming protocol type
299c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner
300c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // Type Checking Functions: Check to see if this type is structurally the
301c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // specified type, ignoring typedefs, and return a pointer to the best type
302c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  // we can.
30377878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff  const BuiltinType *getAsBuiltinType() const;
304c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const FunctionType *getAsFunctionType() const;
305befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner  const PointerType *getAsPointerType() const;
306a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner  const ReferenceType *getAsReferenceType() const;
307c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const ArrayType *getAsArrayType() const;
308d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const ConstantArrayType *getAsConstantArrayType() const;
309d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const VariableArrayType *getAsVariableArrayType() const;
310d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff  const VariableArrayType *getAsVariablyModifiedType() const;
311c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsRecordType() const;
312c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsStructureType() const;
313c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const RecordType *getAsUnionType() const;
314c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const VectorType *getAsVectorType() const; // GCC vector type.
315c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner  const ComplexType *getAsComplexType() const;
316c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner  const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
318dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  /// getDesugaredType - Return the specified type with any "sugar" removed from
319dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  /// type type.  This takes off typedefs, typeof's etc.  If the outer level of
320dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  /// the type is already concrete, it returns it unmodified.  This is similar
321dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  /// to getting the canonical type, but it doesn't remove *all* typedefs.  For
322dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  /// example, it return "T*" as "T*", (not as "int*"), because the pointer is
323dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  /// concrete.
324dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner  const Type *getDesugaredType() const;
325dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// More type predicates useful for type checking/promotion
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isPromotableIntegerType() const; // C99 6.3.1.1p2
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isSignedIntegerType - Return true if this is an integer type that is
330d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
331d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// an enum decl which has a signed representation, or a vector of signed
332d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// integer element type.
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isSignedIntegerType() const;
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isUnsignedIntegerType - Return true if this is an integer type that is
336d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
337d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// decl which has an unsigned representation, or a vector of unsigned integer
338d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner  /// element type.
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isUnsignedIntegerType() const;
340d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner
3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// isConstantSizeType - Return true if this is not a variable sized type,
3429bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// according to the rules of C99 6.7.5p3.  It is not legal to call this on
3439bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  /// incomplete types.
3449bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner  bool isConstantSizeType(ASTContext &Ctx) const;
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getCanonicalTypeInternal() const { return CanonicalType; }
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class QualType;
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const = 0;
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *) { return true; }
35103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
35203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected:
35303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  /// Emit - Emit a Type to bitcode.  Used by ASTContext.
35403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  void Emit(llvm::Serializer& S) const;
35503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
35603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  /// Create - Construct a Type from bitcode.  Used by ASTContext.
35703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S);
35803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
35903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  /// EmitImpl - Subclasses must implement this method in order to
36003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  ///  be serialized.
36103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'.  Builtin
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field.
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type {
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum Kind {
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Void,
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Bool,     // This is bool and/or _Bool.
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_U,   // This is 'char' for targets where char is unsigned.
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UChar,    // This is explicitly qualified unsigned char.
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UShort,
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    UInt,
3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULong,
3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ULongLong,
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Char_S,   // This is 'char' for targets where char is signed.
3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    SChar,    // This is explicitly qualified signed char.
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Short,
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Int,
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Long,
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    LongLong,
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Float, Double, LongDouble
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind TypeKind;
3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {}
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Kind getKind() const { return TypeKind; }
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const char *getName() const;
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const BuiltinType *) { return true; }
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions.
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode {
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ComplexType(QualType Element, QualType CanonicalPtr) :
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Complex, CanonicalPtr), ElementType(Element) {
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
4135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
41503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getElementType());
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Element.getAsOpaquePtr());
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ComplexType *) { return true; }
42573af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek
42603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected:
42703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
42803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
42903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  friend class Type;
4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PointerType - C99 6.7.5.1 - Pointer Declarators.
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PointerType : public Type, public llvm::FoldingSetNode {
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType PointeeType;
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  PointerType(QualType Pointee, QualType CanonicalPtr) :
4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Pointer, CanonicalPtr), PointeeType(Pointee) {
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getPointeeType() const { return PointeeType; }
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getPointeeType());
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Pointee.getAsOpaquePtr());
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const PointerType *) { return true; }
45703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
45803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected:
45903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
46003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
46103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  friend class Type;
4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ReferenceType - C++ 8.3.2 - Reference Declarators.
4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReferenceType : public Type, public llvm::FoldingSetNode {
4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ReferenceeType;
4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ReferenceType(QualType Referencee, QualType CanonicalRef) :
4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Type(Reference, CanonicalRef), ReferenceeType(Referencee) {
4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getReferenceeType() const { return ReferenceeType; }
4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getReferenceeType());
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) {
4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(Referencee.getAsOpaquePtr());
4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const ReferenceType *) { return true; }
4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators.
4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
4902e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode {
4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4])
4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an array with a static size (e.g. int X[static 4]), or with a star size
494c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// (e.g. int X[*]). 'static' is only allowed on function parameters.
4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  enum ArraySizeModifier {
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Normal, Static, Star
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  };
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate:
499fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// ElementType - The element type of the array.
500fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType ElementType;
501c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
502c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// NOTE: These fields are packed into the bitfields space in the Type class.
503c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArraySizeModifier SizeModifier : 2;
504c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
505c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// IndexTypeQuals - Capture qualifiers in declarations like:
506c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  /// 'int X[static restrict 4]'. For function parameters only.
507c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned IndexTypeQuals : 3;
508c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff
509fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected:
510c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArrayType(TypeClass tc, QualType et, QualType can,
511c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff            ArraySizeModifier sm, unsigned tq)
512c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {}
513fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
514fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
515fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  QualType getElementType() const { return ElementType; }
516c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ArraySizeModifier getSizeModifier() const { return SizeModifier; }
517c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  unsigned getIndexTypeQualifier() const { return IndexTypeQuals; }
518fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
5197cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  QualType getBaseType() const {
5207cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    const ArrayType *AT;
5217cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    QualType ElmtType = getElementType();
5227cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    // If we have a multi-dimensional array, navigate to the base type.
5237cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    while ((AT = ElmtType->getAsArrayType()))
5247cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff      ElmtType = AT->getElementType();
5257cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    return ElmtType;
5267cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  }
527fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
528fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray ||
529fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff           T->getTypeClass() == VariableArray;
530fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
531fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ArrayType *) { return true; }
532fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
533fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
5342e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType {
535fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt Size; // Allows us to unique the type.
536fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
537c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  ConstantArrayType(QualType et, QualType can, llvm::APInt sz,
538c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
539c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {}
540fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  friend class ASTContext;  // ASTContext creates these.
541fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic:
542fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  llvm::APInt getSize() const { return Size; }
5437cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  int getMaximumElements() const {
5447cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    QualType ElmtType = getElementType();
545124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser    int maxElements = static_cast<int>(getSize().getZExtValue());
546fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
5477cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    const ConstantArrayType *CAT;
5487cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    // If we have a multi-dimensional array, include it's elements.
5497cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    while ((CAT = ElmtType->getAsConstantArrayType())) {
5507cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff      ElmtType = CAT->getElementType();
551124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser      maxElements *= static_cast<int>(CAT->getSize().getZExtValue());
5527cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    }
5537cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff    return maxElements;
5547cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff  }
555fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
556fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
557fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  void Profile(llvm::FoldingSetNodeID &ID) {
558fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    Profile(ID, getElementType(), getSize());
559fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
560fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
561fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff                      llvm::APInt ArraySize) {
562fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddPointer(ET.getAsOpaquePtr());
563fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    ID.AddInteger(ArraySize.getZExtValue());
564fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
565fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
566fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == ConstantArray;
567fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  }
568fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const ConstantArrayType *) { return true; }
569da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek
570da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenekprotected:
571da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
572da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
573da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek  friend class Type;
574fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff};
575fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff
576fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff// FIXME: VariableArrayType's aren't uniqued (since expressions aren't).
5772e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType {
578fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// SizeExpr - An assignment expression. VLA's are only permitted within
579fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  /// a function block.
5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr *SizeExpr;
5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
582c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff  VariableArrayType(QualType et, QualType can, Expr *e,
583c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff                    ArraySizeModifier sm, unsigned tq)
584c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff    : ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {}
5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
5876e999782a102eb444cfc7b8eaa64f84911fdcf4fChris Lattner  const Expr *getSizeExpr() const { return SizeExpr; }
5886e999782a102eb444cfc7b8eaa64f84911fdcf4fChris Lattner  Expr *getSizeExpr() { return SizeExpr; }
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
592fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const Type *T) {
593fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff    return T->getTypeClass() == VariableArray;
5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
595fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff  static bool classof(const VariableArrayType *) { return true; }
596a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek
59792866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek  friend class StmtIteratorBase;
5982bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek
5992bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  void Profile(llvm::FoldingSetNodeID &ID) {
6002bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek    assert (SizeExpr == NULL
6012bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek            && "Can only unique VariableArrayTypes with no specified size.");
6022bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek
6032bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek    Profile(ID, getElementType());
6042bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
6052bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek
6062bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) {
6072bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek    ID.AddPointer(ET.getAsOpaquePtr());
6082bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek  }
609ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek
610ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenekprotected:
611ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
612ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
613ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek  friend class Type;
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
61673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using
61773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in
61873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the
61973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements.
6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode {
62173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected:
6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// ElementType - The element type of the vector.
6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ElementType;
6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumElements - The number of elements in the vector.
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumElements;
6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
62873322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(QualType vecType, unsigned nElements, QualType canonType) :
62973322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {}
63073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
63173322924127c873c13101b705dd823f5539ffa5fSteve Naroff    QualType canonType) : Type(tc, canonType), ElementType(vecType),
63273322924127c873c13101b705dd823f5539ffa5fSteve Naroff    NumElements(nElements) {}
6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getElementType() const { return ElementType; }
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumElements() const { return NumElements; }
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
64273322924127c873c13101b705dd823f5539ffa5fSteve Naroff    Profile(ID, getElementType(), getNumElements(), getTypeClass());
6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
64473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
64573322924127c873c13101b705dd823f5539ffa5fSteve Naroff                      unsigned NumElements, TypeClass TypeClass) {
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ElementType.getAsOpaquePtr());
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddInteger(NumElements);
64873322924127c873c13101b705dd823f5539ffa5fSteve Naroff    ID.AddInteger(TypeClass);
64973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
65073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const Type *T) {
65173322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector;
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const VectorType *) { return true; }
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
65673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// OCUVectorType - Extended vector type. This type is created using
65773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((ocu_vector_type(n)), where "n" is the number of elements.
658fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// Unlike vector_size, ocu_vector_type is only allowed on typedef's. This
659fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing
660fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language).
66173322924127c873c13101b705dd823f5539ffa5fSteve Naroffclass OCUVectorType : public VectorType {
66273322924127c873c13101b705dd823f5539ffa5fSteve Naroff  OCUVectorType(QualType vecType, unsigned nElements, QualType canonType) :
66373322924127c873c13101b705dd823f5539ffa5fSteve Naroff    VectorType(OCUVector, vecType, nElements, canonType) {}
66473322924127c873c13101b705dd823f5539ffa5fSteve Naroff  friend class ASTContext;  // ASTContext creates these.
66573322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic:
66688dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getPointAccessorIdx(char c) {
66788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
66888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
66988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'x': return 0;
67088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'y': return 1;
67188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'z': return 2;
67288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'w': return 3;
67388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
674e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
67588dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getColorAccessorIdx(char c) {
67688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
67788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
67888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'r': return 0;
67988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'g': return 1;
68088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'b': return 2;
68188dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'a': return 3;
68288dca0464804b8b26ae605f89784c927e8493dddChris Lattner    }
683e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
68488dca0464804b8b26ae605f89784c927e8493dddChris Lattner  static int getTextureAccessorIdx(char c) {
68588dca0464804b8b26ae605f89784c927e8493dddChris Lattner    switch (c) {
68688dca0464804b8b26ae605f89784c927e8493dddChris Lattner    default: return -1;
68788dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 's': return 0;
68888dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 't': return 1;
68988dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'p': return 2;
69088dca0464804b8b26ae605f89784c927e8493dddChris Lattner    case 'q': return 3;
691e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff    }
69288dca0464804b8b26ae605f89784c927e8493dddChris Lattner  };
693b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
694b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  static int getAccessorIdx(char c) {
695b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getPointAccessorIdx(c)+1) return idx-1;
696b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getColorAccessorIdx(c)+1) return idx-1;
697b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    return getTextureAccessorIdx(c);
698b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
699b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
70088dca0464804b8b26ae605f89784c927e8493dddChris Lattner  bool isAccessorWithinNumElements(char c) const {
701b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner    if (int idx = getAccessorIdx(c)+1)
70288dca0464804b8b26ae605f89784c927e8493dddChris Lattner      return unsigned(idx-1) < NumElements;
70388dca0464804b8b26ae605f89784c927e8493dddChris Lattner    return false;
704e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff  }
70531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
70631a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
7077064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff  static bool classof(const Type *T) {
70873322924127c873c13101b705dd823f5539ffa5fSteve Naroff    return T->getTypeClass() == OCUVector;
70973322924127c873c13101b705dd823f5539ffa5fSteve Naroff  }
71073322924127c873c13101b705dd823f5539ffa5fSteve Naroff  static bool classof(const OCUVectorType *) { return true; }
71173322924127c873c13101b705dd823f5539ffa5fSteve Naroff};
71273322924127c873c13101b705dd823f5539ffa5fSteve Naroff
7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators.  This is the common base
7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class of FunctionTypeNoProto and FunctionTypeProto.
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type {
7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// SubClassData - This field is owned by the subclass, put here to pack
7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// tightly with the ivars in Type.
7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool SubClassData : 1;
7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // The type returned by the function.
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType ResultType;
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected:
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical)
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {}
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getSubClassData() const { return SubClassData; }
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getResultType() const { return ResultType; }
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto ||
7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer           T->getTypeClass() == FunctionProto;
7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionType *) { return true; }
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments.
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode {
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeNoProto(QualType Result, QualType Canonical)
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionNoProto, Result, false, Canonical) {}
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // No additional state past what FunctionType provides.
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID) {
7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Profile(ID, getResultType());
7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) {
7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    ID.AddPointer(ResultType.getAsOpaquePtr());
7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionNoProto;
7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeNoProto *) { return true; }
7612b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek
7622b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenekprotected:
7632b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
7642b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
7652b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek  friend class Type;
7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeProto - Represents a prototype with argument type info, e.g.
7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'.  'void' is represented as having no
7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument.
7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs,
7735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                    bool isVariadic, QualType Canonical)
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    : FunctionType(FunctionProto, Result, isVariadic, Canonical),
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      NumArgs(numArgs) {
776942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    // Fill in the trailing argument array.
777942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);;
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    for (unsigned i = 0; i != numArgs; ++i)
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      ArgInfo[i] = ArgArray[i];
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// NumArgs - The number of arguments this function has, not counting '...'.
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned NumArgs;
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
785942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// ArgInfo - There is an variable size array after the class in memory that
786942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  /// holds the argument types.
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  unsigned getNumArgs() const { return NumArgs; }
7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  QualType getArgType(unsigned i) const {
7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(i < NumArgs && "Invalid argument number!");
792942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return arg_type_begin()[i];
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool isVariadic() const { return getSubClassData(); }
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  typedef const QualType *arg_type_iterator;
798942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_begin() const {
799942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner    return reinterpret_cast<const QualType *>(this+1);
800942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  }
801942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner  arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; }
8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) {
8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return T->getTypeClass() == FunctionProto;
8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const FunctionTypeProto *) { return true; }
8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void Profile(llvm::FoldingSetNodeID &ID);
8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
812942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      arg_type_iterator ArgTys, unsigned NumArgs,
813942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner                      bool isVariadic);
81403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek
81503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected:
81603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
81703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
81803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek  friend class Type;
8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type {
8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *Decl;
824c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected:
825c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  TypedefType(TypeClass tc, TypedefDecl *D, QualType can)
826c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian    : Type(tc, can), Decl(D) {
8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!isa<TypedefType>(can) && "Invalid canonical type");
8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TypedefDecl *getDecl() const { return Decl; }
833a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner
834a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
835a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// potentially looking through *all* consequtive typedefs.  This returns the
836a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// sum of the type qualifiers, so if you have:
837a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef const int A;
838a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  ///   typedef volatile A B;
839a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  /// looking through the typedefs for B will give you "const volatile A".
840a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner  QualType LookThroughTypedefs() const;
8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == TypeName; }
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TypedefType *) { return true; }
846b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek
847b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenekprotected:
848b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
849b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek  static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D);
850b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek  friend class Type;
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
853d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfExpr (GCC extension).
854d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfExpr : public Type {
855d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *TOExpr;
856d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) {
857d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
858d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
859d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
860d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
861d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  Expr *getUnderlyingExpr() const { return TOExpr; }
862d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
863d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
864d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
865d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; }
866d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfExpr *) { return true; }
867d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
868d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
869d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension).
870d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type {
871d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType TOType;
872d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) {
873d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff    assert(!isa<TypedefType>(can) && "Invalid canonical type");
874d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  }
875d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  friend class ASTContext;  // ASTContext creates these.
876d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic:
877d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  QualType getUnderlyingType() const { return TOType; }
878d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
879d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
880d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff
881d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; }
882d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff  static bool classof(const TypeOfType *) { return true; }
883d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff};
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type {
886aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek  TagDecl *decl;
887aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek  TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {}
8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  friend class ASTContext;  // ASTContext creates these.
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
891aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek  TagDecl *getDecl() const { return decl; }
8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  virtual void getAsStringInternal(std::string &InnerString) const;
8945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T) { return T->getTypeClass() == Tagged; }
8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const TagType *) { return true; }
897a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek
898a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenekprotected:
899a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek  virtual void EmitImpl(llvm::Serializer& S) const;
90021d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
901a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek  friend class Type;
9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
904a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type {
905a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *Decl;
90606cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected:
907a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) :
90806cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian    Type(tc, QualType()), Decl(D) { }
9093536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  friend class ASTContext;  // ASTContext creates these.
9103536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic:
9113536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
912a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCInterfaceDecl *getDecl() const { return Decl; }
9133536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
9143536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  virtual void getAsStringInternal(std::string &InnerString) const;
9154b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian
9163536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  static bool classof(const Type *T) {
917a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return T->getTypeClass() == ObjCInterface;
9183536b443bc50d58a79f14fca9b6842541a434854Steve Naroff  }
919a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCInterfaceType *) { return true; }
9203536b443bc50d58a79f14fca9b6842541a434854Steve Naroff};
9213536b443bc50d58a79f14fca9b6842541a434854Steve Naroff
922a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types
923e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian/// conforming to a list of protocols; such as, INTF<Proto1, Proto2, Proto1>.
924878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in
925878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order.
926a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType,
92706cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian                                   public llvm::FoldingSetNode {
92806cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian
929e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian  // List of protocols for this protocol conforming object type
930e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian  // List is sorted on protocol name. No protocol is enterred more than once.
931a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
932e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian
933a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
934a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                             ObjCProtocolDecl **Protos,  unsigned NumP) :
935a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    ObjCInterfaceType(ObjCQualifiedInterface, D),
93600bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner    Protocols(Protos, Protos+NumP) { }
9374b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  friend class ASTContext;  // ASTContext creates these.
938e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic:
939e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian
940a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl *getProtocols(unsigned i) const {
9414b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    return Protocols[i];
9424b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  }
9434b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  unsigned getNumProtocols() const {
9444b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian    return Protocols.size();
9454b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  }
946a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl **getReferencedProtocols() {
947411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian    return &Protocols[0];
948411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian  }
9494b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  virtual void getAsStringInternal(std::string &InnerString) const;
9504b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian
9514b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  void Profile(llvm::FoldingSetNodeID &ID);
9524b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian  static void Profile(llvm::FoldingSetNodeID &ID,
953a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
9544b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian
955e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian  static bool classof(const Type *T) {
956a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return T->getTypeClass() == ObjCQualifiedInterface;
957e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian  }
958a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCQualifiedInterfaceType *) { return true; }
959e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian};
960c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
961a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedIdType - to represent id<protocol-list>
962a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedIdType : public Type,
963c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian                            public llvm::FoldingSetNode {
964c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  // List of protocols for this protocol conforming 'id' type
965c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  // List is sorted on protocol name. No protocol is enterred more than once.
966a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
967c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
968a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCQualifiedIdType(QualType can, ObjCProtocolDecl **Protos,  unsigned NumP)
969a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  : Type(ObjCQualifiedId, can),
970c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  Protocols(Protos, Protos+NumP) { }
971c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  friend class ASTContext;  // ASTContext creates these.
972c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianpublic:
973c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
974a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl *getProtocols(unsigned i) const {
975c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian    return Protocols[i];
976c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  }
977c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  unsigned getNumProtocols() const {
978c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian    return Protocols.size();
979c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  }
980a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  ObjCProtocolDecl **getReferencedProtocols() {
981411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian    return &Protocols[0];
982411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian  }
983c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
984c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  virtual void getAsStringInternal(std::string &InnerString) const;
985c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
986c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  void Profile(llvm::FoldingSetNodeID &ID);
987c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  static void Profile(llvm::FoldingSetNodeID &ID,
988a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                      ObjCProtocolDecl **protocols, unsigned NumProtocols);
989c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
990c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  static bool classof(const Type *T) {
991a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek    return T->getTypeClass() == ObjCQualifiedId;
992c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian  }
993a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  static bool classof(const ObjCQualifiedIdType *) { return true; }
994c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian
995c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian};
996e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// RecordType - This is a helper class that allows the use of isa/cast/dyncast
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to detect TagType objects of structs/unions/classes.
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass RecordType : public TagType {
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RecordType(); // DO NOT IMPLEMENT
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1003dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff  RecordDecl *getDecl() const {
10045d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner    return reinterpret_cast<RecordDecl*>(TagType::getDecl());
10055d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner  }
10065d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // FIXME: This predicate is a helper to QualType/Type. It needs to
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // recursively check all fields for const-ness. If any field is declared
10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // const, it needs to return false.
10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasConstFields() const { return false; }
10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const Type *T);
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool classof(const RecordType *) { return true; }
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1017611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions.
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getCanonicalType - Return the canonical version of this type, with the
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// appropriate type qualifiers on it.
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline QualType QualType::getCanonicalType() const {
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return QualType(getTypePtr()->getCanonicalTypeInternal().getTypePtr(),
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getQualifiers() |
10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                  getTypePtr()->getCanonicalTypeInternal().getQualifiers());
10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1026611c1fff195d32df97706e0920c92468b2509900Chris Lattner
1027611c1fff195d32df97706e0920c92468b2509900Chris Lattner
1028611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const {
1029611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<FunctionType>(CanonicalType);
1030611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1031611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const {
10327359f04a80cae1dcbd944ee07eb50a27ce7f5077Fariborz Jahanian  return isa<PointerType>(CanonicalType);
1033611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1034498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const {
103501c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek  if (const PointerType* T = getAsPointerType())
1036498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return T->getPointeeType()->isFunctionType();
1037498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek  else
1038498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek    return false;
1039498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek}
1040611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isReferenceType() const {
1041611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ReferenceType>(CanonicalType);
1042611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1043611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const {
1044611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<ArrayType>(CanonicalType);
1045611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1046611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const {
1047611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<RecordType>(CanonicalType);
1048611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1049611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const {
1050611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<VectorType>(CanonicalType);
1051611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1052611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isOCUVectorType() const {
1053611c1fff195d32df97706e0920c92468b2509900Chris Lattner  return isa<OCUVectorType>(CanonicalType);
1054611c1fff195d32df97706e0920c92468b2509900Chris Lattner}
1055a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const {
1056a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  return isa<ObjCInterfaceType>(CanonicalType)
1057a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek           || isa<ObjCQualifiedInterfaceType>(CanonicalType);
1058e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian}
1059a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const {
1060a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek  return isa<ObjCQualifiedIdType>(CanonicalType);
1061d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian}
10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1065