Type.h revision 71af02f1cea2bcedacbff2a20d883bf2b8042eb0
14b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 24b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 34b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// The LLVM Compiler Infrastructure 44b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 5959e5be188a505881058777f35abaaa3fe2de40bChris Lattner// This file is distributed under the University of Illinois Open Source 6959e5be188a505881058777f35abaaa3fe2de40bChris Lattner// License. See LICENSE.TXT for details. 74b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 84b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===----------------------------------------------------------------------===// 94b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// This file defines the Type interface and subclasses. 114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner// 124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner//===----------------------------------------------------------------------===// 134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#ifndef LLVM_CLANG_AST_TYPE_H 154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#define LLVM_CLANG_AST_TYPE_H 164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 17da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner#include "clang/Basic/Diagnostic.h" 184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#include "llvm/Support/Casting.h" 1983c13010359c33354c581acee65d0c986a75247eSteve Naroff#include "llvm/ADT/APSInt.h" 2048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/FoldingSet.h" 2148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/PointerIntPair.h" 2278f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek#include "llvm/Bitcode/SerializationFwd.h" 234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::isa; 244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast; 254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast_or_null; 264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast; 274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast_or_null; 284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class ASTContext; 314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class Type; 324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TypedefDecl; 33dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor class TemplateTypeParmDecl; 344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TagDecl; 354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class RecordDecl; 36ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis class CXXRecordDecl; 374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class EnumDecl; 3864be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek class FieldDecl; 3942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCInterfaceDecl; 4042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCProtocolDecl; 4142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCMethodDecl; 424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class Expr; 43718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek class Stmt; 444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class SourceLocation; 45cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner class PointerLikeType; 464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class PointerType; 477aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff class BlockPointerType; 484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class ReferenceType; 494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class VectorType; 504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class ArrayType; 515eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff class ConstantArrayType; 525eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff class VariableArrayType; 538ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman class IncompleteArrayType; 541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor class DependentSizedArrayType; 552cb6638a26cfa999e5fb999e6af9211127e681c1Steve Naroff class RecordType; 560832dbca0e11ee020bbed181c515b3835158436eEli Friedman class EnumType; 577a85fa1ba94c9f4cf960463dd3eb444ef6f89446Chris Lattner class ComplexType; 58806b319509d01bffe47317f11140c930da800dbbSteve Naroff class TagType; 595c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek class TypedefType; 60dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor class TemplateTypeParmType; 61806b319509d01bffe47317f11140c930da800dbbSteve Naroff class FunctionType; 62d5a56aae166344e13f1f8c845530beee0868db49Chris Lattner class FunctionTypeProto; 63af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman class ExtVectorType; 64c33c060e2f4e7c7e89e3b809f52cfc6d55ea9838Steve Naroff class BuiltinType; 65b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner class ObjCInterfaceType; 66b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner class ObjCQualifiedIdType; 6742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCQualifiedInterfaceType; 68fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek class StmtIteratorBase; 694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// their own: instead each reference to a type stores the qualifiers. This 724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// greatly reduces the number of nodes we need to allocate for types (for 734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// example we only need one for 'int', 'const int', 'volatile int', 744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'const volatile int', etc). 754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// As an added efficiency bonus, instead of making this a pair, we just store 774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// the three bits we care about in the low bits of the pointer. To handle the 784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// packing/unpacking, we make QualType be a simple wrapper class that acts like 794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// a smart pointer. 804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass QualType { 8148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner llvm::PointerIntPair<Type*, 3> Value; 824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Const = 0x1, 854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Restrict = 0x2, 864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Volatile = 0x4, 874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner CVRFlags = Const|Restrict|Volatile 884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType() {} 914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType(const Type *Ptr, unsigned Quals) 9348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 96b9b218e566459808be9f1c52b03afad3e0d39ed3Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 9748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner Type *getTypePtr() const { return Value.getPointer(); } 9848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner 9948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static QualType getFromOpaquePtr(void *Ptr) { 1014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType T; 10248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner T.Value.setFromOpaqueValue(Ptr); 1034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T; 1044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type &operator*() const { 1074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return *getTypePtr(); 1084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type *operator->() const { 1114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return getTypePtr(); 1124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isNull - Return true if this QualType doesn't point to a type yet. 1154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isNull() const { 11648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return getTypePtr() == 0; 1174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isConstQualified() const { 12048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return (getCVRQualifiers() & Const) ? true : false; 1214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVolatileQualified() const { 12348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRestrictQualified() const { 12648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 128a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes 129a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1302e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner 1312e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1322e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner /// QualType. 13348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 13448a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 13548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 13848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 13948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 14093eb82549eec82d75ce5dd3afbeeaf6fdb0e2a27Sanjiv Gupta 1414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getQualifiedType(unsigned TQs) const { 1424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return QualType(getTypePtr(), TQs); 1434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 144a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 145a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 146a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner } 1474b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 1484b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 1494b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 1504b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1523fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getUnqualifiedType() const; 1533fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 1543fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 1553fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getNonReferenceType() const; 1564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1576573cfd6fc32eab0b696cfc318bb21f4e3933f35Douglas Gregor 1584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// operator==/!= - Indicate whether the specified types and qualifiers are 1594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// identical. 1604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool operator==(const QualType &RHS) const { 16148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return Value == RHS.Value; 1624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool operator!=(const QualType &RHS) const { 16448a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return Value != RHS.Value; 1654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner std::string getAsString() const { 1674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner std::string S; 1684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner getAsStringInternal(S); 1694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return S; 1704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void getAsStringInternal(std::string &Str) const; 1724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 173a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump(const char *s) const; 174a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 1759d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek 1769d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 1779d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 1789d464449c2a782e0a91ea85d79ad9e35418ec441Ted Kremenek } 1794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 180b06cf30badcddfea862bc9a538447453bdd94598Chris Lattnerpublic: 1814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1822a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// getAddressSpace - Return the address space of this type. 1832a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb inline unsigned getAddressSpace() const; 1842a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 185034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Emit - Serialize a QualType to Bitcode. 18678f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek void Emit(llvm::Serializer& S) const; 18778f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 188034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Read - Deserialize a QualType from Bitcode. 189034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static QualType ReadVal(llvm::Deserializer& D); 19064be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek 19164be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek void ReadBackpatch(llvm::Deserializer& D); 1924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 1934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end clang. 1954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace llvm { 1974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 1984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// to a specific Type class. 1994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type<const ::clang::QualType> { 2004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef ::clang::Type* SimpleType; 2014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return Val.getTypePtr(); 2034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 2044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 2054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type< ::clang::QualType> 2064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner : public simplify_type<const ::clang::QualType> {}; 20778f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 20878f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek} // end namespace llvm 2094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 2114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Type - This is the base class of the type hierarchy. A central concept 2134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// with types is that each type always has a canonical type. A canonical type 2144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is the type with any typedef names stripped out of it or the types it 2154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// references. For example, consider: 2164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef int foo; 2184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef foo* bar; 2194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int *' 'foo *' 'bar' 2204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// There will be a Type object created for 'int'. Since int is canonical, its 2224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 2234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// TypeNameType). Its CanonicalType pointer points to the 'int' Type. Next 2244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// there is a PointerType that represents 'int*', which, like 'int', is 2254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 2264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type 2274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is also 'int*'. 2284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Non-canonical types are useful for emitting diagnostics, without losing 2304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// information about typedefs being used. Canonical types are useful for type 2314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// about whether something has a particular form (e.g. is a function type), 2334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// because they implicitly, recursively, strip all typedefs out of a type. 2344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Types, once created, are immutable. 2364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass Type { 2384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 2394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TypeClass { 24083c13010359c33354c581acee65d0c986a75247eSteve Naroff Builtin, Complex, Pointer, Reference, 2411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ConstantArray, VariableArray, IncompleteArray, DependentSizedArray, 242af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman Vector, ExtVector, 2434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner FunctionNoProto, FunctionProto, 2442a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb TypeName, Tagged, ASQual, 245dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor TemplateTypeParm, 24642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterface, ObjCQualifiedInterface, 24742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCQualifiedId, 2487aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff TypeOfExp, TypeOfTyp, // GNU typeof extension. 2497aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointer // C extension 2504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 2514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 2524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType CanonicalType; 2534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 2551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool Dependent : 1; 2561b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 2574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Note that this should stay at the end of the ivars for Type so that 2594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// subclasses can pack their bitfields into the same word. 2602a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb unsigned TC : 5; 2611b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 2624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 2637c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 2647c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser Type *this_() { return this; } 2651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 26635fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 2671b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Dependent(dependent), TC(tc) {} 2681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual ~Type() {} 269db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 2704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; 27178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 27278f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek void EmitTypeInternal(llvm::Serializer& S) const; 27378f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek void ReadTypeInternal(llvm::Deserializer& D); 27478f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 2754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 27692803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 2774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 2794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 2814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// object types, function types, and incomplete types. 2824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isObjectType - types that fully describe objects. An object is a region 2844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// of memory that can be examined and stored into (H&S). 2854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isObjectType() const; 2864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isIncompleteType - Return true if this is an incomplete type. 2884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// A type that can describe objects, but which lacks information needed to 2894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// determine its size (e.g. void, or a fwd declared struct). Clients of this 2904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// routine will need to determine if the size is actually required. 2914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIncompleteType() const; 2929db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner 2939db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 2949db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// type, in other words, not a function type. 2959db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner bool isIncompleteOrObjectType() const { 2969db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner return !isFunctionType(); 2979db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner } 2984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2995eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 3005eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// types that have a non-constant expression. This does not include "[]". 3015eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff bool isVariablyModifiedType() const; 3025eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff 3034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Helper methods to distinguish type categories. All type predicates 3042a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 3058888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff 3068888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 3078888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 3098d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isEnumeralType() const; 3108d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isBooleanType() const; 3118d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isCharType() const; 3121815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor bool isWideCharType() const; 313c81f316d260b8b8b9da21a0f9a22baa334e063fbFariborz Jahanian bool isIntegralType() const; 3144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 3154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Floating point categories. 3164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 3174300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 3184300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isComplexType() const; // C99 6.2.5p11 (complex) 3203277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 324e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isVoidType() const; // C99 6.2.5p19 325e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isDerivedType() const; // C99 6.2.5p20 326e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 327e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isAggregateType() const; // C99 6.2.5p21 (arrays, structures) 3284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 329e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Predicates: Check to see if this type is structurally the specified 3302a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb // type, ignoring typedefs and qualifiers. 331e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isFunctionType() const; 332cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isPointerLikeType() const; // Pointer or Reference. 3337931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner bool isPointerType() const; 3347aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff bool isBlockPointerType() const; 335f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner bool isReferenceType() const; 336cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isFunctionPointerType() const; 337e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isArrayType() const; 338a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isConstantArrayType() const; 339a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isIncompleteArrayType() const; 340a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isVariableArrayType() const; 3411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentSizedArrayType() const; 342e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isRecordType() const; 3432e78db3510b136b3f961af202e6a1a3df4839172Chris Lattner bool isClassType() const; 344e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isStructureType() const; 34536e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff bool isUnionType() const; 346b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 347b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isVectorType() const; // GCC vector type. 348af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman bool isExtVectorType() const; // Extended vector type. 349b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 350b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 351b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedIdType() const; // id<foo> 352dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 3531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 3541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 3551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// that its definition somehow depends on a template parameter 3561b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// (C++ [temp.dep.type]). 3571b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentType() const { return Dependent; } 35845014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor bool isOverloadType() const; // C++ overloaded function 359dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 360e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Checking Functions: Check to see if this type is structurally the 36135fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 36235fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // the best type we can. 363c33c060e2f4e7c7e89e3b809f52cfc6d55ea9838Steve Naroff const BuiltinType *getAsBuiltinType() const; 364e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const FunctionType *getAsFunctionType() const; 365d5a56aae166344e13f1f8c845530beee0868db49Chris Lattner const FunctionTypeProto *getAsFunctionTypeProto() const; 366cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner const PointerLikeType *getAsPointerLikeType() const; // Pointer or Reference. 3677931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner const PointerType *getAsPointerType() const; 3687aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 369f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner const ReferenceType *getAsReferenceType() const; 370e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsRecordType() const; 3715c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const RecordType *getAsStructureType() const; 3721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 3735c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const TypedefType *getAsTypedefType() const; 374e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsUnionType() const; 3750832dbca0e11ee020bbed181c515b3835158436eEli Friedman const EnumType *getAsEnumType() const; 376e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 3777a85fa1ba94c9f4cf960463dd3eb444ef6f89446Chris Lattner const ComplexType *getAsComplexType() const; 37836e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 379af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 380b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 381b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 382b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 383dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 384dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 385f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 386f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// interface, return the interface type, otherwise return null. 387f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 388f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner 389a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 390a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// element type of the array, potentially with type qualifiers missing. 391a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// This method should never be used when type qualifiers are meaningful. 392a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 393a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 394a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 3954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 3962afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 3975c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 3982afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 3992afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4002ea769b494649b5ca4864acf154f2fedc7718029Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 4012afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// concrete. 402a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner QualType getDesugaredType() const; 4032afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner 4044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// More type predicates useful for type checking/promotion 4054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isSignedIntegerType - Return true if this is an integer type that is 408bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 409bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 410bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// integer element type. 4114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isSignedIntegerType() const; 4124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isUnsignedIntegerType - Return true if this is an integer type that is 414bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 415bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 416bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// element type. 4174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isUnsignedIntegerType() const; 418bbe686be29157b575e53fbed328613117b525f26Chris Lattner 4194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isConstantSizeType - Return true if this is not a variable sized type, 4200448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4210448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// incomplete types. 42262f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman bool isConstantSizeType() const; 423a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 4244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getCanonicalTypeInternal() const { return CanonicalType; } 425a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 4264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const = 0; 4274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *) { return true; } 428034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 429034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 430034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Emit - Emit a Type to bitcode. Used by ASTContext. 431034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek void Emit(llvm::Serializer& S) const; 432034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 433034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Create - Construct a Type from bitcode. Used by ASTContext. 434034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S); 435034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 436034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// EmitImpl - Subclasses must implement this method in order to 437034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// be serialized. 4389c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar // FIXME: Make this abstract once implemented. 4399c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const { 4409c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar assert (false && "Serializization for type not supported."); 4419c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar } 4424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 4434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4442a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26 4452a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// This supports address space qualified types. 4462a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// 4472a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambclass ASQualType : public Type, public llvm::FoldingSetNode { 44835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 44935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 45035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner /// can't have any here. 45135fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner Type *BaseType; 4522a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 4532a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb unsigned AddressSpace; 45435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) : 4551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(ASQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 4561b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor AddressSpace(AddrSpace) { 4572a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb } 4582a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb friend class ASTContext; // ASTContext creates these. 4592a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambpublic: 46035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner Type *getBaseType() const { return BaseType; } 4612a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb unsigned getAddressSpace() const { return AddressSpace; } 4622a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 4632a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb virtual void getAsStringInternal(std::string &InnerString) const; 4642a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 4652a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 4662a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb Profile(ID, getBaseType(), AddressSpace); 4672a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb } 46835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 4692a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb unsigned AddrSpace) { 47035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner ID.AddPointer(Base); 4712a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb ID.AddInteger(AddrSpace); 4722a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb } 4732a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 4742a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb static bool classof(const Type *T) { return T->getTypeClass() == ASQual; } 4752a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb static bool classof(const ASQualType *) { return true; } 4762a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 4772a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambprotected: 4782a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb virtual void EmitImpl(llvm::Serializer& S) const; 4792a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 4802a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb friend class Type; 4812a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb}; 4822a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 4832a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 4844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'. Builtin 4854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field. 4864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type { 4874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 4884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum Kind { 4894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Void, 4904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Bool, // This is bool and/or _Bool. 4924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_U, // This is 'char' for targets where char is unsigned. 4934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UChar, // This is explicitly qualified unsigned char. 4944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UShort, 4954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UInt, 4964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULong, 4974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULongLong, 4984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_S, // This is 'char' for targets where char is signed. 5004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner SChar, // This is explicitly qualified signed char. 50185bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis WChar, // This is 'wchar_t' for C++. 5024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Short, 5034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Int, 5044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Long, 5054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner LongLong, 5064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 507d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor Float, Double, LongDouble, 508d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor 5091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Overload, // This represents the type of an overloaded function declaration. 5101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Dependent // This represents the type of a type-dependent expression. 5114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 5124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 5134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind TypeKind; 5144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 5151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor BuiltinType(Kind K) 5161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 5171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeKind(K) {} 5184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind getKind() const { return TypeKind; } 5204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner const char *getName() const; 5214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 5234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 5254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const BuiltinType *) { return true; } 5264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 5274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 5294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions. 5304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 5314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode { 5324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 5334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ComplexType(QualType Element, QualType CanonicalPtr) : 5341b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 5351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(Element) { 5364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 5384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 5394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 5404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 542034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 5434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 5444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType()); 5454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 5474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Element.getAsOpaquePtr()); 5484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 5514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ComplexType *) { return true; } 55278f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 553034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 554034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 555034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 556034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek friend class Type; 5574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 5584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 559cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// PointerLikeType - Common base class for pointers and references. 5604fea7b688be1fd4fd3fd34ed70127c78904eaa91Steve Naroff/// FIXME: Add more documentation on this classes design point. For example, 5614fea7b688be1fd4fd3fd34ed70127c78904eaa91Steve Naroff/// should BlockPointerType inherit from it? Is the concept of a PointerLikeType 5624fea7b688be1fd4fd3fd34ed70127c78904eaa91Steve Naroff/// in the C++ standard? 563cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// 564cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerclass PointerLikeType : public Type { 565cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType PointeeType; 566cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerprotected: 567cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) : 5681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(K, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 569cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner } 570cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerpublic: 571cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner 572cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType getPointeeType() const { return PointeeType; } 573cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner 574cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner static bool classof(const Type *T) { 575cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner return T->getTypeClass() == Pointer || T->getTypeClass() == Reference; 576cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner } 577cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner static bool classof(const PointerLikeType *) { return true; } 578cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner}; 5794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// PointerType - C99 6.7.5.1 - Pointer Declarators. 5814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 582cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerclass PointerType : public PointerLikeType, public llvm::FoldingSetNode { 5834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner PointerType(QualType Pointee, QualType CanonicalPtr) : 584cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner PointerLikeType(Pointer, Pointee, CanonicalPtr) { 5854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 5874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 5884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 5904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 5924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getPointeeType()); 5934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 5954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Pointee.getAsOpaquePtr()); 5964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 5974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 5994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const PointerType *) { return true; } 600034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 601034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 602034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 603034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 604034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek friend class Type; 6054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 6064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6077aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type. 6087aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as 6097aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6104fea7b688be1fd4fd3fd34ed70127c78904eaa91Steve Naroff/// FIXME: Should BlockPointerType inherit from PointerLikeType? It could 6114fea7b688be1fd4fd3fd34ed70127c78904eaa91Steve Naroff/// simplfy some type checking code, however PointerLikeType doesn't appear 6124fea7b688be1fd4fd3fd34ed70127c78904eaa91Steve Naroff/// to be used by the type checker. 6137aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// 6147aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6157aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6167aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 6171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 6181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor PointeeType(Pointee) { 6197aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6207aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class ASTContext; // ASTContext creates these. 6217aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic: 6227aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6237aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6247aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6257aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6267aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 6277aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6287aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 6297aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff Profile(ID, getPointeeType()); 6307aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6317aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6327aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 6337aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6347aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6357aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const Type *T) { 6367aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff return T->getTypeClass() == BlockPointer; 6377aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6387aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 6397aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6407aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff protected: 6417aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff virtual void EmitImpl(llvm::Serializer& S) const; 6427aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 6437aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class Type; 6447aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}; 6457aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ReferenceType - C++ 8.3.2 - Reference Declarators. 6474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 648cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerclass ReferenceType : public PointerLikeType, public llvm::FoldingSetNode { 6494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ReferenceType(QualType Referencee, QualType CanonicalRef) : 650cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner PointerLikeType(Reference, Referencee, CanonicalRef) { 6514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 6534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 6544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 6554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 657cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner Profile(ID, getPointeeType()); 6584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 6604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Referencee.getAsOpaquePtr()); 6614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Reference; } 6644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ReferenceType *) { return true; } 6654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 6664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators. 6684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 669c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 6704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 6714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 6721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 6731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// with a star size (e.g. int X[*]). 6741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// 'static' is only allowed on function parameters. 6754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum ArraySizeModifier { 6764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Normal, Static, Star 6774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 6784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 67983c13010359c33354c581acee65d0c986a75247eSteve Naroff /// ElementType - The element type of the array. 68083c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType ElementType; 68124c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff 682dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 68324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 684dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek unsigned SizeModifier : 2; 68524c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff 68624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 68724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// 'int X[static restrict 4]'. For function parameters only. 68824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned IndexTypeQuals : 3; 68924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff 69083c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected: 6911b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // C++ [temp.dep.type]p1: 6921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // A type is dependent if it is... 6931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // - an array type constructed from any dependent type or whose 6941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // size is specified by a constant expression that is 6951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // value-dependent, 69624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 69724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 6981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 6991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 7001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 70183c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 70283c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 70383c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType getElementType() const { return ElementType; } 704dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek ArraySizeModifier getSizeModifier() const { 705dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek return ArraySizeModifier(SizeModifier); 706dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek } 70724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 70883c13010359c33354c581acee65d0c986a75247eSteve Naroff 70983c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 71083c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray || 7118ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman T->getTypeClass() == VariableArray || 7121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == IncompleteArray || 7131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == DependentSizedArray; 71483c13010359c33354c581acee65d0c986a75247eSteve Naroff } 71583c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ArrayType *) { return true; } 71683c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 71783c13010359c33354c581acee65d0c986a75247eSteve Naroff 71856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant 71956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[100]' has ConstantArrayType where the element type 72056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// is 'int' and the size is 100. 721c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType { 72283c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt Size; // Allows us to unique the type. 72383c13010359c33354c581acee65d0c986a75247eSteve Naroff 72424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ConstantArrayType(QualType et, QualType can, llvm::APInt sz, 72524c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 72624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {} 72783c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 72883c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 729a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const llvm::APInt &getSize() const { return Size; } 73083c13010359c33354c581acee65d0c986a75247eSteve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 73183c13010359c33354c581acee65d0c986a75247eSteve Naroff 73283c13010359c33354c581acee65d0c986a75247eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 73383c13010359c33354c581acee65d0c986a75247eSteve Naroff Profile(ID, getElementType(), getSize()); 73483c13010359c33354c581acee65d0c986a75247eSteve Naroff } 73583c13010359c33354c581acee65d0c986a75247eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 73683c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt ArraySize) { 73783c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 73883c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddInteger(ArraySize.getZExtValue()); 73983c13010359c33354c581acee65d0c986a75247eSteve Naroff } 74083c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 74183c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray; 74283c13010359c33354c581acee65d0c986a75247eSteve Naroff } 74383c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ConstantArrayType *) { return true; } 7444234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek 7454234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenekprotected: 7464234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 7474234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 7484234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek friend class Type; 74983c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 75083c13010359c33354c581acee65d0c986a75247eSteve Naroff 75156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 75256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 75356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified. 7548ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType { 7558ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman IncompleteArrayType(QualType et, QualType can, 7568ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ArraySizeModifier sm, unsigned tq) 7578ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 7588ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class ASTContext; // ASTContext creates these. 7598ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic: 7608ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 7618ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 7628ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 7638ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const Type *T) { 7648ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman return T->getTypeClass() == IncompleteArray; 7658ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 7668ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 7678ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 7688ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class StmtIteratorBase; 7698ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 7708ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 7718ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman Profile(ID, getElementType()); 7728ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 7738ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 7748ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) { 7758ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 7768ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 7778ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 7788ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanprotected: 7798ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman virtual void EmitImpl(llvm::Serializer& S) const; 7808ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 7818ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class Type; 7828ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman}; 7838ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 78456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 78556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 78656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 78756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 78856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 78956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean 79056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type 79156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically: 79256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 79356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) { 79456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Y[x]; 79556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ++x; 79656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Z[x]; 79756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// } 79856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 799c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType { 80083c13010359c33354c581acee65d0c986a75247eSteve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 80183c13010359c33354c581acee65d0c986a75247eSteve Naroff /// a function block. 802718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek Stmt *SizeExpr; 8034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 80424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 80524c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 806718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 8074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 808db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 809db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 8104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 811a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner Expr *getSizeExpr() const { 812718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // We use C-style casts instead of cast<> here because we do not wish 813718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 814718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek return (Expr*) SizeExpr; 815718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek } 8164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 8184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 81983c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 82083c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == VariableArray; 8214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 82283c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const VariableArrayType *) { return true; } 82327a32d6f18844a97446d6e2002bf181da591332aTed Kremenek 824fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek friend class StmtIteratorBase; 8253793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek 8263793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 8278ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman assert (0 && "Cannnot unique VariableArrayTypes."); 8283793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek } 8295cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek 8305cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenekprotected: 8315cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 8325cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 8335cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek friend class Type; 8344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 8354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8361b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in 8371b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example: 8381b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @code 8391b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// template<typename T, int Size> 8401b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array { 8411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// T data[Size]; 8421b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// }; 8431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @endcode 8441b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is 8451b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will 8461b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 8471b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType { 8481b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 8491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// size of the array. 8501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Stmt *SizeExpr; 8511b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8521b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 8531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ArraySizeModifier sm, unsigned tq) 8541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 8551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class ASTContext; // ASTContext creates these. 8561b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void Destroy(ASTContext& C); 8571b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic: 8591b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Expr *getSizeExpr() const { 8601b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // We use C-style casts instead of cast<> here because we do not wish 8611b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 8621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return (Expr*) SizeExpr; 8631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 8641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 8661b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8671b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const Type *T) { 8681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return T->getTypeClass() == DependentSizedArray; 8691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 8701b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 8711b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class StmtIteratorBase; 8731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 8751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor assert (0 && "Cannnot unique DependentSizedArrayTypes."); 8761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 8771b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8781b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorprotected: 8791b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 8801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 8811b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class Type; 8821b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}; 8831b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 8844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using 8854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// __attribute__((vector_size(n)), where "n" specifies the vector size in 8864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// bytes. Since the constructor takes the number of vector elements, the 8874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements. 8884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode { 8894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 8904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ElementType - The element type of the vector. 8914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 8924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumElements - The number of elements in the vector. 8944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements; 8954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner VectorType(QualType vecType, unsigned nElements, QualType canonType) : 8971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(Vector, canonType, vecType->isDependentType()), 8981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(vecType), NumElements(nElements) {} 8994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner VectorType(TypeClass tc, QualType vecType, unsigned nElements, 9001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor QualType canonType) 9011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 9021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor NumElements(nElements) {} 9034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 9044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 9054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 9074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumElements() const { return NumElements; } 9084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 9104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 9124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType(), getNumElements(), getTypeClass()); 9134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 9144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 9154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements, TypeClass TypeClass) { 9164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ElementType.getAsOpaquePtr()); 9174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(NumElements); 9184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(TypeClass); 9194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 9204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 921af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 9224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 9234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const VectorType *) { return true; } 9244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 9254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 926af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using 927af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 928af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 9296154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing 9306154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 931af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType { 932af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 933af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 9344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 9354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 9369096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getPointAccessorIdx(char c) { 9379096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 9389096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 9399096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'x': return 0; 9409096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'y': return 1; 9419096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'z': return 2; 9429096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'w': return 3; 9439096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 9441b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 9459096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getColorAccessorIdx(char c) { 9469096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 9479096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 9489096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'r': return 0; 9499096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'g': return 1; 9509096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'b': return 2; 9519096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'a': return 3; 9529096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 9531b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 9549096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getTextureAccessorIdx(char c) { 9559096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 9569096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 9579096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 's': return 0; 9589096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 't': return 1; 9599096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'p': return 2; 9609096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'q': return 3; 9611b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 9629096b795541c783297fb19684a58c54d0fe823b8Chris Lattner }; 96342158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner 96442158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner static int getAccessorIdx(char c) { 96542158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 96642158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getColorAccessorIdx(c)+1) return idx-1; 96742158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner return getTextureAccessorIdx(c); 96842158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner } 96942158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner 9709096b795541c783297fb19684a58c54d0fe823b8Chris Lattner bool isAccessorWithinNumElements(char c) const { 97142158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getAccessorIdx(c)+1) 9729096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return unsigned(idx-1) < NumElements; 9739096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return false; 9741b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 975c11705f9b742b542724dd56796bf90e07191e342Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 976c11705f9b742b542724dd56796bf90e07191e342Steve Naroff 977806b319509d01bffe47317f11140c930da800dbbSteve Naroff static bool classof(const Type *T) { 978af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman return T->getTypeClass() == ExtVector; 9794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 980af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman static bool classof(const ExtVectorType *) { return true; } 9814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 9824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 9844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// class of FunctionTypeNoProto and FunctionTypeProto. 9854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 9864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type { 9874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// SubClassData - This field is owned by the subclass, put here to pack 9884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// tightly with the ivars in Type. 9894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool SubClassData : 1; 9904b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 9914b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// TypeQuals - Used only by FunctionTypeProto, put here to pack with the 9924b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// other bitfields. 9934b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// The qualifiers are part of FunctionTypeProto because... 9944b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 9954b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 9964b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// cv-qualifier-seq, [...], are part of the function type. 9974b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 9984b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned TypeQuals : 3; 9994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // The type returned by the function. 10014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ResultType; 10024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 10034b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 10041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 10051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, Canonical, Dependent), 10064b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 10074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool getSubClassData() const { return SubClassData; } 10084b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return TypeQuals; } 10094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getResultType() const { return ResultType; } 10124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 10154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto || 10164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner T->getTypeClass() == FunctionProto; 10174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionType *) { return true; } 10194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has 10224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments. 10234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode { 10244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner FunctionTypeNoProto(QualType Result, QualType Canonical) 10251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 10261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /*Dependent=*/false) {} 10274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 10284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // No additional state past what FunctionType provides. 10304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 10324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 10344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getResultType()); 10354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 10374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ResultType.getAsOpaquePtr()); 10384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 10414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto; 10424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionTypeNoProto *) { return true; } 104487f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek 104587f0429f888ee5d332304641611b88f7b54b5065Ted Kremenekprotected: 104687f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 104787f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 104887f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek friend class Type; 10494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionTypeProto - Represents a prototype with argument type info, e.g. 10524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 10534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// arguments, not as having a single void argument. 10544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode { 10551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 10561b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// types within the arguments passed in. 10571b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 10581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 10591b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor if (ArgArray[Idx]->isDependentType()) 10601b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return true; 10611b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return false; 10631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 10641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 106536104c1a2a18f1f78eba031e3a7a76d40416c4a7Eli Friedman FunctionTypeProto(QualType Result, const QualType *ArgArray, unsigned numArgs, 10664b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis bool isVariadic, unsigned typeQuals, QualType Canonical) 10671b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 10681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor (Result->isDependentType() || 10691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor hasAnyDependentType(ArgArray, numArgs))), 10704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner NumArgs(numArgs) { 10714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // Fill in the trailing argument array. 10724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 10734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner for (unsigned i = 0; i != numArgs; ++i) 10744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ArgInfo[i] = ArgArray[i]; 10754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumArgs - The number of arguments this function has, not counting '...'. 10784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumArgs; 10794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 10814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// holds the argument types. 1082db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 10834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1084db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 1085db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 10864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumArgs() const { return NumArgs; } 10884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getArgType(unsigned i) const { 10894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(i < NumArgs && "Invalid argument number!"); 10904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return arg_type_begin()[i]; 10914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVariadic() const { return getSubClassData(); } 10944b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 10954b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef const QualType *arg_type_iterator; 10974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_begin() const { 10984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return reinterpret_cast<const QualType *>(this+1); 10994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 11014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 11034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 11054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionProto; 11064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionTypeProto *) { return true; } 11084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID); 11104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 11114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 11124b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis bool isVariadic, unsigned TypeQuals); 1113034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 1114034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 1115034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1116034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 1117034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek friend class Type; 11184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type { 11224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *Decl; 1123e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected: 1124e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 11251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 11264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(!isa<TypedefType>(can) && "Invalid canonical type"); 11274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *getDecl() const { return Decl; } 11324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 11344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// potentially looking through *all* consequtive typedefs. This returns the 11354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// sum of the type qualifiers, so if you have: 11364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef const int A; 11374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef volatile A B; 11384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// looking through the typedefs for B will give you "const volatile A". 11394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType LookThroughTypedefs() const; 11404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 11424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == TypeName; } 11444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TypedefType *) { return true; } 11452f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek 11462f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenekprotected: 11472f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 11482f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 11492f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek friend class Type; 11504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11527cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfExpr (GCC extension). 11537cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfExpr : public Type { 11547cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *TOExpr; 11551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeOfExpr(Expr *E, QualType can); 11567cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 11577cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 11587cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 11597cbb14653934a298c09002b87704dc6531261771Steve Naroff 11607cbb14653934a298c09002b87704dc6531261771Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 11617cbb14653934a298c09002b87704dc6531261771Steve Naroff 11627cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; } 11637cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfExpr *) { return true; } 116471af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu 116571af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xuprotected: 116671af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu virtual void EmitImpl(llvm::Serializer& S) const; 116771af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 116871af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu friend class Type; 11697cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 11707cbb14653934a298c09002b87704dc6531261771Steve Naroff 11717cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension). 11727cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type { 11737cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType TOType; 11741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeOfType(QualType T, QualType can) 11751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(TypeOfTyp, can, T->isDependentType()), TOType(T) { 11767cbb14653934a298c09002b87704dc6531261771Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 11777cbb14653934a298c09002b87704dc6531261771Steve Naroff } 11787cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 11797cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 11807cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType getUnderlyingType() const { return TOType; } 11817cbb14653934a298c09002b87704dc6531261771Steve Naroff 11827cbb14653934a298c09002b87704dc6531261771Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 11837cbb14653934a298c09002b87704dc6531261771Steve Naroff 11847cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; } 11857cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfType *) { return true; } 11867cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 11874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type { 1189581571c848395ba6c7401b5384f91ead457c9adcTed Kremenek TagDecl *decl; 119046a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek friend class ASTContext; 11911d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 11921d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected: 11931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // FIXME: We'll need the user to pass in information about whether 11941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // this type is dependent or not, because we don't have enough 11951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // information to compute it here. 11961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TagType(TagDecl *D, QualType can) 11971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(Tagged, can, /*Dependent=*/false), decl(D) {} 11981d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 11991d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorpublic: 1200581571c848395ba6c7401b5384f91ead457c9adcTed Kremenek TagDecl *getDecl() const { return decl; } 12014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 12034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Tagged; } 12054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TagType *) { return true; } 12068db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek 12078db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenekprotected: 12088db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 120964be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 12108db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek friend class Type; 12114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 12124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12131baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 12141baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes. 12151baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType { 1216ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected: 12173cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit RecordType(RecordDecl *D) 12183cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { } 12191d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 12201baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 12211baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 12221baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner RecordDecl *getDecl() const { 12231baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 12241baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 12251baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 12261baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 12271baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // recursively check all fields for const-ness. If any field is declared 12281baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // const, it needs to return false. 12291baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner bool hasConstFields() const { return false; } 12301baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 12311baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 12321baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // the same address space, and return that. 12331baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner unsigned getAddressSpace() const { return 0; } 12341baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1235eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 1236eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 1237eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 1238eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 12391baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const RecordType *) { return true; } 12401baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 12411baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1242ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis/// CXXRecordType - This is a helper class that allows the use of 1243ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis/// isa/cast/dyncast to detect TagType objects of C++ structs/unions/classes. 1244ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisclass CXXRecordType : public RecordType { 1245ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis explicit CXXRecordType(CXXRecordDecl *D) 1246ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis : RecordType(reinterpret_cast<RecordDecl*>(D)) { } 1247ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis friend class ASTContext; // ASTContext creates these. 1248ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidispublic: 1249ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis 1250ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis CXXRecordDecl *getDecl() const { 1251ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis return reinterpret_cast<CXXRecordDecl*>(RecordType::getDecl()); 1252ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis } 1253ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis 1254ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis static bool classof(const TagType *T); 1255ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis static bool classof(const Type *T) { 1256ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis return isa<TagType>(T) && classof(cast<TagType>(T)); 1257ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis } 1258ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis static bool classof(const CXXRecordType *) { return true; } 1259ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis}; 1260ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis 12611baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 12621baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums. 12631baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType { 12643cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit EnumType(EnumDecl *D) 12653cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { } 12661d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 12671baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 12681baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 12691baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner EnumDecl *getDecl() const { 12701baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 12711baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 12721baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1273eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 1274eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 1275eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 1276eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 12771baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const EnumType *) { return true; } 12781baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 12791baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1280dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorclass TemplateTypeParmType : public Type { 1281dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor TemplateTypeParmDecl *Decl; 1282dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1283dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorprotected: 1284dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor TemplateTypeParmType(TemplateTypeParmDecl *D) 12851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), Decl(D) { } 1286dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1287dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor friend class ASTContext; // ASTContext creates these 1288dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1289dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorpublic: 1290dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor TemplateTypeParmDecl *getDecl() const { return Decl; } 1291dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1292dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 12931baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1294dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const Type *T) { 1295dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor return T->getTypeClass() == TemplateTypeParm; 1296dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor } 1297dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 1298dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1299dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorprotected: 1300dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 1301dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1302dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor friend class Type; 1303dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}; 13041baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1305f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1306f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// object oriented design. They basically correspond to C++ classes. There 1307f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1308f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// qualified interfaces, which are qualified with a protocol list like 1309f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1310f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 131142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCInterfaceType : public Type { 131242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *Decl; 13130c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanianprotected: 131442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 13151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 131681f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff friend class ASTContext; // ASTContext creates these. 131781f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 131881f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 131942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 132081f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 1321f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1322f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// list of protocols qualifying this interface. If this is an instance of 1323f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1324f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// empty list if there are no qualifying protocols. 1325f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1326f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner inline qual_iterator qual_begin() const; 1327f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner inline qual_iterator qual_end() const; 1328f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1329f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1330f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1331f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// interface type, or 0 if there are none. 1332f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner inline unsigned getNumProtocols() const; 1333f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1334d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner /// getProtocol - Return the specified qualifying protocol. 1335d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner inline ObjCProtocolDecl *getProtocol(unsigned i) const; 133691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian 1337f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1338f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 133981f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff static bool classof(const Type *T) { 1340b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner return T->getTypeClass() == ObjCInterface || 1341b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner T->getTypeClass() == ObjCQualifiedInterface; 134281f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff } 134342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 134481f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff}; 134581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 134642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1347e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1348e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// 1349c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1350c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// alphabetical order. 135142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 13520c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian public llvm::FoldingSetNode { 13530c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian 1354c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian // List of protocols for this protocol conforming object type 1355c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1356f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1357c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian 135842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1359b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 136042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 1361d855a6ead44e3a875179400c472ac0b37df35f70Chris Lattner Protocols(Protos, Protos+NumP) { } 136291193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1363c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanianpublic: 1364c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian 1365d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner ObjCProtocolDecl *getProtocol(unsigned i) const { 136691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian return Protocols[i]; 136791193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian } 136891193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian unsigned getNumProtocols() const { 136991193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian return Protocols.size(); 137091193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian } 1371b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner 1372b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1373b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1374b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner 137591193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 137691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian 137791193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 137891193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 1379fd5690fe6b5ea1c553dfe20f99d3fef269a50bd1Chris Lattner const ObjCInterfaceDecl *Decl, 138042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 138191193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian 1382c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian static bool classof(const Type *T) { 138342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1384c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian } 138542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1386c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian}; 1387f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1388f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1389f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1390f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1391f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return QIT->qual_begin(); 1392f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return 0; 1393f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1394f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1395f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1396f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1397f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return QIT->qual_end(); 1398f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return 0; 1399f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1400f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1401f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1402f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// interface type, or 0 if there are none. 1403f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1404f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1405f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1406f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return QIT->getNumProtocols(); 1407f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return 0; 1408f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1409f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1410d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner/// getProtocol - Return the specified qualifying protocol. 1411d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattnerinline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1412d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1413f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1414f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1415f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1416e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1417e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// ObjCQualifiedIdType - to represent id<protocol-list>. 1418e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// 1419e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// Duplicate protocols are removed and protocol list is canonicalized to be in 1420e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// alphabetical order. 142142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedIdType : public Type, 1422e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian public llvm::FoldingSetNode { 1423e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian // List of protocols for this protocol conforming 'id' type 1424e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 142542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1426e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 14274a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 14281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 14291b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /*Dependent=*/false), 1430e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian Protocols(Protos, Protos+NumP) { } 1431e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian friend class ASTContext; // ASTContext creates these. 1432e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianpublic: 1433e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 143442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 1435e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian return Protocols[i]; 1436e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian } 1437e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian unsigned getNumProtocols() const { 1438e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian return Protocols.size(); 1439e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian } 144042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1441957442db1d23f62ee2d0d71310bee240606b267dFariborz Jahanian return &Protocols[0]; 1442b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner } 1443b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner 1444b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1445b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1446b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1447e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1448e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 1449e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1450e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 14514a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, 145242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 1453e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1454e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian static bool classof(const Type *T) { 145542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek return T->getTypeClass() == ObjCQualifiedId; 1456e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian } 145742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCQualifiedIdType *) { return true; } 1458e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1459e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian}; 1460c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian 14614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1462b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions. 14634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 14642a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 14652a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline QualType QualType::getUnqualifiedType() const { 146635fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner Type *TP = getTypePtr(); 146735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP)) 146835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner TP = ASQT->getBaseType(); 146935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner return QualType(TP, 0); 14702a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 14712a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 14722a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type. 14732a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const { 147401ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 147501ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1476a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return AT->getElementType().getAddressSpace(); 147701ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1478efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman return RT->getAddressSpace(); 147901ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ASQualType *ASQT = dyn_cast<ASQualType>(CT)) 14802a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return ASQT->getAddressSpace(); 14812a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return 0; 14822a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 1483b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner 14843fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 14853fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 14863fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and 14873fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile 14883fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int". 14893fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 14903fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor // FIXME: Handle address spaces 14913fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 14923fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 14934459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(this->getAddressSpace() == 0 && "Address space not checked"); 14944459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(Other.getAddressSpace() == 0 && "Address space not checked"); 14953fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 14963fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 14973fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 14983fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 14993fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile 15003fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 15013fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int". 15023fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 15033fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor // FIXME: Handle address spaces 15043fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 15053fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 15064459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(this->getAddressSpace() == 0 && "Address space not checked"); 15074459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(Other.getAddressSpace() == 0 && "Address space not checked"); 15083fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 15093fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 15103fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 15113fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 15123fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const 15133fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 15143fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6: 15153fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 15163fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 15173fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 15183fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// analysis, the expression designates the object or function 15193fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 15203fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const { 15213fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 15223fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return RefType->getPointeeType(); 15233fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor else 15243fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return *this; 15253fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 15263fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 15275c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenekinline const TypedefType* Type::getAsTypedefType() const { 15285c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek return dyn_cast<TypedefType>(this); 15295c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek} 1530f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1531f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner if (const PointerType *PT = getAsPointerType()) 1532f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 1533f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner return 0; 1534f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner} 1535f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner 1536a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1537a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// space qualifiers if present. 1538b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const { 15392a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1540b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 1541b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const { 15422a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1543b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 15447aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const { 15457aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff return isa<BlockPointerType>(CanonicalType); 15467aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff} 1547cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const { 1548cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1549cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 1550cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isPointerLikeType() const { 1551cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner return isa<PointerLikeType>(CanonicalType.getUnqualifiedType()); 1552cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 155383b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const { 155474a340749eb63af1ba7098c67f3ef72bd48f5ae8Ted Kremenek if (const PointerType* T = getAsPointerType()) 155583b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return T->getPointeeType()->isFunctionType(); 155683b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek else 155783b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return false; 155883b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek} 1559b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const { 15602a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1561b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 1562a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const { 1563a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1564a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 1565a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const { 1566a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1567a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 1568a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const { 1569a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1570a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 15711b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const { 15721b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 15731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor} 1574b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const { 15752a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1576b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 15773277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const { 1578a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 15793277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner} 1580b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const { 15812a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1582b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 1583af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const { 1584af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1585b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 158642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCInterfaceType() const { 1587a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1588b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 1589b06cf30badcddfea862bc9a538447453bdd94598Chris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 1590a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1591550e05034c6c8efcb7ab4c65f58048eee0892237Fariborz Jahanian} 159242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 1593a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1594dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian} 1595dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const { 1596dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 1597dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor} 1598dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 159945014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregorinline bool Type::isOverloadType() const { 160045014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 160145014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor return BT->getKind() == BuiltinType::Overload; 160245014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor else 160345014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor return false; 160445014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor} 160545014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor 1606da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 1607da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<. 1608da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1609da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner QualType T) { 1610da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 1611da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner Diagnostic::ak_qualtype); 1612da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner return DB; 1613da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner} 1614da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner 16154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end namespace clang 16164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 16174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif 1618