Type.h revision 368eefa081d12f0a265ee90ee8ec61b54168d57d
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; 41bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner class PointerLikeType; 423acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner class PointerType; 43251dcaf8616c6f04051e214f35cadb7de42aef7eBill Wendling class ReferenceType; 443acb13805673d47be95829bd5a4b1707952c0b6fChris Lattner class VectorType; 45700204c74b455746752e851b25565ebf932f5340Steve Naroff class ArrayType; 46d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff class ConstantArrayType; 47d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff class VariableArrayType; 48c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman class IncompleteArrayType; 49dfa6aae5a119a527e537c35566ba3272fd8c5d74Steve Naroff class RecordType; 50c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner class ComplexType; 517064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff class TagType; 527064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff class FunctionType; 537064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff class OCUVectorType; 5477878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff class BuiltinType; 55368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner class ObjCInterfaceType; 56368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner class ObjCQualifiedIdType; 57a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCQualifiedInterfaceType; 5892866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer uintptr_t ThePtr; 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType() : ThePtr(0) {} 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType(Type *Ptr, unsigned Quals) { 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert((Quals & ~CVRFlags) == 0 && "Invalid type qualifiers!"); 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ThePtr = reinterpret_cast<uintptr_t>(Ptr); 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert((ThePtr & CVRFlags) == 0 && "Type pointer not 8-byte aligned?"); 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ThePtr |= Quals; 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T.ThePtr = reinterpret_cast<uintptr_t>(Ptr); 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner unsigned getCVRQualifiers() const { 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr & CVRFlags; 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *getTypePtr() const { 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return reinterpret_cast<Type*>(ThePtr & ~CVRFlags); 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *getAsOpaquePtr() const { 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return reinterpret_cast<void*>(ThePtr); 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr == 0; 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 120b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner return (ThePtr & Const) ? true : false; 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 123b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner return (ThePtr & Volatile) ? true : false; 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 126b8128140956c6f8f0ab143818775a81f4b4aa477Chris Lattner return (ThePtr & Restrict) ? true : false; 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1287effa1aceac1219529af23c776835f855b8d905cChris Lattner 1297effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1307effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1317effa1aceac1219529af23c776835f855b8d905cChris Lattner void addConst() { ThePtr |= Const; } 1327effa1aceac1219529af23c776835f855b8d905cChris Lattner void addVolatile() { ThePtr |= Volatile; } 1337effa1aceac1219529af23c776835f855b8d905cChris Lattner void addRestrict() { ThePtr |= Restrict; } 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 139ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline QualType getUnqualifiedType() const; 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr == RHS.ThePtr; 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return ThePtr != RHS.ThePtr; 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string getAsString() const { 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getAsStringInternal(S); 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void getAsStringInternal(std::string &Str) const; 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void dump(const char *s = 0) const; 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 158368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner//private: 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCanonicalType - Return the canonical version of this type, with the 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// appropriate type qualifiers on it. 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer inline QualType getCanonicalType() const; 162368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 164ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 165ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 166ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 16703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Emit - Serialize a QualType to Bitcode. 16873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek void Emit(llvm::Serializer& S) const; 16973af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 17003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Read - Deserialize a QualType from Bitcode. 17103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static QualType ReadVal(llvm::Deserializer& D); 17221d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek 17321d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenekprivate: 17421d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek void ReadBackpatch(llvm::Deserializer& D); 17521d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek friend class FieldDecl; 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 19173af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 19273af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// TypeNameType). Its CanonicalType pointer points to the 'int' Type. Next 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 224fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff Builtin, Complex, Pointer, Reference, 225c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ConstantArray, VariableArray, IncompleteArray, 226fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff Vector, OCUVector, 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionNoProto, FunctionProto, 228ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb TypeName, Tagged, ASQual, 229a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterface, ObjCQualifiedInterface, 230a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedId, 231d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff TypeOfExp, TypeOfTyp // GNU typeof extension. 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 239ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned TC : 5; 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 241124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 242124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type(TypeClass tc, QualType Canonical) 244f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 245f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner TC(tc) {} 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual ~Type(); 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 24873af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 24973af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek void EmitTypeInternal(llvm::Serializer& S) const; 25073af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek void ReadTypeInternal(llvm::Deserializer& D); 25173af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2528b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 253a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isObjectType - types that fully describe objects. An object is a region 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of memory that can be examined and stored into (H&S). 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 269d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 270d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 271d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 272d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 273d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 274d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 276d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 277d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 278d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 279d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 2805c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff /// isIncompleteArrayType (C99 6.2.5p22) - Return true for variable array 2815c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff /// types that don't have any expression ("[]"). 2825c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff bool isIncompleteArrayType() const; 2835c06a69a3ef19cc6dbeed7f2acb9de28b66c45d4Steve Naroff 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 285ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 28696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 28796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 28896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 29013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 29113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 29213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 29333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 29702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 29802f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 300f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 304c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 305c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 306c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 307c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isAggregateType() const; // C99 6.2.5p21 (arrays, structures) 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 309c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 310ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 311c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 312bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isPointerLikeType() const; // Pointer or Reference. 313befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 314a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 315bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 316c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 317c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 318c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3194cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 320368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 321368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 322368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isOCUVectorType() const; // OCU vector type. 323368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 324368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 325368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 326c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner 327c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 328f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 329f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 33077878cc5aa6ad01fc0c91bac1a61819dbf3bf691Steve Naroff const BuiltinType *getAsBuiltinType() const; 331c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const FunctionType *getAsFunctionType() const; 332bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner const PointerLikeType *getAsPointerLikeType() const; // Pointer or Reference. 333befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 334a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 335c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const ArrayType *getAsArrayType() const; 336d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff const ConstantArrayType *getAsConstantArrayType() const; 337d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff const VariableArrayType *getAsVariableArrayType() const; 338c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman const IncompleteArrayType *getAsIncompleteArrayType() const; 339c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 340c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsStructureType() const; 341c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 342c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 343c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 3444cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 345c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const OCUVectorType *getAsOCUVectorType() const; // OCU vector type. 346368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 347368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 348368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 349368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 351dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 352dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// type type. This takes off typedefs, typeof's etc. If the outer level of 353dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 354dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 3553830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 356dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 357dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner const Type *getDesugaredType() const; 358dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 363d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 364d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 365d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 369d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 370d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 371d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 373d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 3759bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 3769bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 3773c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class QualType; 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const = 0; 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 38403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 38503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 38603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Emit - Emit a Type to bitcode. Used by ASTContext. 38703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek void Emit(llvm::Serializer& S) const; 38803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 38903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// Create - Construct a Type from bitcode. Used by ASTContext. 39003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S); 39103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 39203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// EmitImpl - Subclasses must implement this method in order to 39303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek /// be serialized. 39403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 397ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26 398ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// This supports address space qualified types. 399ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 400ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambclass ASQualType : public Type, public llvm::FoldingSetNode { 401f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 402f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 403f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 404f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 405ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 406ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 407f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) : 408ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb Type(ASQual, CanonicalPtr), BaseType(Base), AddressSpace(AddrSpace) { 409ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 410ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 411ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 412f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 413ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned getAddressSpace() const { return AddressSpace; } 414ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 415ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb virtual void getAsStringInternal(std::string &InnerString) const; 416ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 417ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 418ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb Profile(ID, getBaseType(), AddressSpace); 419ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 420f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 421ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddrSpace) { 422f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 423ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 424ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 425ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 426ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb static bool classof(const Type *T) { return T->getTypeClass() == ASQual; } 427ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb static bool classof(const ASQualType *) { return true; } 428ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 429ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambprotected: 430ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb virtual void EmitImpl(llvm::Serializer& S) const; 431ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 432ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class Type; 433ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 434ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 435ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 4385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Float, Double, LongDouble 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BuiltinType(Kind K) : Type(Builtin, QualType()), TypeKind(K) {} 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type(Complex, CanonicalPtr), ElementType(Element) { 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 48703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 49773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 49803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 49903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 50003ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 50103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek friend class Type; 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 504bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// PointerLikeType - Common base class for pointers and references. 505bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 506bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerclass PointerLikeType : public Type { 507bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 508bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerprotected: 509bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) : 510bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Type(K, CanonicalPtr), PointeeType(Pointee) { 511bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner } 512bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerpublic: 513bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner 514bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType getPointeeType() const { return PointeeType; } 515bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner 516bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner static bool classof(const Type *T) { 517bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return T->getTypeClass() == Pointer || T->getTypeClass() == Reference; 518bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner } 519bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner static bool classof(const PointerLikeType *) { return true; } 520bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner}; 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// PointerType - C99 6.7.5.1 - Pointer Declarators. 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 524bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerclass PointerType : public PointerLikeType, public llvm::FoldingSetNode { 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 526bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner PointerLikeType(Pointer, Pointee, CanonicalPtr) { 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 54203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 54303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 54403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 54503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 54603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek friend class Type; 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ReferenceType - C++ 8.3.2 - Reference Declarators. 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 551bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerclass ReferenceType : public PointerLikeType, public llvm::FoldingSetNode { 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ReferenceType(QualType Referencee, QualType CanonicalRef) : 553bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner PointerLikeType(Reference, Referencee, CanonicalRef) { 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 560bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Reference; } 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 5722e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an array with a static size (e.g. int X[static 4]), or with a star size 576c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// (e.g. int X[*]). 'static' is only allowed on function parameters. 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 581fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 582fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 583c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 584ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 585c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 586ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 587c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 588c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 589c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 590c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 591c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 592fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 593c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 594c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 595c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff : Type(tc, can), ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 596fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 597fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 598fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 599ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 600ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 601ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 602c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 603fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 6047cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff QualType getBaseType() const { 6057cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff const ArrayType *AT; 6067cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff QualType ElmtType = getElementType(); 6077cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff // If we have a multi-dimensional array, navigate to the base type. 6087cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff while ((AT = ElmtType->getAsArrayType())) 6097cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff ElmtType = AT->getElementType(); 6107cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff return ElmtType; 6117cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff } 612fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 613fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 614c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 615c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == IncompleteArray; 616fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 617fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 618fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 619fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 6202e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 621fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 622fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 623c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ConstantArrayType(QualType et, QualType can, llvm::APInt sz, 624c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 625c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {} 626fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 627fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 628fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt getSize() const { return Size; } 6297cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff int getMaximumElements() const { 6307cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff QualType ElmtType = getElementType(); 631124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser int maxElements = static_cast<int>(getSize().getZExtValue()); 632fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 6337cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff const ConstantArrayType *CAT; 6347cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff // If we have a multi-dimensional array, include it's elements. 6357cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff while ((CAT = ElmtType->getAsConstantArrayType())) { 6367cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff ElmtType = CAT->getElementType(); 637124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser maxElements *= static_cast<int>(CAT->getSize().getZExtValue()); 6387cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff } 6397cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff return maxElements; 6407cf8c444320313f0e5b8a483daa996ba844b11ffSteve Naroff } 641fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 642fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 643fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 644fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff Profile(ID, getElementType(), getSize()); 645fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 646fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 647fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt ArraySize) { 648fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 649fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 650fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 651fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 652fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray; 653fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 654fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 655da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek 656da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenekprotected: 657da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 658da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 659da5dbb4a0ad091791bdb0dad1b9ceba3c04a7f5cTed Kremenek friend class Type; 660fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 661fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 662c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 663c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 664c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArraySizeModifier sm, unsigned tq) 665c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 666c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 667c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 668c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 669c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 670c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 671c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 672c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 673c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 674c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 675c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 676c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 677c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 678c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 679c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Profile(ID, getElementType()); 680c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 681c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 682c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) { 683c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 684c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 685c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 686c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanprotected: 687c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman virtual void EmitImpl(llvm::Serializer& S) const; 688c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 689c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class Type; 690c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 691c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 692fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff// FIXME: VariableArrayType's aren't uniqued (since expressions aren't). 6932e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 694fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 695fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 6965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Expr *SizeExpr; 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 698c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 699c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 700c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff : ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {} 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7036e999782a102eb444cfc7b8eaa64f84911fdcf4fChris Lattner const Expr *getSizeExpr() const { return SizeExpr; } 7046e999782a102eb444cfc7b8eaa64f84911fdcf4fChris Lattner Expr *getSizeExpr() { return SizeExpr; } 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 708fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 709fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 711fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 712a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 71392866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 7142bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 7152bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 716c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman assert (0 && "Cannnot unique VariableArrayTypes."); 7172bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 718ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek 719ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenekprotected: 720ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 721ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 722ed1a01d4d0ee773eb6478ff9701b46d2f0c06952Ted Kremenek friend class Type; 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 72573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 72673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 72773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 72873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 73073322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 73773322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 73873322924127c873c13101b705dd823f5539ffa5fSteve Naroff Type(Vector, canonType), ElementType(vecType), NumElements(nElements) {} 73973322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 74073322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType canonType) : Type(tc, canonType), ElementType(vecType), 74173322924127c873c13101b705dd823f5539ffa5fSteve Naroff NumElements(nElements) {} 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 75173322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 75373322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 75473322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 75773322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 75873322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 75973322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 76073322924127c873c13101b705dd823f5539ffa5fSteve Naroff return T->getTypeClass() == Vector || T->getTypeClass() == OCUVector; 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 76573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// OCUVectorType - Extended vector type. This type is created using 76673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((ocu_vector_type(n)), where "n" is the number of elements. 767fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// Unlike vector_size, ocu_vector_type is only allowed on typedef's. This 768fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 769fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 77073322924127c873c13101b705dd823f5539ffa5fSteve Naroffclass OCUVectorType : public VectorType { 77173322924127c873c13101b705dd823f5539ffa5fSteve Naroff OCUVectorType(QualType vecType, unsigned nElements, QualType canonType) : 77273322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(OCUVector, vecType, nElements, canonType) {} 77373322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 77473322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 77588dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 77688dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 77788dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 77888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 77988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 78088dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 78188dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 78288dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 783e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 78488dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getColorAccessorIdx(char c) { 78588dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 78688dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 78788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'r': return 0; 78888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'g': return 1; 78988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'b': return 2; 79088dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'a': return 3; 79188dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 792e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 79388dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getTextureAccessorIdx(char c) { 79488dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 79588dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 79688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 's': return 0; 79788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 't': return 1; 79888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'p': return 2; 79988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'q': return 3; 800e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 80188dca0464804b8b26ae605f89784c927e8493dddChris Lattner }; 802b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 803b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 804b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 805b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getColorAccessorIdx(c)+1) return idx-1; 806b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner return getTextureAccessorIdx(c); 807b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 808b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 80988dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 810b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 81188dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 81288dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 813e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 81431a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 81531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 8167064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 81773322924127c873c13101b705dd823f5539ffa5fSteve Naroff return T->getTypeClass() == OCUVector; 81873322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 81973322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const OCUVectorType *) { return true; } 82073322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 82173322924127c873c13101b705dd823f5539ffa5fSteve Naroff 8225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 8235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// class of FunctionTypeNoProto and FunctionTypeProto. 8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 8285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 8315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 8325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionType(TypeClass tc, QualType res, bool SubclassInfo,QualType Canonical) 8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : Type(tc, Canonical), SubClassData(SubclassInfo), ResultType(res) {} 8355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode { 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionTypeNoProto(QualType Result, QualType Canonical) 8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : FunctionType(FunctionNoProto, Result, false, Canonical) {} 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionTypeNoProto *) { return true; } 8702b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek 8712b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenekprotected: 8722b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 8732b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 8742b14d46231fd75ad1e58043e9fab029c54c817cbTed Kremenek friend class Type; 8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionTypeProto - Represents a prototype with argument type info, e.g. 8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument. 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode { 8815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FunctionTypeProto(QualType Result, QualType *ArgArray, unsigned numArgs, 8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic, QualType Canonical) 8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : FunctionType(FunctionProto, Result, isVariadic, Canonical), 8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer NumArgs(numArgs) { 885942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 886942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 8875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 8885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 8925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumArgs; 8935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 894942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 895942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 8965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 901942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 907942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 908942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 909942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 910942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionTypeProto *) { return true; } 9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 921942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 922942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner bool isVariadic); 92303ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 92403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenekprotected: 92503ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 92603ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 92703ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek friend class Type; 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 933c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 934c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 935c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian : Type(tc, can), Decl(D) { 9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 942a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 943a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 944a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// potentially looking through *all* consequtive typedefs. This returns the 945a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 946a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 947a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 948a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 949a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == TypeName; } 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 955b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek 956b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenekprotected: 957b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 958b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 959b28166d11e788bc99fd5cd47c4f649ea0195c3b1Ted Kremenek friend class Type; 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 962d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfExpr (GCC extension). 963d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfExpr : public Type { 964d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 965d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff TypeOfExpr(Expr *E, QualType can) : Type(TypeOfExp, can), TOExpr(E) { 966d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 967d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 968d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 969d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 970d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 971d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 972d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 973d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 974d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; } 975d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfExpr *) { return true; } 976d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 977d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 978d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 979d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 980d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 981d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff TypeOfType(QualType T, QualType can) : Type(TypeOfTyp, can), TOType(T) { 982d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 983d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 984d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 985d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 986d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 987d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 988d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 989d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 990d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; } 991d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 992d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 995aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek TagDecl *decl; 996aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {} 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1000aad48b6b2dfc81ad36a05d161c775cd6aab5b339Ted Kremenek TagDecl *getDecl() const { return decl; } 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Tagged; } 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 1006a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek 1007a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenekprotected: 1008a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 100921d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1010a225400804cc53dd9cf6b28cf0e8e7f103a7522fTed Kremenek friend class Type; 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10135edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 10145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 10155edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 10165edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordType(); // DO NOT IMPLEMENT 10175edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 10185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 10205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 10215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 10225edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 10245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 10255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 10265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 10275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 10295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 10305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 10315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10322daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 10332daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 10342daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 10352daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 10365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 10375edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 10385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 10405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 10415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 10425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumType(); // DO NOT IMPLEMENT 10435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 10445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 10465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 10475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 10485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10492daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 10502daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 10512daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 10522daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 10535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 10545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 10555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 10585edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1059a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 1060a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 106106cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 1062a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 106306cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian Type(tc, QualType()), Decl(D) { } 10643536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 10653536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 10663536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1067a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 10683536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 10693536b443bc50d58a79f14fca9b6842541a434854Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 10704b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 10713536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 1072368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return T->getTypeClass() == ObjCInterface || 1073368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner T->getTypeClass() == ObjCQualifiedInterface; 10743536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 1075a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 10763536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 10773536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1078a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1079e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian/// conforming to a list of protocols; such as, INTF<Proto1, Proto2, Proto1>. 1080878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1081878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 1082a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 108306cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 108406cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1085e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1086e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1087a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1088e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1089a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1090a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **Protos, unsigned NumP) : 1091a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 109200bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 10934b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1094e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1095e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1096a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 10974b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols[i]; 10984b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 10994b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 11004b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 11014b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1102a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1103411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian return &Protocols[0]; 1104411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian } 11054b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 11064b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 11074b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 11084b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 1109a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 11104b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1111e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1112a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1113e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1114a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1115e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1116c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1117a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedIdType - to represent id<protocol-list> 1118a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedIdType : public Type, 1119c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian public llvm::FoldingSetNode { 1120c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List of protocols for this protocol conforming 'id' type 1121c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1122a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1123c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1124a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedIdType(QualType can, ObjCProtocolDecl **Protos, unsigned NumP) 1125a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek : Type(ObjCQualifiedId, can), 1126c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian Protocols(Protos, Protos+NumP) { } 1127c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1128c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianpublic: 1129c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1130a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 1131c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols[i]; 1132c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1133c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian unsigned getNumProtocols() const { 1134c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols.size(); 1135c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1136a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1137411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian return &Protocols[0]; 1138411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian } 1139c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1140c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 1141c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1142c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 1143c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 1144a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 1145c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1146c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian static bool classof(const Type *T) { 1147a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedId; 1148c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1149a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedIdType *) { return true; } 1150c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1151c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian}; 1152e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1154611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getCanonicalType - Return the canonical version of this type, with the 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// appropriate type qualifiers on it. 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerinline QualType QualType::getCanonicalType() const { 1159f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner QualType CanType = getTypePtr()->getCanonicalTypeInternal(); 1160f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(CanType.getTypePtr(), 1161f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner getCVRQualifiers() | CanType.getCVRQualifiers()); 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1163611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1164ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 1165ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 1166f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 1167f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP)) 1168f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner TP = ASQT->getBaseType(); 1169f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 1170ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1171ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1172ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 1173ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 11748e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman if (const ArrayType *AT = dyn_cast<ArrayType>(getCanonicalType())) 11758e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return AT->getBaseType().getAddressSpace(); 11768e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman if (const RecordType *RT = dyn_cast<RecordType>(getCanonicalType())) 11778e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 1178f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner if (const ASQualType *ASQT = dyn_cast<ASQualType>(getCanonicalType())) 1179ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return ASQT->getAddressSpace(); 1180ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 1181ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1182611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1183611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 1184ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1185611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1186611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 1187ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1188611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1189bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 1190bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1191bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 1192bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isPointerLikeType() const { 1193bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<PointerLikeType>(CanonicalType.getUnqualifiedType()); 1194bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 1195498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 119601c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 1197498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 1198498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 1199498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 1200498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 1201611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 1202ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1203611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1204611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 1205ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1206611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1207f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 1208f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner return isa<ComplexType>(CanonicalType); 1209f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 1210611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 1211ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1212611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1213611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isOCUVectorType() const { 1214ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<OCUVectorType>(CanonicalType.getUnqualifiedType()); 1215611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1216a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 1217368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return isa<ObjCInterfaceType>(CanonicalType); 1218368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 1219368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 1220368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType); 1221e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 1222a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 1223a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return isa<ObjCQualifiedIdType>(CanonicalType); 1224d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1228