Type.h revision 6e8ed16ffef02b82995a90bdcf10ffff7d63839a
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Type interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h" 181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h" 19e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h" 22fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h" 235cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h" 245cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h" 251734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h" 267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa; 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null; 32bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattnernamespace clang { class Type; } 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 36daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 37bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 38bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 39bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 40bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 41bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 42bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 43bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 44bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner enum { NumLowBitsAvailable = 3 }; 45bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TypedefDecl; 5155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 5272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 53aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 547532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 5749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 5921d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 60a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 61a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 62a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 64b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 6692866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 6740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 68e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor class QualifiedNameType; 6972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 7072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 7172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 7272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 73f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 855cf243a883872441d73ca49cea7e20de5802629bChris Lattner llvm::PointerIntPair<Type*, 3> Value; 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 94d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian enum GCAttrTypes { 95d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 96d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 97d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 98d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 99d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1005cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1025cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 1035cf243a883872441d73ca49cea7e20de5802629bChris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1055cf243a883872441d73ca49cea7e20de5802629bChris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 106a3ab4b85f54090927c2dfa2585b9f0e48509e944Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 1075cf243a883872441d73ca49cea7e20de5802629bChris Lattner Type *getTypePtr() const { return Value.getPointer(); } 1085cf243a883872441d73ca49cea7e20de5802629bChris Lattner 1095cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 1125cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1265cf243a883872441d73ca49cea7e20de5802629bChris Lattner return getTypePtr() == 0; 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 1305cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Const) ? true : false; 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 1335cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 1365cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 138b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 139b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1407effa1aceac1219529af23c776835f855b8d905cChris Lattner 1417effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1427effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1435cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 1445cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1455cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1475cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1485cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1495cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 1501c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 154c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 155c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 156c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 157971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 158971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 159971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 160971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 162e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getUnqualifiedType() const; 163e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 164e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 165e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1672fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 1682fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 1692fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 1702fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1712fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1722fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 173969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 17498cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1785cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value == RHS.Value; 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1815cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value != RHS.Value; 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string getAsString() const { 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getAsStringInternal(S); 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void getAsStringInternal(std::string &Str) const; 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 190c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 191c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 1923f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek 1933f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 1943f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 1953f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 197368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 199ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 200ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 201ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 202d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 203d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 204f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 205f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 206f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 207f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 208f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 209f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 210f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 211f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 22973af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2304e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2314e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 232daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2334e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2364e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2394e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 24011a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2410eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 24373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 25872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 26172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 27572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 27672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 27772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 27872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 280d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 284898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 285898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 286898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 290ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned TC : 5; 291898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 29216ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 29316ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 295124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 296124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 297898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 298f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 299898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 300898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3014b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 30373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 3048b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 305a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 312bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 313bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 314bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 315bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 316bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 317bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 325d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 326d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 327d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 328d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 329d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 330d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 33164b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 33264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 33364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 33464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 335d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 336d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 337d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 338d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 340ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 341e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 342e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 343e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 34496d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 34596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 34696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 34813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 34913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 35013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 35177a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 35233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 35602f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 35702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 359f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 363c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 364c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 365c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 366d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 368c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 369ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 370c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 37126d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 37226d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 373befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 3745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 375a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 378bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 379f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 380f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 381c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 382c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 383c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 384c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 385898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 386c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 38799dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner bool isClassType() const; 388c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3894cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 390368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 391368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 392213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 393368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 394368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 395368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 39672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 3976e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 398898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 399898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 400898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// that its definition somehow depends on a template parameter 401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 402898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 403063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 40472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4058958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4068958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4078958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4086e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4098958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4108958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 411820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 412820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 413820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian bool hasObjCPointerRepresentation() const; 414820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 415c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 416f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 417f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 418f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 419f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 42072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 42172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 422befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 4235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 424a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 4257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const LValueReferenceType *getAsLValueReferenceType() const; 4267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const RValueReferenceType *getAsRValueReferenceType() const; 427f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const MemberPointerType *getAsMemberPointerType() const; 428fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor const TagType *getAsTagType() const; 429c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 430769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 431898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 432769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 433c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 434ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 435c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 436c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4374cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 438213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 439368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 440368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 441368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 44272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 44372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4457532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 44655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 4472b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4482b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4492b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4502b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 451c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 452c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 453c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 454c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 455c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 456dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 457769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 458dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 459dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4603830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 461dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 462969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 463dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 468d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 469d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 470d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 474d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 475d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 476d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 478d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 4809bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4819bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 4823c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 483c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 485c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const = 0; 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 490f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 491f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 492f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 493f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 494ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 495f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 496f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 497f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 498f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 499f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 50059d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 501ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 502ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 50359d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 504d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 50559d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 50659d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 507d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 508b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 509b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 510b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 511b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 512b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 513ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 514ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 515f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 516d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5174886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 518ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 519ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb virtual void getAsStringInternal(std::string &InnerString) const; 520ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 521ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5224886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 523ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 524f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 525d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 526f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 527ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5284886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 529ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 530ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 531f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 532f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 533ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 534ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 535ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 5502df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 5542ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 5592df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5618e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 5628e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 5636e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 5646e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 565898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 566898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent // This represents the type of a type-dependent expression. 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 571898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor BuiltinType(Kind K) 572898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 573898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *getName() const; 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 584f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 585f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 586f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 587f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 588f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 589f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 590f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 591f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 592f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 593f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 594f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 595f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 596f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 597f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 598f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 599f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 600f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 601f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 602f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 603f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 604f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 611898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 612898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 61903ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 63168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 632bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 63368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 634bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 63768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 64468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 64568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6575618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 6585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 6595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6605618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 6615618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6625618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 664898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 665898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 6665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 6685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 6695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6725618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 6745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 6765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 6775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 6805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const Type *T) { 6835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return T->getTypeClass() == BlockPointer; 6845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 6865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 6875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 69068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 69168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 69268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6937c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 6947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 6957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 69668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 6975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 69968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 70068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 702bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 7107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 7117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 7137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 7167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 7187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 7207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 7237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl virtual void getAsStringInternal(std::string &InnerString) const; 7247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 7277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 7297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 7327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 7347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 7367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 7397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl virtual void getAsStringInternal(std::string &InnerString) const; 7407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 7437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 745f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 746f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 747f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 748f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 749f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 750f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 751f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 752f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 753f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 754f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 755f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 756f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 757f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 758f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 759f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 760f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 761f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 762f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 763f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 764f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 765f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 766f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 767f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl virtual void getAsStringInternal(std::string &InnerString) const; 768f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 769f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 770f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 771f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 772f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 773f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 774f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 775f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 776f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 777f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 778f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 779f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 780f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 781f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7862e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 789898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 790898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 791898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 796fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 797fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 798c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 799ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 800c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 801ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 802c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 803c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 804c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 805c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 806c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 807fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 808898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 809898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 810898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 811898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 812898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 813c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 814c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 815898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 816898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 817898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 818fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 819fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 820fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 821ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 822ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 823ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 824c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 825fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 826fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 827fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 828c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 829898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 830898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 831fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 832fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 833fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 834fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 835da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant 836da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[100]' has ConstantArrayType where the element type 837da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// is 'int' and the size is 100. 8382e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 839fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 840fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 8410be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 842c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 8430be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 844fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 845fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 846c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 847fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 848fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 849fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8500be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSize(), 8510be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 852fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 853fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8540be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 8550be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 856fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 857fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 8580be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8590be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 860fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 861fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 862fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray; 863fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 864fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 865fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 866fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 867da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 868da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 869da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 870c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 871c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 872c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArraySizeModifier sm, unsigned tq) 873c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 874c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 875c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 876c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 877c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman virtual void getAsStringInternal(std::string &InnerString) const; 878c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 879c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 880c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 881c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 882c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 883c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 884c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 885c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 886c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 8870be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 888c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 889c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 8900be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8910be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 892c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 8930be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8940be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 895c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 896c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 897c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 898da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 899da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 900da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 901da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 902da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 903da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 904da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 905da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 906da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 907da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 908da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 909da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 910da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 911da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 912da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 9132e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 914fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 915fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 916b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 918c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 919c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 920b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9224b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 9234b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 925c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Expr *getSizeExpr() const { 926b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 927b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 928b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 929b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 933fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 934fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 936fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 937a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 93892866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 9392bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 9402bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 941bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 9422bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 945898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 946898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 947898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 948898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// template<typename T, int Size> 949898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 950898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 951898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 953898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 954898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 956898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 957898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 958898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 959898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 960898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 961898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 962898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArraySizeModifier sm, unsigned tq) 963898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 964898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 965898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 966898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 967898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 968898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr *getSizeExpr() const { 969898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 970898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 971898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 972898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 973898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 974898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 975898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 976898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const Type *T) { 977898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return T->getTypeClass() == DependentSizedArray; 978898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 979898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 980898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 981898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 982898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 983898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 984bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 985898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 986898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 987898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 98873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 98973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 99073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 99173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 99373322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 100073322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1001898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Vector, canonType, vecType->isDependentType()), 1002898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(vecType), NumElements(nElements) {} 100373322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1004353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman QualType canonType) 1005898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1006898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumElements(nElements) {} 10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 101673322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 101873322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 101973322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 102273322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 102373322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 102473322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 1025213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 10285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1030213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1031213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1032213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1033fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1034fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1035213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1036213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1037213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 103873322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 103973322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 104088dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 104188dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 104288dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 104388dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 104488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 104588dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 104688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 104788dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1048e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1049353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 105088dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1051353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1052353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1053353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1054353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1055353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1056353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1057353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1058353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1059353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1060353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1061353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1062353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1063353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1064353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1065353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1066353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1067353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 106888dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1069e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1070b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 1071b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1072b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1073353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1074b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 1075b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 107688dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1077b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 107888dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 107988dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1080e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 108131a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 108231a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 10837064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 1084213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == ExtVector; 108573322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1086213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 108773322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 108873322924127c873c13101b705dd823f5539ffa5fSteve Naroff 10895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 109072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 10915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1096971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 109772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1098971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 109972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1100971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1101971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1102971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1103971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1104971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1109971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1110898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 1111898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 1112971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 11135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1114971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 112772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 112972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 113072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType(QualType Result, QualType Canonical) 1131898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 11324b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false) {} 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 114972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 115272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// arguments, not as having a single void argument. 115572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1156898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1157898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1158898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1159898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 11614b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1162898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1163898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1165898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 116672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1167bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl bool isVariadic, unsigned typeQuals, QualType Canonical) 1168898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 11694b4218f48fef71a179c5a8287dae281580faf52fNate Begeman (Result->isDependentType() || 11704b4218f48fef71a179c5a8287dae281580faf52fNate Begeman hasAnyDependentType(ArgArray, numArgs))), 1171bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl NumArgs(numArgs) { 1172942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1173bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1177bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1179bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl unsigned NumArgs; 1180bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl 1181942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1182942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1183bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11854b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1190942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1192bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1194971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1197942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1198942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1199942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1200942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1201bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 12065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 120772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1208bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl 12095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1211942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1212bfa2fcba545fb270f31205d616846c2bfaf4e47eSebastian Redl bool isVariadic, unsigned TypeQuals); 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 12175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1218c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 1219c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1220898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 1227a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 1228a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1229fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1230a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1231a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1232a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1233a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1234a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 123872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 12405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 124272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 124372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1244d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 124572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TypeOfExprType(Expr *E, QualType can); 1246d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1247d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1248d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 1249d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1250d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 1251d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 125272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 125372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1254d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1255d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1256d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1257d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1258d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 1259898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeOfType(QualType T, QualType can) 126072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1261d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1262d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1263d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1264d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1265d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 1266d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1267d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff virtual void getAsStringInternal(std::string &InnerString) const; 1268d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 126972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1270d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1271d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 12740b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 12750b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 12760b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 12770b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 12780b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1279fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 12804b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 12810b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 12822ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 12832ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 1284898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // FIXME: We'll need the user to pass in information about whether 1285898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // this type is dependent or not, because we don't have enough 1286898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // information to compute it here. 128772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can) 128872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TC, can, /*Dependent=*/false), decl(D, 0) {} 12892ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 12902ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorpublic: 12910b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12930b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 12940b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// defined. 12950b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 12960b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 12970b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer virtual void getAsStringInternal(std::string &InnerString) const; 1299e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void getAsStringInternal(std::string &InnerString, 1300e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor bool SuppressTagKind) const; 1301e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 130272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { 130372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 130472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 130672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 130772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 13115edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 13125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 131349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1314509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 131572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 131672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 131772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 13182ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 13195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 13205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 13225edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 13235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 13245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 13265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 13275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 13285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 13295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 13315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 13325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 13335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13342daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 13352daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 13362daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 13372daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 13385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 13395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 13405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 13425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 13435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1344509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 134572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 13462ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 13475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 13485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 13505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 13515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 13525edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13532daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 13542daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 13552daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 13562daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 13575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 13585edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 13595edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1360fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1361fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Depth : 16; 1362fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 1363fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 136472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1365fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1366fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor QualType Canon) 1367fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1368fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Depth(D), Index(I), Name(N) { } 136972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1370fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I) 1371fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1372fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Depth(D), Index(I), Name(0) { } 137372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1374fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 137572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1376fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1377fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1378fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 1379fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 1380fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 138172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 13825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1383fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1384fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Profile(ID, Depth, Index, Name); 1385fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1386fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1387fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1388fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index, IdentifierInfo *Name) { 1389fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1390fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 1391fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1392fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1393fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 139472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const Type *T) { 139572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return T->getTypeClass() == TemplateTypeParm; 139672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 139772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 139872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1399fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 14007532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 14017532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 140255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 14037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 14047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 14057532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 14067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 14077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 140855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 14097532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// a tag type for the instantiation 141055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 14117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 14127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 14137532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 14147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 14157532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorclass TemplateSpecializationType 141655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 141755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief The name of the template being specialized. 14197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 142055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 142140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 142240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 142355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 142455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateSpecializationType(TemplateName T, 14267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 14277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 142855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14295908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 14305908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 143155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 143255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 143355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 143440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 143540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 143640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 143740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor unsigned NumArgs); 143840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1439df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1440df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1441df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1442df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor unsigned NumArgs); 1443df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 144440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 144540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 144640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 144740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 144840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 14497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 14507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 145155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 145240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 145340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *getArgs() const { 145440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 145540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 145640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 145740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 145855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 145955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 146055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 146155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 146240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 146355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 146455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 146555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 146655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 146740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Profile(ID, Template, getArgs(), NumArgs); 146855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 146955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 147140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *Args, unsigned NumArgs); 147255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 147355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor static bool classof(const Type *T) { 14747532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return T->getTypeClass() == TemplateSpecialization; 147555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 14767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 147755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 147855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1479e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1480e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1481e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1482e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1483119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1484119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1485119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1486e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1487ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1488ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1489e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1490e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1491e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1492e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1493ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1494ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1495ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1496ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1497e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1498e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1499e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1500e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1501ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1502ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1503e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1504e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1505e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1506e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1507e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 1508e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1509e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1510ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1511e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1512e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1513ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1514ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 1515ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 1516ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 1517ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 1518e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1519e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const Type *T) { 1520e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return T->getTypeClass() == QualifiedName; 1521e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1522e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1523e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 1524e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1525d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 1526d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 1527d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 1528d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 1529d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 1530d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 1531d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 1532d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 1533d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 1534d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 1535d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 1536d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 1537d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 1538d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1539d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 1540d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 15411734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor typedef llvm::PointerUnion<const IdentifierInfo *, 15421734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 15431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1544d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 15451734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 1546d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1547d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1548d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 1549d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1550d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && 1551d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 1552d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1553d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 15541734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 15551734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 15561734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 15571734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && 15581734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 15591734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 15601734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1561d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 1562d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1563d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 1564d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 1565d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1566d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 15671734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 15681734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 15691734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 15701734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 15711734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 15721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 15731734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const IdentifierInfo *getIdentifier() const { 15741734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const IdentifierInfo *>(); 15751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 15761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 15771734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 15781734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 15791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 15801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 15811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 1582d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1583d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor virtual void getAsStringInternal(std::string &InnerString) const; 1584d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1585d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1586d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 1587d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1588d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1589d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 15901734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 1591d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 15921734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 1593d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1594d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1595d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const Type *T) { 1596d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return T->getTypeClass() == Typename; 1597d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1598d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 1599d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 1600d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1601fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1602fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 1603fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1604fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 1605fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1606fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1607a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 1608a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 160906cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 1610a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1611898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 16123536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 16133536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 16143536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1615a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 16163536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1617fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1618fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// list of protocols qualifying this interface. If this is an instance of 1619fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1620fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// empty list if there are no qualifying protocols. 1621fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1622fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_begin() const; 1623fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_end() const; 1624fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1625fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1626fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1627fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// interface type, or 0 if there are none. 1628fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline unsigned getNumProtocols() const; 1629fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 16309baefc21bfe1bf49ab4a234e9f267f00abe0b1b1Chris Lattner /// getProtocol - Return the specified qualifying protocol. 16319baefc21bfe1bf49ab4a234e9f267f00abe0b1b1Chris Lattner inline ObjCProtocolDecl *getProtocol(unsigned i) const; 16324b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1633fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1634fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner virtual void getAsStringInternal(std::string &InnerString) const; 16353536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 1636368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return T->getTypeClass() == ObjCInterface || 1637368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner T->getTypeClass() == ObjCQualifiedInterface; 16383536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 1639a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 16403536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 16413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1642a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1643372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1644372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1645878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1646878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 1647a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 164806cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 164906cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1650e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1651e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1652fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1653e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1654a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1655065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 1656a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 165700bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 16584b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1659e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1660e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 16619baefc21bfe1bf49ab4a234e9f267f00abe0b1b1Chris Lattner ObjCProtocolDecl *getProtocol(unsigned i) const { 16624b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols[i]; 16634b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 16644b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 16654b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 16664b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1667065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1668065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1669065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1670065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 16714b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 16724b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 16734b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 16744b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 16751ee0700c7dbe3554df09b4558e0b35a53d487ff2Chris Lattner const ObjCInterfaceDecl *Decl, 1676a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 16774b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1678e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1679a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1680e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1681a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1682e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1683fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1684fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1685fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1686fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1687fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_begin(); 1688fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1689fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1690fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1691fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1692fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1693fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_end(); 1694fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1695fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1696fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1697fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1698fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// interface type, or 0 if there are none. 1699fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1700fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1701fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1702fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->getNumProtocols(); 1703fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1704fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1705fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 17069baefc21bfe1bf49ab4a234e9f267f00abe0b1b1Chris Lattner/// getProtocol - Return the specified qualifying protocol. 17079baefc21bfe1bf49ab4a234e9f267f00abe0b1b1Chris Lattnerinline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 17089baefc21bfe1bf49ab4a234e9f267f00abe0b1b1Chris Lattner return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1709fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1710fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1711fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1712c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1713372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// ObjCQualifiedIdType - to represent id<protocol-list>. 1714372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1715372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// Duplicate protocols are removed and protocol list is canonicalized to be in 1716372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// alphabetical order. 1717a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedIdType : public Type, 1718c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian public llvm::FoldingSetNode { 1719c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List of protocols for this protocol conforming 'id' type 1720c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1721a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1722c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 172362f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1724898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 17254b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false), 1726c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian Protocols(Protos, Protos+NumP) { } 1727c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1728c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianpublic: 1729c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1730a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl *getProtocols(unsigned i) const { 1731c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols[i]; 1732c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1733c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian unsigned getNumProtocols() const { 1734c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols.size(); 1735c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1736a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **getReferencedProtocols() { 1737411f373abf5692a1bd90d35a139d955fa67ae82dFariborz Jahanian return &Protocols[0]; 1738065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner } 1739065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1740065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1741065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1742065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1743c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1744c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian virtual void getAsStringInternal(std::string &InnerString) const; 1745c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1746c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 174762f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, 1748a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 1749c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1750c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian static bool classof(const Type *T) { 1751a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedId; 1752c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1753a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedIdType *) { return true; } 1754c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1755c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian}; 1756e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1757611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 17585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1759ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 1760ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 1761f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 1762f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1763f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 1764f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 1765ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1766ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1767ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 1768ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 17694243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 17704243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1771c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 17724243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 17738e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 1774f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1775f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 1776ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 1777ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1778611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1779d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 1780d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1781d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1782d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1783d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 1784d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1785d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 17864ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian if (const PointerType *PT = CT->getAsPointerType()) 17874ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 1788bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 1789d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1790d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1791e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 1792e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 1793e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 1794e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 1795e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 1796e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 1797e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1798e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1799ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1800ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1801e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1802e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1803e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1804e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1805e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 1806e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 1807e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 1808e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1809e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1810e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1811ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1812ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1813e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 1814e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1815e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1816e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 1817e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 1818e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 1819e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 1820e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 1821e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 1822e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 1823e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 1824e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 1825e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 1826e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1827e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 1828e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 1829e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 1830e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1831e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1832769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 1833769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 1834769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 18352b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 18362b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner if (const PointerType *PT = getAsPointerType()) 18372b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 18382b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 18392b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 18402b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 1841c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1842c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 1843611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 1844ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1845611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1846611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 1847ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1848611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 18495618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 185075b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 18515618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 1852bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 1853bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1854bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 18557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 18567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 18577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 18587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 18597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 18607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 1861498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 186201c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 1863498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 1864498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 1865498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 1866498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 1867f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 1868f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1869f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1870f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 1871f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (const MemberPointerType* T = getAsMemberPointerType()) 1872f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 1873f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 1874f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 1875f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1876611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 1877ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1878611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1879c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 1880c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1881c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1882c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 1883c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1884c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1885c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 1886c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1887c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1888898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 1889898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1890898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1891611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 1892ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1893611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1894f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 1895c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1896f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 1897611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 1898ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1899611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1900213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 1901213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1902611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1903a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 1904c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1905368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 1906368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 1907c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1908e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 1909a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 1910c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1911d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 191272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 191372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 191472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 191572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1916e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 1917904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 1918e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 1919e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 1920e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 1921e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 1922e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 1923063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 1924063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 1925063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 1926063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 1927904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 1928904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 19298958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 19308958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 19318958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar isObjCInterfaceType() || isObjCQualifiedIdType() || 19326e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 19338958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 19348958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 1935820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 1936820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian return (isObjCInterfaceType() || isObjCQualifiedIdType() || 1937820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 1938820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 1939820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 194022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 194122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 194222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 194322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 194422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 194522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 194622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 194722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 194822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 19495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 19505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1952