Type.h revision 8e7dafec4b70303dfaff95151cd06bfc5532720c
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; 47c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman class IncompleteArrayType; 48dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff class RecordType; 49c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner class ComplexType; 507064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff class TagType; 517064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff class FunctionType; 527064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff class OCUVectorType; 5377878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff class BuiltinType; 54a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCQualifiedInterfaceType; 5592866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer uintptr_t ThePtr; 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType() : ThePtr(0) {} 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType(Type *Ptr, unsigned Quals) { 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!"); 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ThePtr = reinterpret_cast<uintptr_t>(Ptr); 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?"); 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ThePtr |= Quals; 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T.ThePtr = reinterpret_cast<uintptr_t>(Ptr); 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 92f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner unsigned getCVRQualifiers() const { 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr & CVRFlags; 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *getTypePtr() const { 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return reinterpret_cast<Type*>(ThePtr & ~CVRFlags); 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *getAsOpaquePtr() const { 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return reinterpret_cast<void*>(ThePtr); 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr == 0; 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 117b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner return (ThePtr & Const) ? true : false; 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 120b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner return (ThePtr & Volatile) ? true : false; 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 123b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner return (ThePtr & Restrict) ? true : false; 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1257effa1aceac1219529af23c776835f855b8d905cChris Lattner 1267effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1277effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1287effa1aceac1219529af23c776835f855b8d905cChris Lattner void addConst() { ThePtr |= Const; } 1297effa1aceac1219529af23c776835f855b8d905cChris Lattner void addVolatile() { ThePtr |= Volatile; } 1307effa1aceac1219529af23c776835f855b8d905cChris Lattner void addRestrict() { ThePtr |= Restrict; } 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 136ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline QualType getUnqualifiedType() const; 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr == RHS.ThePtr; 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr != RHS.ThePtr; 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string getAsString() const { 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getAsStringInternal(S); 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void getAsStringInternal(std::string &Str) const; 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void dump(const char *s = 0) const; 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCanonicalType - Return the canonical version of this type, with the 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// appropriate type qualifiers on it. 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer inline QualType getCanonicalType() const; 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 159ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 160ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 161ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 16203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Emit - Serialize a QualType to Bitcode. 16373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek void Emit(llvm::Serializer& S) const; 16473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 16503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Read - Deserialize a QualType from Bitcode. 16603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static QualType ReadVal(llvm::Deserializer& D); 16721d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek 16821d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenekprivate: 16921d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek void ReadBackpatch(llvm::Deserializer& D); 17021d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek friend class FieldDecl; 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 18673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 18773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// TypeNameType). Its CanonicalType pointer points to the 'int' Type. Next 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 219fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff Builtin, Complex, Pointer, Reference, 220c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ConstantArray, VariableArray, IncompleteArray, 221fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff Vector, OCUVector, 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionNoProto, FunctionProto, 223ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb TypeName, Tagged, ASQual, 224a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterface, ObjCQualifiedInterface, 225a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedId, 226d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff TypeOfExp, TypeOfTyp // GNU typeof extension. 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 234ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned TC : 5; 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 236124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 237124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type(TypeClass tc, QualType Canonical) 239f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 240f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner TC(tc) {} 2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual ~Type(); 2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 24373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 24473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek void EmitTypeInternal(llvm::Serializer& S) const; 24573af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek void ReadTypeInternal(llvm::Deserializer& D); 24673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2478b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 248a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isObjectType - types that fully describe objects. An object is a region 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of memory that can be examined and stored into (H&S). 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 265d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 266d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 267d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 268d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 2695c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff /// isIncompleteArrayType (C99 6.2.5p22) - Return true for variable array 2705c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff /// types that don't have any expression ("[]"). 2715c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff bool isIncompleteArrayType() const; 2725c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 274ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 27596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 27696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 27796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 27913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 28013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 28113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 28233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 28602f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 28702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 292c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 293c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 294c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 295c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isAggregateType() const; // C99 6.2.5p21 (arrays, structures) 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 297c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 298ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 299c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 300befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 301498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek bool isFunctionPointerType() const; 302a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 303c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 304c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 305c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3064cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 3074cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isComplexIntegerType() const; // GCC complex int type. 308c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVectorType() const; // GCC vector type. 309c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isOCUVectorType() const; // OCU vector type. 310a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek bool isObjCInterfaceType() const; // includes conforming protocol type 311a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek bool isObjCQualifiedIdType() const; // id includes conforming protocol type 312c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 313c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 314f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 315f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 31677878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff const BuiltinType *getAsBuiltinType() const; 317c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const FunctionType *getAsFunctionType() const; 318befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 319a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 320c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const ArrayType *getAsArrayType() const; 321d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff const ConstantArrayType *getAsConstantArrayType() const; 322d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff const VariableArrayType *getAsVariableArrayType() const; 323c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman const IncompleteArrayType *getAsIncompleteArrayType() const; 324c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 325c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsStructureType() const; 326c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 327c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 328c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 3294cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 330c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const OCUVectorType *getAsOCUVectorType() const; // OCU vector type. 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 332dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 333dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// type type. This takes off typedefs, typeof's etc. If the outer level of 334dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 335dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 3363830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 337dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 338dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner const Type *getDesugaredType() const; 339dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 3415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 344d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 345d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 346d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 350d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 351d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 352d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 354d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 3569bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 3579bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 3583c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class QualType; 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const = 0; 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 36503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 36603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 36703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Emit - Emit a Type to bitcode. Used by ASTContext. 36803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek void Emit(llvm::Serializer& S) const; 36903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 37003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Create - Construct a Type from bitcode. Used by ASTContext. 37103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S); 37203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 37303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// EmitImpl - Subclasses must implement this method in order to 37403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// be serialized. 37503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 378ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26 379ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// This supports address space qualified types. 380ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 381ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambclass ASQualType : public Type, public llvm::FoldingSetNode { 382f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 383f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 384f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 385f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 386ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 387ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 388f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) : 389ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb Type(ASQual, CanonicalPtr), BaseType(Base), AddressSpace(AddrSpace) { 390ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 391ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 392ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 393f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 394ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned getAddressSpace() const { return AddressSpace; } 395ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 396ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb virtual void getAsStringInternal(std::string &InnerString) const; 397ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 398ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 399ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb Profile(ID, getBaseType(), AddressSpace); 400ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 401f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 402ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddrSpace) { 403f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 404ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 405ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 406ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 407ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb static bool classof(const Type *T) { return T->getTypeClass() == ASQual; } 408ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb static bool classof(const ASQualType *) { return true; } 409ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 410ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambprotected: 411ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb virtual void EmitImpl(llvm::Serializer& S) const; 412ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 413ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class Type; 414ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 415ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 416ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 4235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 4255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 4265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 4305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Float, Double, LongDouble 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {} 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type(Complex, CanonicalPtr), ElementType(Element) { 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 46803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 47873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 47903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 48003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 48103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 48203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek friend class Type; 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PointerType - C99 6.7.5.1 - Pointer Declarators. 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass PointerType : public Type, public llvm::FoldingSetNode { 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType PointeeType; 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type(Pointer, CanonicalPtr), PointeeType(Pointee) { 4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getPointeeType() const { return PointeeType; } 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 51003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 51103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 51203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 51303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 51403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek friend class Type; 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ReferenceType - C++ 8.3.2 - Reference Declarators. 5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ReferenceType : public Type, public llvm::FoldingSetNode { 5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ReferenceeType; 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ReferenceType(QualType Referencee, QualType CanonicalRef) : 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type(Reference, CanonicalRef), ReferenceeType(Referencee) { 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getReferenceeType() const { return ReferenceeType; } 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getReferenceeType()); 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Reference; } 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5432e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an array with a static size (e.g. int X[static 4]), or with a star size 547c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// (e.g. int X[*]). 'static' is only allowed on function parameters. 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 552fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 553fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 554c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 555ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 556c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 557ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 558c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 559c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 560c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 561c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 562c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 563fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 564c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 565c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 566c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 567fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 568fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 569fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 570ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 571ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 572ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 573c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 574fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 5757cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff QualType getBaseType() const { 5767cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff const ArrayType *AT; 5777cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff QualType ElmtType = getElementType(); 5787cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff // If we have a multi-dimensional array, navigate to the base type. 5797cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff while ((AT = ElmtType->getAsArrayType())) 5807cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff ElmtType = AT->getElementType(); 5817cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff return ElmtType; 5827cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff } 583fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 584fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 585c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 586c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == IncompleteArray; 587fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 588fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 589fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 590fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 5912e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 592fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 593fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 594c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ConstantArrayType(QualType et, QualType can, llvm::APInt sz, 595c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 596c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {} 597fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 598fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 599fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt getSize() const { return Size; } 6007cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff int getMaximumElements() const { 6017cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff QualType ElmtType = getElementType(); 602124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser int maxElements = static_cast<int>(getSize().getZExtValue()); 603fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 6047cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff const ConstantArrayType *CAT; 6057cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff // If we have a multi-dimensional array, include it's elements. 6067cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff while ((CAT = ElmtType->getAsConstantArrayType())) { 6077cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff ElmtType = CAT->getElementType(); 608124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser maxElements *= static_cast<int>(CAT->getSize().getZExtValue()); 6097cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff } 6107cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff return maxElements; 6117cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff } 612fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 613fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 614fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 615fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff Profile(ID, getElementType(), getSize()); 616fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 617fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 618fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt ArraySize) { 619fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 620fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 621fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 622fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 623fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray; 624fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 625fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 626da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek 627da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenekprotected: 628da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 629da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 630da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek friend class Type; 631fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 632fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 633c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 634c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 635c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArraySizeModifier sm, unsigned tq) 636c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 637c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 638c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 639c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 640c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 641c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 642c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 643c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 644c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 645c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 646c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 647c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 648c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 649c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 650c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Profile(ID, getElementType()); 651c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 652c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 653c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) { 654c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 655c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 656c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 657c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanprotected: 658c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman virtual void EmitImpl(llvm::Serializer& S) const; 659c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 660c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class Type; 661c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 662c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 663fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff// FIXME: VariableArrayType's aren't uniqued (since expressions aren't). 6642e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 665fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 666fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *SizeExpr; 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 669c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 670c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 671c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff : ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {} 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6746e999782a102eb444cfc7b8eaa64f84911fdcf4fChris Lattner const Expr *getSizeExpr() const { return SizeExpr; } 6756e999782a102eb444cfc7b8eaa64f84911fdcf4fChris Lattner Expr *getSizeExpr() { return SizeExpr; } 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 679fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 680fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 682fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 683a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 68492866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 6852bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 6862bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 687c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman assert (0 && "Cannnot unique VariableArrayTypes."); 6882bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 689ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek 690ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenekprotected: 691ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 692ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 693ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek friend class Type; 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 69673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 69773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 69873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 69973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 70173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 70873322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 70973322924127c873c13101b705dd823f5539ffa5fSteve Naroff Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {} 71073322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 71173322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType canonType) : Type(tc, canonType), ElementType(vecType), 71273322924127c873c13101b705dd823f5539ffa5fSteve Naroff NumElements(nElements) {} 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 72273322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 72473322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 72573322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 72873322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 72973322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 73073322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 73173322924127c873c13101b705dd823f5539ffa5fSteve Naroff return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector; 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 73673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// OCUVectorType - Extended vector type. This type is created using 73773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((ocu_vector_type(n)), where "n" is the number of elements. 738fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// Unlike vector_size, ocu_vector_type is only allowed on typedef's. This 739fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 740fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 74173322924127c873c13101b705dd823f5539ffa5fSteve Naroffclass OCUVectorType : public VectorType { 74273322924127c873c13101b705dd823f5539ffa5fSteve Naroff OCUVectorType(QualType vecType, unsigned nElements, QualType canonType) : 74373322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(OCUVector, vecType, nElements, canonType) {} 74473322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 74573322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 74688dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 74788dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 74888dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 74988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 75088dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 75188dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 75288dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 75388dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 754e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 75588dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getColorAccessorIdx(char c) { 75688dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 75788dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 75888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'r': return 0; 75988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'g': return 1; 76088dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'b': return 2; 76188dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'a': return 3; 76288dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 763e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 76488dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getTextureAccessorIdx(char c) { 76588dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 76688dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 76788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 's': return 0; 76888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 't': return 1; 76988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'p': return 2; 77088dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'q': return 3; 771e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 77288dca0464804b8b26ae605f89784c927e8493dddChris Lattner }; 773b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 774b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 775b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 776b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getColorAccessorIdx(c)+1) return idx-1; 777b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner return getTextureAccessorIdx(c); 778b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 779b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 78088dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 781b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 78288dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 78388dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 784e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 78531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 78631a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 7877064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 78873322924127c873c13101b705dd823f5539ffa5fSteve Naroff return T->getTypeClass() == OCUVector; 78973322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 79073322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const OCUVectorType *) { return true; } 79173322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 79273322924127c873c13101b705dd823f5539ffa5fSteve Naroff 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class of FunctionTypeNoProto and FunctionTypeProto. 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical) 8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {} 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 8145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 8215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode { 8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionTypeNoProto(QualType Result, QualType Canonical) 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : FunctionType(FunctionNoProto, Result, false, Canonical) {} 8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionTypeNoProto *) { return true; } 8412b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek 8422b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenekprotected: 8432b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 8442b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 8452b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek friend class Type; 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeProto - Represents a prototype with argument type info, e.g. 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument. 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode { 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs, 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic, QualType Canonical) 8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : FunctionType(FunctionProto, Result, isVariadic, Canonical), 8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer NumArgs(numArgs) { 856942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 857942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 865942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 866942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 872942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 878942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 879942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 880942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 881942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionTypeProto *) { return true; } 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 892942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 893942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner bool isVariadic); 89403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 89503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 89603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 89703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 89803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek friend class Type; 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 904c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 905c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 906c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian : Type(tc, can), Decl(D) { 9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 913a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 914a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 915a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// potentially looking through *all* consequtive typedefs. This returns the 916a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 917a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 918a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 919a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 920a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == TypeName; } 9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 926b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek 927b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenekprotected: 928b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 929b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 930b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek friend class Type; 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 933d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfExpr (GCC extension). 934d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfExpr : public Type { 935d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 936d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) { 937d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 938d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 939d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 940d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 941d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 942d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 943d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 944d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 945d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; } 946d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfExpr *) { return true; } 947d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 948d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 949d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 950d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 951d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 952d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) { 953d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 954d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 955d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 956d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 957d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 958d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 959d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 960d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 961d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; } 962d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 963d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 966aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek TagDecl *decl; 967aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {} 9685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 971aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek TagDecl *getDecl() const { return decl; } 9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Tagged; } 9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 977a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek 978a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenekprotected: 979a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 98021d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 981a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek friend class Type; 9825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 984a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 985a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 98606cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 987a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 98806cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian Type(tc, QualType()), Decl(D) { } 9893536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 9903536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 9913536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 992a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 9933536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 9943536b443bc50d58a79f14fca9b6842541a434854Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 9954b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 9963536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 997a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCInterface; 9983536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 999a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 10003536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 10013536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1002a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1003e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian/// conforming to a list of protocols; such as, INTF<Proto1, Proto2, Proto1>. 1004878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1005878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 1006a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 100706cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 100806cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1009e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1010e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1011a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1012e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1013a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1014a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **Protos, unsigned NumP) : 1015a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 101600bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 10174b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1018e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1019e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1020a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 10214b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols[i]; 10224b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 10234b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 10244b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 10254b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1026a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1027411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian return &Protocols[0]; 1028411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian } 10294b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 10304b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 10314b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 10324b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 1033a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 10344b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1035e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1036a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1037e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1038a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1039e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1040c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1041a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedIdType - to represent id<protocol-list> 1042a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedIdType : public Type, 1043c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian public llvm::FoldingSetNode { 1044c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List of protocols for this protocol conforming 'id' type 1045c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1046a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1047c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1048a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedIdType(QualType can, ObjCProtocolDecl **Protos, unsigned NumP) 1049a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek : Type(ObjCQualifiedId, can), 1050c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian Protocols(Protos, Protos+NumP) { } 1051c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1052c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianpublic: 1053c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1054a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 1055c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols[i]; 1056c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1057c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian unsigned getNumProtocols() const { 1058c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols.size(); 1059c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1060a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1061411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian return &Protocols[0]; 1062411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian } 1063c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1064c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 1065c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1066c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 1067c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 1068a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 1069c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1070c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian static bool classof(const Type *T) { 1071a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedId; 1072c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1073a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedIdType *) { return true; } 1074c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1075c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian}; 1076e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 10785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to detect TagType objects of structs/unions/classes. 10795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass RecordType : public TagType { 10805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RecordType(); // DO NOT IMPLEMENT 10815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1083dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff RecordDecl *getDecl() const { 10845d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 10855d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner } 10865d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner 10875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // FIXME: This predicate is a helper to QualType/Type. It needs to 10885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // recursively check all fields for const-ness. If any field is declared 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // const, it needs to return false. 10908e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman bool hasConstFields() const { return false; } 10918e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman 10928e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman // FIXME: RecordType needs to check when it is created that all fields are in 10938e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman // the same address space, and return that. 10948e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman unsigned getAddressSpace() const { return 0; } 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T); 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const RecordType *) { return true; } 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1101611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getCanonicalType - Return the canonical version of this type, with the 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// appropriate type qualifiers on it. 11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline QualType QualType::getCanonicalType() const { 1106f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner QualType CanType = getTypePtr()->getCanonicalTypeInternal(); 1107f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(CanType.getTypePtr(), 1108f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner getCVRQualifiers() | CanType.getCVRQualifiers()); 11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1110611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1111ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 1112ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 1113f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 1114f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP)) 1115f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner TP = ASQT->getBaseType(); 1116f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 1117ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1118ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1119ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 1120ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 11218e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman if (const ArrayType *AT = dyn_cast<ArrayType>(getCanonicalType())) 11228e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return AT->getBaseType().getAddressSpace(); 11238e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman if (const RecordType *RT = dyn_cast<RecordType>(getCanonicalType())) 11248e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 1125f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner if (const ASQualType *ASQT = dyn_cast<ASQualType>(getCanonicalType())) 1126ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return ASQT->getAddressSpace(); 1127ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 1128ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1129611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1130611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 1131ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1132611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1133611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 1134ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1135611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1136498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 113701c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 1138498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 1139498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 1140498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 1141498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 1142611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isReferenceType() const { 1143ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1144611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1145611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 1146ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1147611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1148611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 1149ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1150611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1151611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 1152ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1153611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1154611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isOCUVectorType() const { 1155ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<OCUVectorType>(CanonicalType.getUnqualifiedType()); 1156611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1157a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 1158a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return isa<ObjCInterfaceType>(CanonicalType) 1159a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek || isa<ObjCQualifiedInterfaceType>(CanonicalType); 1160e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 1161a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 1162a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return isa<ObjCQualifiedIdType>(CanonicalType); 1163d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1167