Type.h revision 1e589cc31d339860b9df61870930961601d68120
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" 18734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#include "llvm/Support/Casting.h" 2083c13010359c33354c581acee65d0c986a75247eSteve Naroff#include "llvm/ADT/APSInt.h" 2148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/FoldingSet.h" 2248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner#include "llvm/ADT/PointerIntPair.h" 2378f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek#include "llvm/Bitcode/SerializationFwd.h" 244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::isa; 254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast; 264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::cast_or_null; 274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast; 284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerusing llvm::dyn_cast_or_null; 294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class ASTContext; 324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class Type; 334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TypedefDecl; 348e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor class TemplateDecl; 35dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor class TemplateTypeParmDecl; 36279272e63b321f89c8fa0bb198acd3a834459aebDouglas Gregor class NonTypeTemplateParmDecl; 37279272e63b321f89c8fa0bb198acd3a834459aebDouglas Gregor class TemplateTemplateParamDecl; 384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class TagDecl; 394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class RecordDecl; 40ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidis class CXXRecordDecl; 414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class EnumDecl; 4264be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek class FieldDecl; 4342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCInterfaceDecl; 4442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCProtocolDecl; 4542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek class ObjCMethodDecl; 464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class Expr; 47718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek class Stmt; 484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner class SourceLocation; 49fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek class StmtIteratorBase; 50f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor class TemplateArgument; 51734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor class QualifiedNameType; 524fa58905062efa6a12137b1983a1367220182a20Douglas Gregor 534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor // Provide forward declarations for all of the *Type classes 544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) class Class##Type; 554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 567555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// their own: instead each reference to a type stores the qualifiers. This 594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// greatly reduces the number of nodes we need to allocate for types (for 604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// example we only need one for 'int', 'const int', 'volatile int', 614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'const volatile int', etc). 624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// As an added efficiency bonus, instead of making this a pair, we just store 644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// the three bits we care about in the low bits of the pointer. To handle the 654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// packing/unpacking, we make QualType be a simple wrapper class that acts like 664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// a smart pointer. 674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass QualType { 6848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner llvm::PointerIntPair<Type*, 3> Value; 694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Const = 0x1, 724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Restrict = 0x2, 734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Volatile = 0x4, 744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner CVRFlags = Const|Restrict|Volatile 754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 77af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian enum GCAttrTypes { 78af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian GCNone = 0, 79af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian Weak, 80af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian Strong 81af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian }; 82af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian 8348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType() {} 844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner QualType(const Type *Ptr, unsigned Quals) 8648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 89b9b218e566459808be9f1c52b03afad3e0d39ed3Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 9048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner Type *getTypePtr() const { return Value.getPointer(); } 9148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner 9248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static QualType getFromOpaquePtr(void *Ptr) { 944b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType T; 9548a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner T.Value.setFromOpaqueValue(Ptr); 964b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T; 974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type &operator*() const { 1004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return *getTypePtr(); 1014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Type *operator->() const { 1044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return getTypePtr(); 1054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isNull - Return true if this QualType doesn't point to a type yet. 1084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isNull() const { 10948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return getTypePtr() == 0; 1104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isConstQualified() const { 11348a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return (getCVRQualifiers() & Const) ? true : false; 1144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVolatileQualified() const { 11648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRestrictQualified() const { 11948a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 121a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes 122a7bbf567dac9dfd58f12c9ff14584d64104694f3Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1232e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner 1242e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1252e3b1d2ed22e5638fa9c55cc1ea5dac4db6aecdcChris Lattner /// QualType. 12648a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 12748a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 12848a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13048a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 13148a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 13248a3432a72fd17868c0bf4d864ddb60420c63d68Chris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 13393eb82549eec82d75ce5dd3afbeeaf6fdb0e2a27Sanjiv Gupta 1344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getQualifiedType(unsigned TQs) const { 1354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return QualType(getTypePtr(), TQs); 1364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 137a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 138a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 139a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner } 1404b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 1414b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 1424b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 1434b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1453fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getUnqualifiedType() const; 1463fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 1473fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 1483fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor QualType getNonReferenceType() const; 1494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 150835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 151835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 152835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 153835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 154835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 155835327293da59eb16667ae5a2b7158131865a079Chris Lattner /// concrete. 156835327293da59eb16667ae5a2b7158131865a079Chris Lattner QualType getDesugaredType() const; 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 185af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 186af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 18785534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 18885534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 18985534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCWeak() const { 19085534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian return getObjCGCAttr() == Weak; 19185534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 19285534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian 19385534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 19485534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian bool isObjCGCStrong() const { 19585534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian return getObjCGCAttr() == Strong; 19685534581967bd50a73c25ae76c96d39b05854a05Fariborz Jahanian } 197af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian 198034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Emit - Serialize a QualType to Bitcode. 19978f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek void Emit(llvm::Serializer& S) const; 20078f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 201034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Read - Deserialize a QualType from Bitcode. 202034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static QualType ReadVal(llvm::Deserializer& D); 20364be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek 20464be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek void ReadBackpatch(llvm::Deserializer& D); 2054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 2064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end clang. 2084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace llvm { 2104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// to a specific Type class. 2124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type<const ::clang::QualType> { 2134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef ::clang::Type* SimpleType; 2144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return Val.getTypePtr(); 2164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 2174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 2184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnertemplate<> struct simplify_type< ::clang::QualType> 2194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner : public simplify_type<const ::clang::QualType> {}; 22078f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 22178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek} // end namespace llvm 2224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnernamespace clang { 2244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Type - This is the base class of the type hierarchy. A central concept 2264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// with types is that each type always has a canonical type. A canonical type 2274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is the type with any typedef names stripped out of it or the types it 2284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// references. For example, consider: 2294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef int foo; 2314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// typedef foo* bar; 2324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int *' 'foo *' 'bar' 2334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// There will be a Type object created for 'int'. Since int is canonical, its 2354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 2364fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// there is a PointerType that represents 'int*', which, like 'int', is 2384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 2394fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// is also 'int*'. 2414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Non-canonical types are useful for emitting diagnostics, without losing 2434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// information about typedefs being used. Canonical types are useful for type 2444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// about whether something has a particular form (e.g. is a function type), 2464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// because they implicitly, recursively, strip all typedefs out of a type. 2474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// Types, once created, are immutable. 2494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 2504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass Type { 2514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 2524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum TypeClass { 2534fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define TYPE(Class, Base) Class, 2544fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 2554fa58905062efa6a12137b1983a1367220182a20Douglas Gregor#include "clang/AST/TypeNodes.def" 2564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TagFirst = Record, TagLast = Enum 2574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 258af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian 2594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 2604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType CanonicalType; 2614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2621b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 2631b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool Dependent : 1; 2641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 2654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Note that this should stay at the end of the ivars for Type so that 2674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// subclasses can pack their bitfields into the same word. 2682a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb unsigned TC : 5; 2691b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 2704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 2717c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 2727c6f0c755e48a2782bc0a0a4cfc63dc84e0f11d5Hartmut Kaiser Type *this_() { return this; } 2731b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 27435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 2751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Dependent(dependent), TC(tc) {} 2761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual ~Type() {} 277db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 2784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; 27978f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 28078f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek void EmitTypeInternal(llvm::Serializer& S) const; 28178f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek void ReadTypeInternal(llvm::Deserializer& D); 28278f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 2834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 28492803daaa6a40a3899c2e599bddc42732c2ce593Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 2854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 2874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 2894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// object types, function types, and incomplete types. 2904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 29126ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// \brief Determines whether the type describes an object in memory. 29226ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// 29326ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// Note that this definition of object type corresponds to the C++ 29426ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// definition of object type, which includes incomplete types, as 29526ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// opposed to the C definition (which does not include incomplete 29626ea122d7b08fc76c2135ef2609af311d951dac3Douglas Gregor /// types). 2974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isObjectType() const; 2984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 2994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isIncompleteType - Return true if this is an incomplete type. 3004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// A type that can describe objects, but which lacks information needed to 3014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// routine will need to determine if the size is actually required. 3034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIncompleteType() const; 3049db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner 3059db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 3069db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner /// type, in other words, not a function type. 3079db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner bool isIncompleteOrObjectType() const { 3089db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner return !isFunctionType(); 3099db553e9ffdcd7c9fbd2fa6cf70646370e589159Chris Lattner } 31039c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 31139c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 31239c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl bool isPODType() const; 31339c0f6f69727c07a1b87605c54f14b86f8189194Sebastian Redl 3145eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 3155eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff /// types that have a non-constant expression. This does not include "[]". 3165eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff bool isVariablyModifiedType() const; 3175eb879b0ab7cc0b98c5700b0c19cae3797530d9cSteve Naroff 3184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Helper methods to distinguish type categories. All type predicates 3192a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 320c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 321c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 322c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 3238888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff 3248888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 3258888c7acd5cd43c7f910bfe03f5979ed4011de2aSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 3278d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isEnumeralType() const; 3288d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isBooleanType() const; 3298d3b170e5cb1700b5cbd227182bc29ca0d16819dSteve Naroff bool isCharType() const; 3301815b3bfc1382c88bee771bd158755b2426f0780Douglas Gregor bool isWideCharType() const; 331c81f316d260b8b8b9da21a0f9a22baa334e063fbFariborz Jahanian bool isIntegralType() const; 3324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 3334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// Floating point categories. 3344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 3354300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 3364300121ffff80d4b23d17689930e2aa2a83086b9Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isComplexType() const; // C99 6.2.5p11 (complex) 3383277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 342e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isVoidType() const; // C99 6.2.5p19 343e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isDerivedType() const; // C99 6.2.5p20 344e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 345e7ef500151147ba851db502fc4d36319f863db80Douglas Gregor bool isAggregateType() const; 3464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 347e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Predicates: Check to see if this type is structurally the specified 3482a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb // type, ignoring typedefs and qualifiers. 349e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isFunctionType() const; 350a6fe878ddf8804734de57b1bbd1c8a25ff963024Chris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 351a6fe878ddf8804734de57b1bbd1c8a25ff963024Chris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 3527931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner bool isPointerType() const; 3537aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff bool isBlockPointerType() const; 354f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner bool isReferenceType() const; 355ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isLValueReferenceType() const; 356ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl bool isRValueReferenceType() const; 357cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner bool isFunctionPointerType() const; 3587555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberPointerType() const; 3597555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl bool isMemberFunctionPointerType() const; 360e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isArrayType() const; 361a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isConstantArrayType() const; 362a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isIncompleteArrayType() const; 363a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner bool isVariableArrayType() const; 3641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentSizedArrayType() const; 365e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isRecordType() const; 3662e78db3510b136b3f961af202e6a1a3df4839172Chris Lattner bool isClassType() const; 367e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner bool isStructureType() const; 36836e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff bool isUnionType() const; 369b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 370b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isVectorType() const; // GCC vector type. 371af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman bool isExtVectorType() const; // Extended vector type. 372b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 373b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 374b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner bool isObjCQualifiedIdType() const; // id<foo> 375dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 3761b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 3771b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 3781b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// that its definition somehow depends on a template parameter 3791b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// (C++ [temp.dep.type]). 3801b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor bool isDependentType() const { return Dependent; } 38100fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor bool isOverloadableType() const; 382dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 383fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 384fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 385fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 386fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar /// interface types. 387fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar bool hasPointerRepresentation() const; 388fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 3897c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 3907c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 3917c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian bool hasObjCPointerRepresentation() const; 3927c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 393e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner // Type Checking Functions: Check to see if this type is structurally the 39435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 39535fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner // the best type we can. 3967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const BuiltinType *getAsBuiltinType() const; 3977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const FunctionType *getAsFunctionType() const; 3984fa58905062efa6a12137b1983a1367220182a20Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 3994fa58905062efa6a12137b1983a1367220182a20Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 4007931f4a186bc76b21dd4629ee74d64264a7fb8a2Chris Lattner const PointerType *getAsPointerType() const; 4017aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 402f0c4a0a830c9154b1ae72e497c2ce586c10e9b71Chris Lattner const ReferenceType *getAsReferenceType() const; 403ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl const LValueReferenceType *getAsLValueReferenceType() const; 404ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl const RValueReferenceType *getAsRValueReferenceType() const; 4057555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const MemberPointerType *getAsMemberPointerType() const; 4069c7825b737617339724d43bd04960852271f08e2Douglas Gregor const TagType *getAsTagType() const; 407e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsRecordType() const; 4085c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const RecordType *getAsStructureType() const; 4091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 4105c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek const TypedefType *getAsTypedefType() const; 411e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const RecordType *getAsUnionType() const; 4120832dbca0e11ee020bbed181c515b3835158436eEli Friedman const EnumType *getAsEnumType() const; 413e35a104a7d5caf8fa71117fbaa6f18cacc53c7a7Chris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 4147a85fa1ba94c9f4cf960463dd3eb444ef6f89446Chris Lattner const ComplexType *getAsComplexType() const; 41536e35e652e28cbdffbeda8cc3362888357ec7173Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 416af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 417b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 418b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 419b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 420dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 421dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 4228e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor const ClassTemplateSpecializationType * 4237e50826d3559f284eee6659f0aa159c68f504b34Douglas Gregor getAsClassTemplateSpecializationType() const; 4248e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 425f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 426f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner /// interface, return the interface type, otherwise return null. 427f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 428f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner 429a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 430a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// element type of the array, potentially with type qualifiers missing. 431a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner /// This method should never be used when type qualifiers are meaningful. 432a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 433a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 4342afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 4355c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 4362afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 4372afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4382ea769b494649b5ca4864acf154f2fedc7718029Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 4392afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner /// concrete. 440a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner QualType getDesugaredType() const; 4412afc72b0b6b3d2f44ca2576c98d307310d556983Chris Lattner 4424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// More type predicates useful for type checking/promotion 4434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isSignedIntegerType - Return true if this is an integer type that is 446bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 447bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 448bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// integer element type. 4494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isSignedIntegerType() const; 4504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 4514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isUnsignedIntegerType - Return true if this is an integer type that is 452bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 453bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 454bbe686be29157b575e53fbed328613117b525f26Chris Lattner /// element type. 4554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isUnsignedIntegerType() const; 456bbe686be29157b575e53fbed328613117b525f26Chris Lattner 4574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// isConstantSizeType - Return true if this is not a variable sized type, 4580448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4590448b4f2fecceebc0bddd67fe0f2c89afe604fdfChris Lattner /// incomplete types. 46062f67fd7f670f1a8b222c6565b257c05e8e80faeEli Friedman bool isConstantSizeType() const; 461a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner 4624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getCanonicalTypeInternal() const { return CanonicalType; } 463a55e321bd645398b514e246981c04a4889ee2472Chris Lattner void dump() const; 4644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const = 0; 4654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *) { return true; } 466034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 467034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 468034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Emit - Emit a Type to bitcode. Used by ASTContext. 469034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek void Emit(llvm::Serializer& S) const; 470034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 471034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// Create - Construct a Type from bitcode. Used by ASTContext. 472034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S); 473034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 474034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// EmitImpl - Subclasses must implement this method in order to 475034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek /// be serialized. 4769c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar // FIXME: Make this abstract once implemented. 4779c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar virtual void EmitImpl(llvm::Serializer& S) const { 478126949ecf2a1051fa3271b42936129ea0299be99Gabor Greif assert(false && "Serialization for type not supported."); 4799c7fd1e1ad0ec0c483560c9a9daeda23c3772055Daniel Dunbar } 4804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 4814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 482b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 483b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// This supports all kinds of type attributes; including, 484b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// address space qualified types, objective-c's __weak and 485b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian/// __strong attributes. 4862a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// 487b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 48835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 48935fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 49035fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner /// can't have any here. 49135fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner Type *BaseType; 492dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian 4932a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 4942a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb unsigned AddressSpace; 495dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian /// GC __weak/__strong attributes 496af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType::GCAttrTypes GCAttrType; 497dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian 498dae66edc49dc2ebbb32377e33012fc3a168c5a4eFariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 499af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType::GCAttrTypes gcAttr) : 50018b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 50118b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 50218b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner assert(!isa<ExtQualType>(BaseType) && 50318b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner "Cannot have ExtQualType of ExtQualType"); 50418b5a9a3396fa4bb6630c5bea19399b101aa3043Chris Lattner } 5052a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb friend class ASTContext; // ASTContext creates these. 5062a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambpublic: 50735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner Type *getBaseType() const { return BaseType; } 508af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5091e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 5102a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 5112a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb virtual void getAsStringInternal(std::string &InnerString) const; 5122a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 5132a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5141e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 5152a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb } 51635fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 517af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 51835fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner ID.AddPointer(Base); 5192a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb ID.AddInteger(AddrSpace); 5201e124fe3e31ab37c45b6fbe6a8075e987fc04408Fariborz Jahanian ID.AddInteger(gcAttr); 5212a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb } 5222a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 523b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 524b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian static bool classof(const ExtQualType *) { return true; } 5252a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 5262a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambprotected: 5272a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb virtual void EmitImpl(llvm::Serializer& S) const; 5282a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 5292a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb friend class Type; 5302a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb}; 5312a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 5322a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 5334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// BuiltinType - This class is used for builtin types like 'int'. Builtin 5344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types are always canonical and have a literal name field. 5354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass BuiltinType : public Type { 5364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 5374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum Kind { 5384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Void, 5394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Bool, // This is bool and/or _Bool. 5414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_U, // This is 'char' for targets where char is unsigned. 5424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UChar, // This is explicitly qualified unsigned char. 5434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UShort, 5444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner UInt, 5454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULong, 5464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ULongLong, 5474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Char_S, // This is 'char' for targets where char is signed. 5494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner SChar, // This is explicitly qualified signed char. 55085bd81edce4057156d7f49408147f07daa675096Argiris Kirtzidis WChar, // This is 'wchar_t' for C++. 5514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Short, 5524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Int, 5534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Long, 5544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner LongLong, 5554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 556d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor Float, Double, LongDouble, 557d2baafd07bc5c7679a6f1f10e5587a95842ffa15Douglas Gregor 5581b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Overload, // This represents the type of an overloaded function declaration. 5591b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Dependent // This represents the type of a type-dependent expression. 5604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 5614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 5624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind TypeKind; 5634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 5641b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor BuiltinType(Kind K) 5651b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 5661b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeKind(K) {} 5674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Kind getKind() const { return TypeKind; } 5694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner const char *getName() const; 5704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 5724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 5734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 5744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const BuiltinType *) { return true; } 5754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 5764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 577ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 578ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// want to or can't map to named integer types. These always have a lower 579ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman/// integer rank than builtin types of the same width. 580ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanclass FixedWidthIntType : public Type { 581ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanprivate: 582ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman unsigned Width; 583ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman bool Signed; 584ff3fcdf47370a4577d971a2adefd259807152078Eli Friedmanpublic: 585ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 586ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman Width(W), Signed(S) {} 587ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman 588ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman unsigned getWidth() const { return Width; } 589ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman bool isSigned() const { return Signed; } 590ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman const char *getName() const; 591ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman 592ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 593ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman 594ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 595ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman static bool classof(const FixedWidthIntType *) { return true; } 596ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman}; 597ff3fcdf47370a4577d971a2adefd259807152078Eli Friedman 5984b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 5994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// types (_Complex float etc) as well as the GCC integer complex extensions. 6004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 6014b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass ComplexType : public Type, public llvm::FoldingSetNode { 6024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 6034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ComplexType(QualType Element, QualType CanonicalPtr) : 6041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 6051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(Element) { 6064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 6084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 6094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 6104b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 612034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 6134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 6144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType()); 6154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 6174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Element.getAsOpaquePtr()); 6184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 6214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ComplexType *) { return true; } 62278f138f44886abc5ab7fc1551d501308f1846d80Ted Kremenek 623034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 624034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 625034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 626034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek friend class Type; 6274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 6284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 629554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 630cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner/// 631554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 632cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner QualType PointeeType; 6334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner PointerType(QualType Pointee, QualType CanonicalPtr) : 635554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 6364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 6384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 6394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 6414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 642554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 643554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 6444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 6454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getPointeeType()); 6464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Pointee.getAsOpaquePtr()); 6494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 6504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 6524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const PointerType *) { return true; } 653034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 654034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 655034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 656034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 657034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek friend class Type; 6584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 6594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 6607aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// BlockPointerType - pointer to a block type. 6617aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// This type is to represent types syntactically represented as 6627aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6637aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff/// 6647aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6657aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6667aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 6671b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 6681b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor PointeeType(Pointee) { 6697aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6707aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class ASTContext; // ASTContext creates these. 6717aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffpublic: 6727aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6737aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6747aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6757aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6767aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 6777aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6787aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 6797aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff Profile(ID, getPointeeType()); 6807aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6817aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6827aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 6837aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6847aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6857aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const Type *T) { 6867aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff return T->getTypeClass() == BlockPointer; 6877aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff } 6887aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 6897aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 6907aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff protected: 6917aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff virtual void EmitImpl(llvm::Serializer& S) const; 6927aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 6937aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff friend class Type; 6947aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff}; 6957aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff 696ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 6974b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 698554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 699554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType PointeeType; 700554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 701ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 702ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 703ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 704554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar PointeeType(Referencee) { 7054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 7064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 707554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 708554af94c53e3a182233fc4fb0f374a9eb3ae6bf6Daniel Dunbar 7094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 710cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner Profile(ID, getPointeeType()); 7114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 7124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 7134b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(Referencee.getAsOpaquePtr()); 7144b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 7154b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 716ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 717ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference || 718ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl T->getTypeClass() == RValueReference; 719ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 7204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const ReferenceType *) { return true; } 7217555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7227555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlprotected: 7237555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl virtual void EmitImpl(llvm::Serializer& S) const; 724ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 725ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 726ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 727ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 728ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass LValueReferenceType : public ReferenceType { 729ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 730ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 731ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 732ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 733ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 734ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl virtual void getAsStringInternal(std::string &InnerString) const; 735ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 736ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 737ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == LValueReference; 738ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 739ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 740ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 741ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 742ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 743ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class Type; 744ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl}; 745ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 746ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 747ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl/// 748ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlclass RValueReferenceType : public ReferenceType { 749ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 750ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 751ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 752ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl friend class ASTContext; // ASTContext creates these 753ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlpublic: 754ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl virtual void getAsStringInternal(std::string &InnerString) const; 755ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 756ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const Type *T) { 757ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return T->getTypeClass() == RValueReference; 758ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl } 759ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 760ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl 761ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlprotected: 7627555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 7637555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class Type; 7647555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl}; 7657555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7667555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 7677555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl/// 7687555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 7697555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType PointeeType; 7707555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 7717555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 7727555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class; 7737555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7747555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 7757555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Type(MemberPointer, CanonicalPtr, 7767555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 7777555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl PointeeType(Pointee), Class(Cls) { 7787555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 7797555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class ASTContext; // ASTContext creates these. 7807555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlpublic: 7817555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7827555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl QualType getPointeeType() const { return PointeeType; } 7837555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7847555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *getClass() const { return Class; } 7857555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7867555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl virtual void getAsStringInternal(std::string &InnerString) const; 7877555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7887555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 7897555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl Profile(ID, getPointeeType(), getClass()); 7907555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 7917555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 7927555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl const Type *Class) { 7937555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 7947555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl ID.AddPointer(Class); 7957555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 7967555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 7977555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const Type *T) { 7987555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getTypeClass() == MemberPointer; 7997555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl } 8007555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static bool classof(const MemberPointerType *) { return true; } 8017555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl 8027555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlprotected: 8037555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl virtual void EmitImpl(llvm::Serializer& S) const; 8047555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 8057555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl friend class Type; 8064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 8074b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 8084b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// ArrayType - C99 6.7.5.2 - Array Declarators. 8094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 810c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 8114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 8124b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 8131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 8141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// with a star size (e.g. int X[*]). 8151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// 'static' is only allowed on function parameters. 8164b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner enum ArraySizeModifier { 8174b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Normal, Static, Star 8184b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner }; 8194b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprivate: 82083c13010359c33354c581acee65d0c986a75247eSteve Naroff /// ElementType - The element type of the array. 82183c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType ElementType; 82224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff 823dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 82424c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 825dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek unsigned SizeModifier : 2; 82624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff 82724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 82824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff /// 'int X[static restrict 4]'. For function parameters only. 82924c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned IndexTypeQuals : 3; 83024c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff 83183c13010359c33354c581acee65d0c986a75247eSteve Naroffprotected: 8321b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // C++ [temp.dep.type]p1: 8331b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // A type is dependent if it is... 8341b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // - an array type constructed from any dependent type or whose 8351b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // size is specified by a constant expression that is 8361b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // value-dependent, 83724c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 83824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 8391b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 8401b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 8411b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 84283c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 84383c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 84483c13010359c33354c581acee65d0c986a75247eSteve Naroff QualType getElementType() const { return ElementType; } 845dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek ArraySizeModifier getSizeModifier() const { 846dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek return ArraySizeModifier(SizeModifier); 847dbd96b23eae3784172d91cfb086abb8ca732f92eTed Kremenek } 84824c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 84983c13010359c33354c581acee65d0c986a75247eSteve Naroff 85083c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 85183c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray || 8528ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman T->getTypeClass() == VariableArray || 8531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == IncompleteArray || 8541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor T->getTypeClass() == DependentSizedArray; 85583c13010359c33354c581acee65d0c986a75247eSteve Naroff } 85683c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ArrayType *) { return true; } 85783c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 85883c13010359c33354c581acee65d0c986a75247eSteve Naroff 85956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant 86056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[100]' has ConstantArrayType where the element type 86156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// is 'int' and the size is 100. 862c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass ConstantArrayType : public ArrayType { 86383c13010359c33354c581acee65d0c986a75247eSteve Naroff llvm::APInt Size; // Allows us to unique the type. 86483c13010359c33354c581acee65d0c986a75247eSteve Naroff 8653f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 86624c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 8673f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 86883c13010359c33354c581acee65d0c986a75247eSteve Naroff friend class ASTContext; // ASTContext creates these. 86983c13010359c33354c581acee65d0c986a75247eSteve Naroffpublic: 870a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner const llvm::APInt &getSize() const { return Size; } 87183c13010359c33354c581acee65d0c986a75247eSteve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 87283c13010359c33354c581acee65d0c986a75247eSteve Naroff 87383c13010359c33354c581acee65d0c986a75247eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8743f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner Profile(ID, getElementType(), getSize(), 8753f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner getSizeModifier(), getIndexTypeQualifier()); 87683c13010359c33354c581acee65d0c986a75247eSteve Naroff } 87783c13010359c33354c581acee65d0c986a75247eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8783f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 8793f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner unsigned TypeQuals) { 88083c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 88183c13010359c33354c581acee65d0c986a75247eSteve Naroff ID.AddInteger(ArraySize.getZExtValue()); 8823f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 8833f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 88483c13010359c33354c581acee65d0c986a75247eSteve Naroff } 88583c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 88683c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == ConstantArray; 88783c13010359c33354c581acee65d0c986a75247eSteve Naroff } 88883c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const ConstantArrayType *) { return true; } 8894234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek 8904234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenekprotected: 8914234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 8924234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 8934234c1b1a9c858b005f4ad7dc85908b63adcafddTed Kremenek friend class Type; 89483c13010359c33354c581acee65d0c986a75247eSteve Naroff}; 89583c13010359c33354c581acee65d0c986a75247eSteve Naroff 89656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 89756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 89856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// type is 'int' and the size is unspecified. 8998ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanclass IncompleteArrayType : public ArrayType { 9008ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman IncompleteArrayType(QualType et, QualType can, 9018ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ArraySizeModifier sm, unsigned tq) 9028ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 9038ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class ASTContext; // ASTContext creates these. 9048ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanpublic: 9058ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 9068ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 9078ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 9088ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const Type *T) { 9098ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman return T->getTypeClass() == IncompleteArray; 9108ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 9118ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 9128ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 9138ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class StmtIteratorBase; 9148ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 9158ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 9163f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 9178ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 9188ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 9193f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 9203f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 9218ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 9223f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(SizeMod); 9233f7a8f19e231b74ff3d94754b420ea4eb2107afdChris Lattner ID.AddInteger(TypeQuals); 9248ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman } 9258ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 9268ff077864feed2c2b75424d37724f60e56d5a597Eli Friedmanprotected: 9278ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman virtual void EmitImpl(llvm::Serializer& S) const; 9288ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 9298ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman friend class Type; 9308ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman}; 9318ff077864feed2c2b75424d37724f60e56d5a597Eli Friedman 93256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 93356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 93456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 93556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 93656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 93756846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// should not be: two lexically equivalent variable array types could mean 93856846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// different things, for example, these variables do not have the same type 93956846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// dynamically: 94056846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 94156846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// void foo(int x) { 94256846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Y[x]; 94356846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// ++x; 94456846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// int Z[x]; 94556846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// } 94656846f2ed2594f49d78eee3645482a5e77d5e236Chris Lattner/// 947c8253192b917a5684717c58f4032e0891d089b00Ted Kremenekclass VariableArrayType : public ArrayType { 94883c13010359c33354c581acee65d0c986a75247eSteve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 94983c13010359c33354c581acee65d0c986a75247eSteve Naroff /// a function block. 950718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek Stmt *SizeExpr; 9514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 95224c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 95324c9b98cc6a8de4a080e2dedb2797bdc2eeb688bSteve Naroff ArraySizeModifier sm, unsigned tq) 954718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 9554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 956db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek virtual void Destroy(ASTContext& C); 957db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 9584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 959a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner Expr *getSizeExpr() const { 960718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // We use C-style casts instead of cast<> here because we do not wish 961718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 962718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek return (Expr*) SizeExpr; 963718b6638e0d259d1b8371ef30e475e9c2e981ffcTed Kremenek } 9644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 9664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 96783c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const Type *T) { 96883c13010359c33354c581acee65d0c986a75247eSteve Naroff return T->getTypeClass() == VariableArray; 9694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 97083c13010359c33354c581acee65d0c986a75247eSteve Naroff static bool classof(const VariableArrayType *) { return true; } 97127a32d6f18844a97446d6e2002bf181da591332aTed Kremenek 972fce813e3159a67a57a03cdca45ac4e10d4cffac3Ted Kremenek friend class StmtIteratorBase; 9733793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek 9743793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 9757029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 9763793e1ab25169c0d5be43f3abe2b4dc92989c043Ted Kremenek } 9775cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek 9785cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenekprotected: 9795cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 9805cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 9815cde3834f43c0946ec8debfda9c6fb588b6b33fdTed Kremenek friend class Type; 9824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 9834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 9841b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// DependentSizedArrayType - This type represents an array type in 9851b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// C++ whose size is a value-dependent expression. For example: 9861b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @code 9871b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// template<typename T, int Size> 9881b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// class array { 9891b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// T data[Size]; 9901b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// }; 9911b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// @endcode 9921b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// For these types, we won't actually know what the array bound is 9931b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// until template instantiation occurs, at which point this will 9941b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 9951b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorclass DependentSizedArrayType : public ArrayType { 9961b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 9971b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// size of the array. 9981b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Stmt *SizeExpr; 9991b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10001b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 10011b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ArraySizeModifier sm, unsigned tq) 10021b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 10031b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class ASTContext; // ASTContext creates these. 10041b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void Destroy(ASTContext& C); 10051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorpublic: 10071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Expr *getSizeExpr() const { 10081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // We use C-style casts instead of cast<> here because we do not wish 10091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 10101b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return (Expr*) SizeExpr; 10111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 10121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 10141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10151b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const Type *T) { 10161b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return T->getTypeClass() == DependentSizedArray; 10171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 10181b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 10191b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class StmtIteratorBase; 10211b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10221b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 10237029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 10241b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 10251b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10261b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorprotected: 10271b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 10281b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 10291b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor friend class Type; 10301b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor}; 10311b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 10324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// VectorType - GCC generic vector type. This type is created using 10334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// __attribute__((vector_size(n)), where "n" specifies the vector size in 10344b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// bytes. Since the constructor takes the number of vector elements, the 10354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// client is responsible for converting the size into the number of elements. 10364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass VectorType : public Type, public llvm::FoldingSetNode { 10374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 10384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ElementType - The element type of the vector. 10394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ElementType; 10404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumElements - The number of elements in the vector. 10424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements; 10434b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner VectorType(QualType vecType, unsigned nElements, QualType canonType) : 10451b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(Vector, canonType, vecType->isDependentType()), 10461b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor ElementType(vecType), NumElements(nElements) {} 10474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner VectorType(TypeClass tc, QualType vecType, unsigned nElements, 10481486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman QualType canonType) 10491b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 10501b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor NumElements(nElements) {} 10514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 10524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getElementType() const { return ElementType; } 10554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumElements() const { return NumElements; } 10564b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 10584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 10594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 10604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getElementType(), getNumElements(), getTypeClass()); 10614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 10634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumElements, TypeClass TypeClass) { 10644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ElementType.getAsOpaquePtr()); 10654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(NumElements); 10664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddInteger(TypeClass); 10674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 1069af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 10704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 10714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const VectorType *) { return true; } 10724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 10734b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1074af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// ExtVectorType - Extended vector type. This type is created using 1075af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1076af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 10776154214e20225a883a8a00226499534e9b514315Steve Naroff/// class enables syntactic extensions, like Vector Components for accessing 10786154214e20225a883a8a00226499534e9b514315Steve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1079af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemanclass ExtVectorType : public VectorType { 1080af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1081af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 10824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 10834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 10849096b795541c783297fb19684a58c54d0fe823b8Chris Lattner static int getPointAccessorIdx(char c) { 10859096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 10869096b795541c783297fb19684a58c54d0fe823b8Chris Lattner default: return -1; 10879096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'x': return 0; 10889096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'y': return 1; 10899096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'z': return 2; 10909096b795541c783297fb19684a58c54d0fe823b8Chris Lattner case 'w': return 3; 10919096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 10921b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 10931486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman static int getNumericAccessorIdx(char c) { 10949096b795541c783297fb19684a58c54d0fe823b8Chris Lattner switch (c) { 10951486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman default: return -1; 10961486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '0': return 0; 10971486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '1': return 1; 10981486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '2': return 2; 10991486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '3': return 3; 11001486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '4': return 4; 11011486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '5': return 5; 11021486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '6': return 6; 11031486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '7': return 7; 11041486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '8': return 8; 11051486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case '9': return 9; 11061486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'a': return 10; 11071486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'b': return 11; 11081486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'c': return 12; 11091486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'd': return 13; 11101486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'e': return 14; 11111486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman case 'f': return 15; 11129096b795541c783297fb19684a58c54d0fe823b8Chris Lattner } 11131b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 111442158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner 111542158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner static int getAccessorIdx(char c) { 111642158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 11171486b507eb8b13d3cc77b42a32395a811c5c962eNate Begeman return getNumericAccessorIdx(c); 111842158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner } 111942158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner 11209096b795541c783297fb19684a58c54d0fe823b8Chris Lattner bool isAccessorWithinNumElements(char c) const { 112142158e7b3a95f41d3482f1fb3a67392dbbf745daChris Lattner if (int idx = getAccessorIdx(c)+1) 11229096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return unsigned(idx-1) < NumElements; 11239096b795541c783297fb19684a58c54d0fe823b8Chris Lattner return false; 11241b8a46c945927340ae7e79b771e93e7d36da4851Steve Naroff } 1125c11705f9b742b542724dd56796bf90e07191e342Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 1126c11705f9b742b542724dd56796bf90e07191e342Steve Naroff 1127806b319509d01bffe47317f11140c930da800dbbSteve Naroff static bool classof(const Type *T) { 1128af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman return T->getTypeClass() == ExtVector; 11294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 1130af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman static bool classof(const ExtVectorType *) { return true; } 11314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11324b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 11344fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 11354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 11364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass FunctionType : public Type { 11374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// SubClassData - This field is owned by the subclass, put here to pack 11384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// tightly with the ivars in Type. 11394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool SubClassData : 1; 11404b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis 11414fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 11424b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// other bitfields. 11434fa58905062efa6a12137b1983a1367220182a20Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 11444b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 11454b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 11464b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// cv-qualifier-seq, [...], are part of the function type. 11474b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis /// 11484b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned TypeQuals : 3; 11494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // The type returned by the function. 11514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType ResultType; 11524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerprotected: 11534b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 11541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 11551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, Canonical, Dependent), 11564b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 11574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool getSubClassData() const { return SubClassData; } 11584b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return TypeQuals; } 11594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getResultType() const { return ResultType; } 11624b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11634b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11644b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 11654b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto || 11664b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner T->getTypeClass() == FunctionProto; 11674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const FunctionType *) { return true; } 11694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 11704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11714fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 11724b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// no information available about its arguments. 11734fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 11744fa58905062efa6a12137b1983a1367220182a20Douglas Gregor FunctionNoProtoType(QualType Result, QualType Canonical) 11751b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1176f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman /*Dependent=*/false) {} 11774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 11784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 11794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // No additional state past what FunctionType provides. 11804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 11824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID) { 11844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner Profile(ID, getResultType()); 11854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 11874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ID.AddPointer(ResultType.getAsOpaquePtr()); 11884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 11904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 11914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionNoProto; 11924b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 11934fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 119487f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek 119587f0429f888ee5d332304641611b88f7b54b5065Ted Kremenekprotected: 119687f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 119787f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 119887f0429f888ee5d332304641611b88f7b54b5065Ted Kremenek friend class Type; 11994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 12004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12014fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 12024b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 12034b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner/// arguments, not as having a single void argument. 12044fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 12051b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 12061b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor /// types within the arguments passed in. 12071b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 12081b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 12091b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor if (ArgArray[Idx]->isDependentType()) 1210f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman return true; 12111b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 12121b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return false; 12131b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor } 12141b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor 12154fa58905062efa6a12137b1983a1367220182a20Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 12164b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis bool isVariadic, unsigned typeQuals, QualType Canonical) 12171b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1218f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman (Result->isDependentType() || 1219f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman hasAnyDependentType(ArgArray, numArgs))), 12204b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner NumArgs(numArgs) { 12214b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner // Fill in the trailing argument array. 12224b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 12234b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner for (unsigned i = 0; i != numArgs; ++i) 12244b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner ArgInfo[i] = ArgArray[i]; 12254b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12264b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12274b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// NumArgs - The number of arguments this function has, not counting '...'. 12284b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned NumArgs; 12294b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12304b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 12314b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// holds the argument types. 1232db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 12334b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 1234db4d5970d9243fb699f250f74eab6b7cce901a40Ted Kremenek 12354b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 12364b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner unsigned getNumArgs() const { return NumArgs; } 12374b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType getArgType(unsigned i) const { 12384b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(i < NumArgs && "Invalid argument number!"); 12394b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return arg_type_begin()[i]; 12404b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner bool isVariadic() const { return getSubClassData(); } 12434b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 12444b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12454b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner typedef const QualType *arg_type_iterator; 12464b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_begin() const { 12474b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return reinterpret_cast<const QualType *>(this+1); 12484b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12494b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 12504b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12514b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 12524b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12534b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const Type *T) { 12544b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner return T->getTypeClass() == FunctionProto; 12554b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 12574b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12584b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner void Profile(llvm::FoldingSetNodeID &ID); 12594b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 12604b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 12614b269b4f8fe1509a5d9a92bc02b1b8b503fcd2fdArgiris Kirtzidis bool isVariadic, unsigned TypeQuals); 1262034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek 1263034a78cafc3505323698ea72db19dc5095324e06Ted Kremenekprotected: 1264034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 1265034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 1266034a78cafc3505323698ea72db19dc5095324e06Ted Kremenek friend class Type; 12674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 12684b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12694b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12704b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TypedefType : public Type { 12714b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *Decl; 1272e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianprotected: 1273e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 12741b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 12754b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner assert(!isa<TypedefType>(can) && "Invalid canonical type"); 12764b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner } 12774b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner friend class ASTContext; // ASTContext creates these. 12784b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerpublic: 12794b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12804b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner TypedefDecl *getDecl() const { return Decl; } 12814b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1283a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 12844b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// sum of the type qualifiers, so if you have: 12854b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef const int A; 12864b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// typedef volatile A B; 12874b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner /// looking through the typedefs for B will give you "const volatile A". 12884b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner QualType LookThroughTypedefs() const; 12894b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12904b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 12914b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 12924fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 12934b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TypedefType *) { return true; } 12942f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek 12952f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenekprotected: 12962f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 12972f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 12982f665cd2aa263b89ac880dc45283847e5322a6c2Ted Kremenek friend class Type; 12994b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 13004b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13014fa58905062efa6a12137b1983a1367220182a20Douglas Gregor/// TypeOfExprType (GCC extension). 13024fa58905062efa6a12137b1983a1367220182a20Douglas Gregorclass TypeOfExprType : public Type { 13037cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *TOExpr; 13044fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TypeOfExprType(Expr *E, QualType can); 13057cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 13067cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 13077cbb14653934a298c09002b87704dc6531261771Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 13087cbb14653934a298c09002b87704dc6531261771Steve Naroff 13097cbb14653934a298c09002b87704dc6531261771Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 13107cbb14653934a298c09002b87704dc6531261771Steve Naroff 13114fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 13124fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 131371af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu 131471af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xuprotected: 131571af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu virtual void EmitImpl(llvm::Serializer& S) const; 131671af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 131771af02f1cea2bcedacbff2a20d883bf2b8042eb0Zhongxing Xu friend class Type; 13187cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 13197cbb14653934a298c09002b87704dc6531261771Steve Naroff 13207cbb14653934a298c09002b87704dc6531261771Steve Naroff/// TypeOfType (GCC extension). 13217cbb14653934a298c09002b87704dc6531261771Steve Naroffclass TypeOfType : public Type { 13227cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType TOType; 13231b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor TypeOfType(QualType T, QualType can) 13244fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 13257cbb14653934a298c09002b87704dc6531261771Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 13267cbb14653934a298c09002b87704dc6531261771Steve Naroff } 13277cbb14653934a298c09002b87704dc6531261771Steve Naroff friend class ASTContext; // ASTContext creates these. 13287cbb14653934a298c09002b87704dc6531261771Steve Naroffpublic: 13297cbb14653934a298c09002b87704dc6531261771Steve Naroff QualType getUnderlyingType() const { return TOType; } 13307cbb14653934a298c09002b87704dc6531261771Steve Naroff 13317cbb14653934a298c09002b87704dc6531261771Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 13327cbb14653934a298c09002b87704dc6531261771Steve Naroff 13334fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 13347cbb14653934a298c09002b87704dc6531261771Steve Naroff static bool classof(const TypeOfType *) { return true; } 13350da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu 13360da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xuprotected: 13370da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu virtual void EmitImpl(llvm::Serializer& S) const; 13380da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 13390da0273153e4526863ce8d1e06f94c8957bd4341Zhongxing Xu friend class Type; 13407cbb14653934a298c09002b87704dc6531261771Steve Naroff}; 13414b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13424b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattnerclass TagType : public Type { 134398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// Stores the TagDecl associated with this type. The decl will 134498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// point to the TagDecl that actually defines the entity (or is a 134598b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// definition in progress), if there is such a definition. The 134698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// single-bit value will be non-zero when this tag is in the 134798b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// process of being defined. 13489c7825b737617339724d43bd04960852271f08e2Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 134946a837c7ced306c55d1686cea5f77cb7a2f3b908Ted Kremenek friend class ASTContext; 135098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor friend class TagDecl; 13511d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 13521d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorprotected: 13531b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // FIXME: We'll need the user to pass in information about whether 13541b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // this type is dependent or not, because we don't have enough 13551b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor // information to compute it here. 13564fa58905062efa6a12137b1983a1367220182a20Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can) 13574fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : Type(TC, can, /*Dependent=*/false), decl(D, 0) {} 13581d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor 13591d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregorpublic: 136098b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 13614b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 136298b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// @brief Determines whether this type is in the process of being 136398b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor /// defined. 136498b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor bool isBeingDefined() const { return decl.getInt(); } 136598b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 136698b275417eab0af35ba0bf0d7dbd89253c710f3cDouglas Gregor 13674b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 1368734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor void getAsStringInternal(std::string &InnerString, 1369734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor bool SuppressTagKind) const; 1370734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 13714fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const Type *T) { 13724fa58905062efa6a12137b1983a1367220182a20Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 13734fa58905062efa6a12137b1983a1367220182a20Douglas Gregor } 13744b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner static bool classof(const TagType *) { return true; } 13754fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const RecordType *) { return true; } 13764fa58905062efa6a12137b1983a1367220182a20Douglas Gregor static bool classof(const EnumType *) { return true; } 13774fa58905062efa6a12137b1983a1367220182a20Douglas Gregor 13788db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenekprotected: 13798db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek virtual void EmitImpl(llvm::Serializer& S) const; 138064be4ada44c719304c1dee75fb1e551f84b7779aTed Kremenek static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 13818db5aa1ca0d42cf8aeaa78cbe196a50f70fc9fc1Ted Kremenek friend class Type; 13824b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner}; 13834b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 13841baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 13851baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of structs/unions/classes. 13861baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass RecordType : public TagType { 1387ea29d1ec6b76c3722d7c0fb6a3d35c2d8cc74a79Argiris Kirtzidisprotected: 13883cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit RecordType(RecordDecl *D) 13894fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 13904fa58905062efa6a12137b1983a1367220182a20Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 13914fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 13921d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 13931baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 13941baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 13951baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner RecordDecl *getDecl() const { 13961baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 13971baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 13981baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 13991baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 14001baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // recursively check all fields for const-ness. If any field is declared 14011baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // const, it needs to return false. 14021baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner bool hasConstFields() const { return false; } 14031baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 14041baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 14051baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner // the same address space, and return that. 14061baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner unsigned getAddressSpace() const { return 0; } 14071baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1408eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 1409eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 1410eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 1411eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 14121baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const RecordType *) { return true; } 14131baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 14141baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 14151baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 14161baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner/// to detect TagType objects of enums. 14171baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerclass EnumType : public TagType { 14183cbc064cf343c2151488b7822430ed327ade176eArgiris Kirtzidis explicit EnumType(EnumDecl *D) 14194fa58905062efa6a12137b1983a1367220182a20Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 14201d661556b9263f4d635372aecdea8c55dac84e83Douglas Gregor friend class ASTContext; // ASTContext creates these. 14211baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattnerpublic: 14221baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 14231baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner EnumDecl *getDecl() const { 14241baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 14251baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner } 14261baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1427eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const TagType *T); 1428eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner static bool classof(const Type *T) { 1429eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 1430eae0eaa09f163aa27d2eb0244ed2d3ebed8eed6fChris Lattner } 14311baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner static bool classof(const EnumType *) { return true; } 14321baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner}; 14331baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1434a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1435a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned Depth : 16; 1436a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned Index : 16; 1437a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor IdentifierInfo *Name; 1438dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1439a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1440a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor QualType Canon) 1441a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1442a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor Depth(D), Index(I), Name(N) { } 1443dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1444a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I) 1445a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1446a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor Depth(D), Index(I), Name(0) { } 1447dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1448a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor friend class ASTContext; // ASTContext creates these 1449dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1450a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregorpublic: 1451a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned getDepth() const { return Depth; } 1452a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned getIndex() const { return Index; } 1453a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor IdentifierInfo *getName() const { return Name; } 1454a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 1455dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 14561baaf13ea33c7b60742bf772bca8df2ccc1a51a8Chris Lattner 1457a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1458a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor Profile(ID, Depth, Index, Name); 1459a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 1460a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 1461a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1462a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor unsigned Index, IdentifierInfo *Name) { 1463a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Depth); 1464a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddInteger(Index); 1465a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor ID.AddPointer(Name); 1466a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor } 1467a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 1468dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const Type *T) { 1469dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor return T->getTypeClass() == TemplateTypeParm; 1470dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor } 1471dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 1472dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1473dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorprotected: 1474dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 1475dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1476dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor friend class Type; 1477dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor}; 1478a491877807202cfb1812f6dcdbb7b992c41ca634Douglas Gregor 14798e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// \brief Represents the type of a class template specialization as 14808e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// written in the source code. 14818e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// 14828e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// Class template specialization types represent the syntactic form 14838e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// of a template-id that refers to a type, e.g., @c vector<int>. All 14848e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization types are syntactic sugar, whose 14858e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// canonical type will point to some other type node that represents 14868e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// the instantiation or class template specialization. For example, a 14878e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// class template specialization type of @c vector<int> will refer to 14888e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// a tag type for the instantiation 14898e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 14908e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorclass ClassTemplateSpecializationType 14918e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor : public Type, public llvm::FoldingSetNode { 14928e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 14938e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor // FIXME: Do we want templates to have a representation in the type 14948e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor // system? It will probably help with dependent templates and 14958e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor // possibly with template-names preceded by a nested-name-specifier. 14968e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor TemplateDecl *Template; 14978e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 1498f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief - The number of template arguments named in this class 1499f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// template specialization. 15008e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned NumArgs; 15018e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 1502f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor ClassTemplateSpecializationType(TemplateDecl *T, 1503f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor const TemplateArgument *Args, 1504f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor unsigned NumArgs, QualType Canon); 15058e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15066f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor virtual void Destroy(ASTContext& C); 15076f37b58716e89420c13ac067fe605c3b6d5821d0Douglas Gregor 15088e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor friend class ASTContext; // ASTContext creates these 15098e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15108e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorpublic: 1511f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Determine whether any of the given template arguments are 1512f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// dependent. 1513f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 1514f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor unsigned NumArgs); 1515f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 151656d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 151756d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor /// enclosing the template arguments. 151856d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 151956d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor unsigned NumArgs); 152056d25a726f0bdb4db08021b9e98782ada5241eafDouglas Gregor 1521f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor typedef const TemplateArgument * iterator; 1522f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 1523f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator begin() const { return getArgs(); } 1524f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor iterator end() const; 1525f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 15268e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \brief Retrieve the template that we are specializing. 15278e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor TemplateDecl *getTemplate() const { return Template; } 15288e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 1529f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the template arguments. 1530f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor const TemplateArgument *getArgs() const { 1531f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 1532f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor } 1533f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor 1534f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor /// \brief Retrieve the number of template arguments. 15358e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 15368e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15378e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \brief Retrieve a specific template argument as a type. 15388e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor /// \precondition @c isArgType(Arg) 1539f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 15408e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15418e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 15428e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15438e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1544f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor Profile(ID, Template, getArgs(), NumArgs); 15458e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 15468e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15478e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateDecl *T, 1548f9ff4b14cfc4ee2c4e43dbb71242aa85446ecc2aDouglas Gregor const TemplateArgument *Args, unsigned NumArgs); 15498e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15508e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor static bool classof(const Type *T) { 15518e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor return T->getTypeClass() == ClassTemplateSpecialization; 15528e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor } 15538e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor static bool classof(const ClassTemplateSpecializationType *T) { return true; } 15548e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 15558e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregorprotected: 15568e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 15578e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 15588e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor friend class Type; 15598e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor}; 15608e458f48f07276fe279a3d02e709e7ce15b2f9c3Douglas Gregor 1561734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1562734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// name, e.g., N::M::type. 1563734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// 1564734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// This type is used to keep track of a type name as written in the 1565734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor/// source code, including any nested-name-specifiers. 1566734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 15671e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief The nested name specifier containing the qualifier. 15681e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *NNS; 1569734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1570734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief The type that this qualified name refers to. 1571734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType NamedType; 1572734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 15731e589cc31d339860b9df61870930961601d68120Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 15741e589cc31d339860b9df61870930961601d68120Douglas Gregor QualType CanonType) 15751e589cc31d339860b9df61870930961601d68120Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 15761e589cc31d339860b9df61870930961601d68120Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1577734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1578734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor friend class ASTContext; // ASTContext creates these 1579734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1580734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorpublic: 15811e589cc31d339860b9df61870930961601d68120Douglas Gregor /// \brief Retrieve the qualification on this type. 15821e589cc31d339860b9df61870930961601d68120Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1583734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1584734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1585734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor QualType getNamedType() const { return NamedType; } 1586734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1587734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 1588734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1589734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 15901e589cc31d339860b9df61870930961601d68120Douglas Gregor Profile(ID, NNS, NamedType); 1591734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 1592734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 15931e589cc31d339860b9df61870930961601d68120Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 15941e589cc31d339860b9df61870930961601d68120Douglas Gregor QualType NamedType) { 15951e589cc31d339860b9df61870930961601d68120Douglas Gregor ID.AddPointer(NNS); 15961e589cc31d339860b9df61870930961601d68120Douglas Gregor NamedType.Profile(ID); 15971e589cc31d339860b9df61870930961601d68120Douglas Gregor } 1598734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1599734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor static bool classof(const Type *T) { 1600734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor return T->getTypeClass() == QualifiedName; 1601734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor } 1602734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1603734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1604734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregorprotected: 1605734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor virtual void EmitImpl(llvm::Serializer& S) const; 1606734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1607734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor friend class Type; 1608734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor}; 1609734b4baa8e7677d03085a3d3716fa550fb40be63Douglas Gregor 1610f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1611f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// object oriented design. They basically correspond to C++ classes. There 1612f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1613f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// qualified interfaces, which are qualified with a protocol list like 1614f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1615f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 161642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCInterfaceType : public Type { 161742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *Decl; 16180c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanianprotected: 161942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 16201b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 162181f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff friend class ASTContext; // ASTContext creates these. 162281f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroffpublic: 162381f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 162442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 162581f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 1626f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1627f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// list of protocols qualifying this interface. If this is an instance of 1628f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1629f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// empty list if there are no qualifying protocols. 1630f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1631f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner inline qual_iterator qual_begin() const; 1632f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner inline qual_iterator qual_end() const; 1633f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1634f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1635f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1636f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner /// interface type, or 0 if there are none. 1637f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner inline unsigned getNumProtocols() const; 1638f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1639d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner /// getProtocol - Return the specified qualifying protocol. 1640d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner inline ObjCProtocolDecl *getProtocol(unsigned i) const; 164191193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian 1642f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1643f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 164481f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff static bool classof(const Type *T) { 1645b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner return T->getTypeClass() == ObjCInterface || 1646b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner T->getTypeClass() == ObjCQualifiedInterface; 164781f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff } 164842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 164981f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff}; 165081f1bbabbdb7dce07802111e2d9648eedc866d51Steve Naroff 165142730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1652e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1653e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// 1654c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1655c5a342d3b1cc5fa6eef09653a6d8d091928366c0Fariborz Jahanian/// alphabetical order. 165642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 16570c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian public llvm::FoldingSetNode { 16580c2f214d3500d1d080afa36b96db40407b91e70dFariborz Jahanian 1659c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian // List of protocols for this protocol conforming object type 1660c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1661f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1662c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian 166342730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1664b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 166542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 1666d855a6ead44e3a875179400c472ac0b37df35f70Chris Lattner Protocols(Protos, Protos+NumP) { } 166791193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1668c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanianpublic: 1669c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian 1670d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner ObjCProtocolDecl *getProtocol(unsigned i) const { 167191193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian return Protocols[i]; 167291193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian } 167391193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian unsigned getNumProtocols() const { 167491193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian return Protocols.size(); 167591193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian } 1676b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner 1677b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1678b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1679b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner 168091193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 168191193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian 168291193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 168391193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 1684fd5690fe6b5ea1c553dfe20f99d3fef269a50bd1Chris Lattner const ObjCInterfaceDecl *Decl, 168542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 168691193f64449fe1faf9306a04ade6539d26f44037Fariborz Jahanian 1687c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian static bool classof(const Type *T) { 168842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1689c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian } 169042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1691c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian}; 1692f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1693f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1694f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1695f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1696f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return QIT->qual_begin(); 1697f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return 0; 1698f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1699f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1700f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1701f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1702f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return QIT->qual_end(); 1703f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return 0; 1704f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1705f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1706f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1707f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner/// interface type, or 0 if there are none. 1708f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1709f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1710f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1711f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return QIT->getNumProtocols(); 1712f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner return 0; 1713f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1714f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1715d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner/// getProtocol - Return the specified qualifying protocol. 1716d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattnerinline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1717d5f8179ed2b75e5c21109f3dd996836b5f743ecdChris Lattner return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1718f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner} 1719f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1720f81d921ec2f5bac3f35a94392fe2b764473884eeChris Lattner 1721e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1722e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// ObjCQualifiedIdType - to represent id<protocol-list>. 1723e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// 1724e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// Duplicate protocols are removed and protocol list is canonicalized to be in 1725e86716008551d268871e9aa7b27ea1b64b462991Chris Lattner/// alphabetical order. 172642730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekclass ObjCQualifiedIdType : public Type, 1727e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian public llvm::FoldingSetNode { 1728e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian // List of protocols for this protocol conforming 'id' type 1729e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 173042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1731e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 17324a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 17331b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 1734f1791b0a471cd61641eca7f4c0815cdce2f105eaNate Begeman /*Dependent=*/false), 1735e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian Protocols(Protos, Protos+NumP) { } 1736e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian friend class ASTContext; // ASTContext creates these. 1737e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanianpublic: 1738e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 173942730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 1740e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian return Protocols[i]; 1741e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian } 1742e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian unsigned getNumProtocols() const { 1743e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian return Protocols.size(); 1744e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian } 174542730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1746957442db1d23f62ee2d0d71310bee240606b267dFariborz Jahanian return &Protocols[0]; 1747b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner } 1748b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner 1749b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1750b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1751b0c6a1fcc5d43696387d2870cc4722581f6db671Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1752e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1753e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 1754e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1755e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 17564a68fe04deb7ab89ac7566dc55b3b623129c72e5Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, 175742730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 1758e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1759e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian static bool classof(const Type *T) { 176042730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek return T->getTypeClass() == ObjCQualifiedId; 1761e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian } 176242730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenek static bool classof(const ObjCQualifiedIdType *) { return true; } 1763e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian 1764e76e8416ff29ee39140b64ed47731237c67434aeFariborz Jahanian}; 1765c04aff17dcfaa5f628bcfed0e393f2e946ea5184Fariborz Jahanian 1766262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// ObjCQualifiedClassType - to represent Class<protocol-list>. 1767262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// 1768262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 1769262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff/// alphabetical order. 1770262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroffclass ObjCQualifiedClassType : public Type, 1771262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff public llvm::FoldingSetNode { 1772262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff // List of protocols for this protocol conforming 'id' type 1773262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff // List is sorted on protocol name. No protocol is enterred more than once. 1774262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1775262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1776262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff ObjCQualifiedClassType(ObjCProtocolDecl **Protos, unsigned NumP) 1777d305a86f087fd359cf0f033eba0c968e55a61ff4Steve Naroff : Type(ObjCQualifiedClass, QualType()/*these are always canonical*/, 1778262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff /*Dependent=*/false), 1779262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff Protocols(Protos, Protos+NumP) { } 1780262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff friend class ASTContext; // ASTContext creates these. 1781262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroffpublic: 1782262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1783262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff ObjCProtocolDecl *getProtocols(unsigned i) const { 1784262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff return Protocols[i]; 1785262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff } 1786262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff unsigned getNumProtocols() const { 1787262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff return Protocols.size(); 1788262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff } 1789262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff ObjCProtocolDecl **getReferencedProtocols() { 1790262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff return &Protocols[0]; 1791262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff } 1792262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1793262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1794262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 1795262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff qual_iterator qual_end() const { return Protocols.end(); } 1796262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1797262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 1798262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1799262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 1800262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, 1801262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 1802262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1803262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff static bool classof(const Type *T) { 1804d305a86f087fd359cf0f033eba0c968e55a61ff4Steve Naroff return T->getTypeClass() == ObjCQualifiedClass; 1805262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff } 1806262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff static bool classof(const ObjCQualifiedClassType *) { return true; } 1807262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff 1808262a5dd7735667460dc4fcf0bef0b5df0ef5335eSteve Naroff}; 18094b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 1810b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner// Inline function definitions. 18114b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 18122a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 18132a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline QualType QualType::getUnqualifiedType() const { 181435fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner Type *TP = getTypePtr(); 1815b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1816b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian TP = EXTQT->getBaseType(); 181735fef52886c88e3855745917fcb0bf6a19fa0ba1Chris Lattner return QualType(TP, 0); 18182a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 18192a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb 18202a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb/// getAddressSpace - Return the address space of this type. 18212a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lambinline unsigned QualType::getAddressSpace() const { 182201ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 182301ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1824a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return AT->getElementType().getAddressSpace(); 182501ee73fb7b2734d3ca1c5876dc623811518985dfChris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1826efc11216a5755f69b5540289aa2dd374d4bc82abNate Begeman return RT->getAddressSpace(); 1827b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1828b60352aa80d17026f445267940db558ab9cfb92eFariborz Jahanian return EXTQT->getAddressSpace(); 18292a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return 0; 18302a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb} 1831b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner 1832af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 1833af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1834af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1835af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1836af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian return AT->getElementType().getObjCGCAttr(); 1837af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1838af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian return EXTQT->getObjCGCAttr(); 1839184541a6a7d218583d79d408534f77c27b7b8c6eFariborz Jahanian if (const PointerType *PT = CT->getAsPointerType()) 1840184541a6a7d218583d79d408534f77c27b7b8c6eFariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 18417029ee3fdeee514a79eafb2508723d27c97fe158Chris Lattner return GCNone; 1842af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian} 1843af23809cb5b961cd4624785e94f339e0a0f5f49eFariborz Jahanian 18443fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 18453fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 18463fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// is more qualified than "const int", "volatile int", and 18473fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int". However, it is not more qualified than "const volatile 18483fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int". 18493fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 18503fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor // FIXME: Handle address spaces 18513fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 18523fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 18534459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(this->getAddressSpace() == 0 && "Address space not checked"); 18544459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(Other.getAddressSpace() == 0 && "Address space not checked"); 18553fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 18563fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 18573fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 18583fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 18593fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// as qualified as the Other type. For example, "const volatile 18603fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 18613fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// "int", and "const volatile int". 18623fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 18633fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor // FIXME: Handle address spaces 18643fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 18653fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 18664459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(this->getAddressSpace() == 0 && "Address space not checked"); 18674459bbe1ad110c100d74af8c74fdc82d87317dfeDouglas Gregor assert(Other.getAddressSpace() == 0 && "Address space not checked"); 18683fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 18693fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 18703fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 18713fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 18723fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int&), returns the type that the reference refers to ("const 18733fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 18743fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// throughout Sema to implement C++ 5p6: 18753fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 18763fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 18773fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 18783fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// analysis, the expression designates the object or function 18793fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 18803fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregorinline QualType QualType::getNonReferenceType() const { 18813fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 18823fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return RefType->getPointeeType(); 18833fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor else 18843fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor return *this; 18853fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor} 18863fb675ab045253ffe2f1b333e9f8e746b50abeb4Douglas Gregor 18875c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenekinline const TypedefType* Type::getAsTypedefType() const { 18885c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek return dyn_cast<TypedefType>(this); 18895c45be48e6125c5981ad48708dc7e8267bace63aTed Kremenek} 1890f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1891f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner if (const PointerType *PT = getAsPointerType()) 1892f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 1893f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner return 0; 1894f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner} 1895f914765ba1d70f599fa69bde38b8646c02d9b1aaChris Lattner 1896a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1897a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner// space qualifiers if present. 1898b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isFunctionType() const { 18992a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1900b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 1901b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isPointerType() const { 19022a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1903b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 19047aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroffinline bool Type::isBlockPointerType() const { 19057aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff return isa<BlockPointerType>(CanonicalType); 19067aa5475ca2f62df5ba3f3b647ee141a40bf48fd3Steve Naroff} 1907cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattnerinline bool Type::isReferenceType() const { 1908cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1909cfac88de7de7d970a2436af939ea87c0e5a9cf9fChris Lattner} 1910ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isLValueReferenceType() const { 1911ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 1912ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 1913ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redlinline bool Type::isRValueReferenceType() const { 1914ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 1915ce6fff0486d0e15bc969fb0e3e4850c0784e997fSebastian Redl} 191683b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenekinline bool Type::isFunctionPointerType() const { 191774a340749eb63af1ba7098c67f3ef72bd48f5ae8Ted Kremenek if (const PointerType* T = getAsPointerType()) 191883b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return T->getPointeeType()->isFunctionType(); 191983b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek else 192083b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek return false; 192183b01279f2e6718581eeb1e5bdba58aa88e4649bTed Kremenek} 19227555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberPointerType() const { 19237555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 19247555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 19257555503bb5f08651638f269c44c15bb425d10c5eSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 19267555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl if (const MemberPointerType* T = getAsMemberPointerType()) 19277555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return T->getPointeeType()->isFunctionType(); 19287555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl else 19297555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl return false; 19307555503bb5f08651638f269c44c15bb425d10c5eSebastian Redl} 1931b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isArrayType() const { 19322a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1933b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 1934a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isConstantArrayType() const { 1935a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1936a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 1937a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isIncompleteArrayType() const { 1938a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1939a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 1940a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattnerinline bool Type::isVariableArrayType() const { 1941a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1942a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner} 19431b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregorinline bool Type::isDependentSizedArrayType() const { 19441b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 19451b21c7ffe5fac1711fea35e4830159004a835c1aDouglas Gregor} 1946b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isRecordType() const { 19472a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1948b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 19493277df47de6b65b55721726dc3f7b294e70ef6feChris Lattnerinline bool Type::isAnyComplexType() const { 1950a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 19513277df47de6b65b55721726dc3f7b294e70ef6feChris Lattner} 1952b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattnerinline bool Type::isVectorType() const { 19532a72bb32dfda134cb2bab50f5bb4a6b214f84348Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1954b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 1955af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begemaninline bool Type::isExtVectorType() const { 1956af6ed504d90dc3b813c573bfbee8bc0e92e7fdc0Nate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1957b0fdfd50e1e4011486d5cb3773e1e87c8ec4325aChris Lattner} 195842730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCInterfaceType() const { 1959a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1960b06cf30badcddfea862bc9a538447453bdd94598Chris Lattner} 1961b06cf30badcddfea862bc9a538447453bdd94598Chris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 1962a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1963550e05034c6c8efcb7ab4c65f58048eee0892237Fariborz Jahanian} 196442730c53aeef9ac6c258d317065fdf38da4e043cTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 1965a1923f6d95601582f4a5c3924b8e1c5ac3f658b3Chris Lattner return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1966dcb2b1e489948a570ee07ca65e12d42edffa20efFariborz Jahanian} 1967dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregorinline bool Type::isTemplateTypeParmType() const { 1968dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 1969dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor} 1970dd861060e2e1f1e41f7b023d025fcd8eb183686dDouglas Gregor 1971c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 197245014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 1973c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 1974c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return true; 1975c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar return false; 1976c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar} 1977c61a8003b2c69add9fca0ec5064b47251f47c90cDaniel Dunbar 197800fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// \brief Determines whether this is a type for which one can define 197900fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor/// an overloaded operator. 198000fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregorinline bool Type::isOverloadableType() const { 198100fe3f63604d2be2fafbf42fe5df0795d7d29116Douglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 198245014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor} 198345014fd2d7e50079dc092df04fec9af7ea0cb0e0Douglas Gregor 1984fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 1985fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 1986fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar isObjCInterfaceType() || isObjCQualifiedIdType() || 1987fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar isObjCQualifiedInterfaceType()); 1988fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar} 1989fc096bf9d87834466e82482f99b1f6fe7e02bf2aDaniel Dunbar 19907c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 19917c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian return (isObjCInterfaceType() || isObjCQualifiedIdType() || 19927c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian isObjCQualifiedInterfaceType()); 19937c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian} 19947c0c17b528295299020428f583a480a6dcb4c7e0Fariborz Jahanian 1995da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 1996da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner/// diagnostic with <<. 1997da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1998da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner QualType T) { 1999da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 2000da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner Diagnostic::ak_qualtype); 2001da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner return DB; 2002da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner} 2003da5c087ebf3d47b40bae2e99671ce1929156a427Chris Lattner 20044b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner} // end namespace clang 20054b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner 20064b0096578e961587d1ec0ed5dce45f592a65ed4Chris Lattner#endif 2007