Type.h revision 131f4658249b2a7d2d7e30fe07e84c484f79ef99
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; 69d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor class PrintingPolicy; 7072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 7172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 7272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 7372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 74f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 865cf243a883872441d73ca49cea7e20de5802629bChris Lattner llvm::PointerIntPair<Type*, 3> Value; 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian enum GCAttrTypes { 96d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 97d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 98d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 99d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 100d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1015cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1035cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 1045cf243a883872441d73ca49cea7e20de5802629bChris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065cf243a883872441d73ca49cea7e20de5802629bChris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 107a3ab4b85f54090927c2dfa2585b9f0e48509e944Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 1085cf243a883872441d73ca49cea7e20de5802629bChris Lattner Type *getTypePtr() const { return Value.getPointer(); } 1095cf243a883872441d73ca49cea7e20de5802629bChris Lattner 1105cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 1135cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1275cf243a883872441d73ca49cea7e20de5802629bChris Lattner return getTypePtr() == 0; 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 1315cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Const) ? true : false; 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 1345cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 1375cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 139b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 140b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1417effa1aceac1219529af23c776835f855b8d905cChris Lattner 1427effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1437effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1445cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 1455cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1465cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1485cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1495cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1505cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 1511c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 155c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 156c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 157c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 158971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 159971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 160971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 161971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 163e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getUnqualifiedType() const; 164e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 165e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 166e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1682fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 1692fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 1702fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 1712fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1722fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1732fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 174969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 17598cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1795cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value == RHS.Value; 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1825cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value != RHS.Value; 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 184d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 185d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 186d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 188d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 191d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const; 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 193c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 194c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 1953f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek 1963f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 1973f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 1983f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 200368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 202ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 203ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 204ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 205d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 206d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 207f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 208f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 209f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 210f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 211f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 214f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 215f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 216f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 23273af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2334e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 235daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2364e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2394e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2404e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 24311a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2440eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 24673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 26172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 26472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 27872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 27972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 28072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 28172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 283d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 287898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 293ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned TC : 5; 294898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 29516ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 29616ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 298124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 299124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 300898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 301f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 303898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3044b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 30673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 3078b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 308a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 316bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 317bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 318bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 319bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 320bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 328d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 329d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 330d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 331d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 332d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 333d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 33464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 33564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 33664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 33764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 338d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 339d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 340d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 341d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 343ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 344e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 345e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 346e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 34796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 34896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 34996d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 35113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 35213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 35313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 35477a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 35533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 35902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 36002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 362f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 366c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 367c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 368c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 369d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 371c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 372ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 373c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 37426d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 37526d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 376befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 3775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 378a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 381bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 382f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 383f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 384c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 385c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 386c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 387c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 388898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 389c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 39099dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner bool isClassType() const; 391c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3924cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 393368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 394368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 395213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 396d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 397368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 398368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 399368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 40072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 4016e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 402898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 403898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 404898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// that its definition somehow depends on a template parameter 405898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 406898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 407063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 40872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4098958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4108958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4118958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4126e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4138958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4148958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 415820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 416820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 417820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian bool hasObjCPointerRepresentation() const; 418820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 419c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 420f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 421f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 422f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 423f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 42472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 42572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 426befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 4275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 428a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 4297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const LValueReferenceType *getAsLValueReferenceType() const; 4307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const RValueReferenceType *getAsRValueReferenceType() const; 431f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const MemberPointerType *getAsMemberPointerType() const; 432fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor const TagType *getAsTagType() const; 433c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 434769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 435898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 436769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 437c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 438ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 439c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 440c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4414cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 442213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 443d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 444368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 445368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 446d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 44772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 44872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 45155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 4522b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4532b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4542b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4552b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 456c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 457c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 458c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 459c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 460c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 461dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 462769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 463dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 464dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4653830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 466dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 467969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 468dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 473d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 474d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 475d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 479d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 480d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 481d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 483d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 4859bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4869bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 4873c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 488c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 48922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 49022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 49122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 49222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 494c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 495d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const = 0; 4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 499f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 500f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 501f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 502f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 503ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 504f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 505f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 506f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 507f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 508f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 50959d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 510ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 511ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 51259d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 513d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 51459d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 51559d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 516d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 517b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 518b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 519b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 520b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 521b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 522ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 523ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 524f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 525d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5264886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 527ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 528d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 529ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 530ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5314886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 532ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 533f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 534d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 535f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 536ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5374886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 538ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 539ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 540f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 541f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 542ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 543ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 544ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 5592df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 5632ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 5682df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5708e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 5718e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 5726e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 5736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 574898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 575898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent // This represents the type of a type-dependent expression. 5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 580898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor BuiltinType(Kind K) 581898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 582898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 585d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const char *getName(bool CPlusPlus) const; 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 587d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 593f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 594f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 595f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 596f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 597f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 598f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 599f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 600f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 601f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 602f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 603f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 604f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 605f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 606f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 607f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 608d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 609f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 610f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 611f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 612f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 613f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 620898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 621898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 627d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 62803ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 64068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 641bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 64268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 643bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 64668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 651d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 65368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 65468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 6675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 6685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 6705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6725618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 673898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 674898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 6755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 6775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 6785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 682d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 6855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 6865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 6895618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6905618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const Type *T) { 6925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return T->getTypeClass() == BlockPointer; 6935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 6955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 6965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 6985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 69968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 70068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 70168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 7037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 7047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 70568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 70868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 70968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 711bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 7125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 7197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 7207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 7227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 7257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 7277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 7297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 732d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 7367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 7387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 7417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 7437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 7457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 748d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 7527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 754f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 755f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 756f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 757f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 758f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 759f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 760f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 761f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 762f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 763f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 764f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 765f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 766f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 767f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 768f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 769f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 770f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 771f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 772f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 773f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 774f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 775f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 776d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 777f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 778f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 779f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 780f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 781f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 782f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 783f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 784f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 785f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 786f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 787f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 788f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 789f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 790f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7952e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 798898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 799898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 800898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 8025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 8035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 805fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 806fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 807c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 808ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 809c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 810ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 811c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 812c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 813c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 814c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 815c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 816fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 817898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 818898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 819898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 820898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 821898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 822c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 823c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 824898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 825898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 826898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 827fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 828fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 829fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 830ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 831ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 832ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 833c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 834fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 835fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 836fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 837c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 838898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 839898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 840fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 841fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 842fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 843fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 844da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant 845da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[100]' has ConstantArrayType where the element type 846da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// is 'int' and the size is 100. 8472e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 848fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 849fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 8500be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 851c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 8520be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 853fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 854fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 855c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 856d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 857fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 858fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8590be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSize(), 8600be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 861fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 862fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8630be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 8640be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 865fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 866fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 8670be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8680be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 869fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 870fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 871fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray; 872fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 873fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 874fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 875fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 876da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 877da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 878da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 879c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 880c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 881c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArraySizeModifier sm, unsigned tq) 882c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 883c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 884c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 885c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 886d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 887c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 888c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 889c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 890c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 891c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 892c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 893c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 894c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 895c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 8960be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 897c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 898c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 8990be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 9000be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 901c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 9020be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 9030be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 904c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 905c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 906c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 907da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 908da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 909da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 910da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 911da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 912da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 913da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 914da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 915da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 916da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 917da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 918da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 919da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 920da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 921da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 9222e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 923fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 924fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 925b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 927c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 928c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 929b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9314b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 9324b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 934c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Expr *getSizeExpr() const { 935b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 936b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 937b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 938b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 940d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 942fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 943fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 945fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 946a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 94792866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 9482bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 9492bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 950bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 9512bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 954898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 956898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 957898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// template<typename T, int Size> 958898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 959898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 960898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 961898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 962898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 963898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 964898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 965898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 966898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 967898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 968898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 969898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 970898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 971898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArraySizeModifier sm, unsigned tq) 972898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 973898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 974898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 975898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 976898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 977898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr *getSizeExpr() const { 978898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 979898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 980898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 981898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 982898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 983d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 984898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 985898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const Type *T) { 986898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return T->getTypeClass() == DependentSizedArray; 987898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 988898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 989898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 990898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 991898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 992898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 993bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 994898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 995898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 996898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 997f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 9989cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 9999cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 10009cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 10019cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 10029cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 10039cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 10049cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 10059cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorclass DependentSizedExtVectorType : public Type { 10069cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 10079cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 10089cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 10099cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 10109cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10119cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor DependentSizedExtVectorType(QualType ElementType, QualType can, 10129cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr, SourceLocation loc) 10139cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor : Type (DependentSizedExtVector, can, true), 10149cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {} 10159cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 10169cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 10179cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10189cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 1019f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor const Expr *getSizeExpr() const { return SizeExpr; } 10209cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 10219cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 10229cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10239cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 10249cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const Type *T) { 10269cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return T->getTypeClass() == DependentSizedExtVector; 10279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 10289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const DependentSizedExtVectorType *) { return true; } 10299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 10309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 103273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 103373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 103473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 103573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 103773322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 10385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 104473322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1045898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Vector, canonType, vecType->isDependentType()), 1046898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(vecType), NumElements(nElements) {} 104773322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1048353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman QualType canonType) 1049898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1050898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumElements(nElements) {} 10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1057d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 106073322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 10615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 106273322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 106373322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 106673322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 106773322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 106873322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 1069213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1074213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1075213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1076213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1077fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1078fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1079213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1080213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1081213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 108273322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 108373322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 108488dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 108588dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 108688dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 108788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 108888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 108988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 109088dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 109188dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1092e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1093353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 109488dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1095353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1096353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1097353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1098353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1099353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1100353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1101353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1102353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1103353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1104353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1105353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1106131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1107353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1108131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1109353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1110131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1111353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1112131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1113353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1114131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1115353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1116131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1117353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 111888dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1119e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1120b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 1121b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1122b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1123353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1124b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 1125b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 112688dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1127b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 112888dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 112988dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1130e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1131d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 113231a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 11337064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 1134213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == ExtVector; 113573322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1136213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 113773322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 113873322924127c873c13101b705dd823f5539ffa5fSteve Naroff 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 114072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1146971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 114772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1148971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 114972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1150971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1151971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1152971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1153971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1154971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1159971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1160898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 1161898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 1162971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1164971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 117772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 117972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 118072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType(QualType Result, QualType Canonical) 1181898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 11824b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false) {} 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 11865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1187d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 11915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 119972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 12005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 120272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1204465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1205465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1206465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 120772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1208898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1209898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1210898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1211898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1212898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 12134b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1214898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1215898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1216898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1217898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 121872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1219465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1220465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 1221465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned numExs, QualType Canonical) 1222898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 12234b4218f48fef71a179c5a8287dae281580faf52fNate Begeman (Result->isDependentType() || 12244b4218f48fef71a179c5a8287dae281580faf52fNate Begeman hasAnyDependentType(ArgArray, numArgs))), 1225465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1226465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1227942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1228465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1231465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1232465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1233465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1234465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1236465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1238465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1239465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1240465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1241465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1242465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1243465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1244465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1245465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1246465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1247465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1248465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1249942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1250942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1251465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1252465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1253465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1254465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12564b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1261942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1263465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1264465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1265465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1266465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1267465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1268465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1269465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1270465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1271d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson bool hasEmptyExceptionSpec() const { 1272a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson return hasExceptionSpec() && !hasAnyExceptionSpec() && 1273a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1274d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1275465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1277971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1280942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1281942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1282942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1283942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1284465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1285465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1286465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1287465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1288465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1289465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1290465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1291465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1292465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1293465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1294d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 129972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1300465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1303942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1304465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1305465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 1306465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions, exception_iterator Exs); 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1312c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 1313c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1314898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 13185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 1321a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 1322a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1323fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1324a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1325a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1326a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1327a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1328a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1330d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 133272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 13345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 133672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 133772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1338d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 133972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TypeOfExprType(Expr *E, QualType can); 1340d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1341d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1342d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 1343d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1344d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1345d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 134672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 134772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1348d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1349d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1350d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1351d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1352d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 1353898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeOfType(QualType T, QualType can) 135472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1355d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1356d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1357d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1358d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1359d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 1360d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1361d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1362d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 136372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1364d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1365d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1367395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 1368395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 1369395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 1370395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson DecltypeType(Expr *E, QualType can); 1371395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 1372395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 1373395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 1374395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1375395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson virtual void getAsStringInternal(std::string &InnerString, 1376395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson const PrintingPolicy &Policy) const; 1377395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1378395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1379395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 1380395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 1381395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 13830b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 13840b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 13850b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 13860b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 13870b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1388fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 13894b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 13900b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 13912ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 13922ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 13937da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 13942ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 13952ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorpublic: 13960b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13980b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 13990b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// defined. 14000b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 14010b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 14020b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 1403d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1404e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 140572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { 140672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 140772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 140972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 141072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14135edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 14145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 14155edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 141649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1417509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 141872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 141972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 142072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 14212ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 14225edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 14235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 14255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 14265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 14275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 14295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 14305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 14315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 14325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 14345edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 14355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 14365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14372daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 14382daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 14392daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 14402daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 14415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 14425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 14435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 14455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 14465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1447509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 144872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 14492ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 14505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 14515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14525edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 14535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 14545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 14555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14562daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 14572daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 14582daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 14592daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 14605edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 14615edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 14625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1463fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 146476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 1465fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 146676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 1467fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 146872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 146976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 1470fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor QualType Canon) 1471fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 147276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 147372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 147476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1475fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 147676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 147772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1478fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 147972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1480fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1481fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1482fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 148376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 1484fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 1485fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1486d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 14875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1488fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 148976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 1490fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1491fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1492fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 149376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Index, bool ParameterPack, 149476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 1495fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1496fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 149776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 1498fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1499fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1500fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 150172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const Type *T) { 150272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return T->getTypeClass() == TemplateTypeParm; 150372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 150472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 150572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1506fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 15077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 15087532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 150955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 15107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 15117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 15127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 15137532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 15147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 151555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 15167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// a tag type for the instantiation 151755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 15187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 15197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 15207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 15217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 15227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorclass TemplateSpecializationType 152355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 152455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief The name of the template being specialized. 15267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 152755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 152840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 152940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 153055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 153155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateSpecializationType(TemplateName T, 15337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 15347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 153555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15365908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 15375908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 153855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 153955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 154055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 154140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 154240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 154340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 154440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor unsigned NumArgs); 154540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1546df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1547df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1548df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1549d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 1550d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 1551df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 155240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 155340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 155440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 155540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 155640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 15577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 15587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 155955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 156040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 156140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *getArgs() const { 156240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 156340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 156440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 156540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 156655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 156755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 156855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 156955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 157040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 157155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1572d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 157355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 157455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 157540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Profile(ID, Template, getArgs(), NumArgs); 157655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 157755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 157940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *Args, unsigned NumArgs); 158055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 158155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor static bool classof(const Type *T) { 15827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return T->getTypeClass() == TemplateSpecialization; 158355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 15847532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 158555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 158655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1587e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1588e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1589e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1590e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1591119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1592119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1593119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1594e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1595ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1596ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1597e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1598e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1599e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1600e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1601ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1602ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1603ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1604ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1605e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1606e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1607e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1608e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1609ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1610ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1611e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1612e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1613e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1614e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1615d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1616e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1617e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1618ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1619e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1620e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1621ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1622ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 1623ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 1624ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 1625ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 1626e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1627e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const Type *T) { 1628e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return T->getTypeClass() == QualifiedName; 1629e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1630e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1631e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 1632e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1633d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 1634d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 1635d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 1636d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 1637d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 1638d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 1639d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 1640d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 1641d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 1642d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 1643d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 1644d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 1645d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 1646d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1647d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 1648d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16491734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor typedef llvm::PointerUnion<const IdentifierInfo *, 16501734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 16511734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1652d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 16531734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 1654d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1655d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1656d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 1657d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1658d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && 1659d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 1660d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1661d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16621734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 16631734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 16641734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 16651734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && 16661734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 16671734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 16681734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1669d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 1670d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1671d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 1672d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 1673d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1674d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 16761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 16771734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 16781734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 16791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 16801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 16811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const IdentifierInfo *getIdentifier() const { 16821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const IdentifierInfo *>(); 16831734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 16841734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 16851734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 16861734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 16871734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 16881734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 16891734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 1690d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1691d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1692d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1693d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1694d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 1695d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1696d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1697d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 16981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 1699d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 17001734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 1701d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1702d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1703d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const Type *T) { 1704d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return T->getTypeClass() == Typename; 1705d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1706d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 1707d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 1708d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1709d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 1710d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// and 'Interface <p> *'. 1711d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// 1712d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 1713d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// alphabetical order. 1714d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 1715d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCInterfaceDecl *Decl; 1716d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // List of protocols for this protocol conforming object type 1717d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // List is sorted on protocol name. No protocol is entered more than once. 1718d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1719d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1720d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerType(ObjCInterfaceDecl *D, 1721d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCProtocolDecl **Protos, unsigned NumP) : 1722d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 1723d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff Decl(D), Protocols(Protos, Protos+NumP) { } 1724d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff friend class ASTContext; // ASTContext creates these. 1725d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1726d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffpublic: 1727d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCInterfaceDecl *getDecl() const { return Decl; } 1728d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1729d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// isObjCQualifiedIdType - true for "id <p>". 1730d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCQualifiedIdType() const { return Decl == 0 && Protocols.size(); } 1731d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1732d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 1733d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// list of protocols qualifying this interface. 1734d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1735d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1736d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 1737d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff qual_iterator qual_end() const { return Protocols.end(); } 1738d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool qual_empty() const { return Protocols.size() == 0; } 1739d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1740d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 1741d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// interface type, or 0 if there are none. 1742d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 1743d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1744d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 1745d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, 1746d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCInterfaceDecl *Decl, 1747d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 1748d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1749d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const PrintingPolicy &Policy) const; 1750d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff static bool classof(const Type *T) { 1751d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return T->getTypeClass() == ObjCObjectPointer; 1752d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 1753d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 1754d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}; 1755d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1756fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1757fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 1758fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1759fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 1760fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1761fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1762a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 1763a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 176406cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 1765a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1766898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 17673536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 17683536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 17693536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1770a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 17713536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1772fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1773fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// list of protocols qualifying this interface. If this is an instance of 1774fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1775fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// empty list if there are no qualifying protocols. 1776fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1777fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_begin() const; 1778fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_end() const; 1779fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1780fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1781fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1782fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// interface type, or 0 if there are none. 1783fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline unsigned getNumProtocols() const; 1784fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1785d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 17863536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 1787368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return T->getTypeClass() == ObjCInterface || 1788368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner T->getTypeClass() == ObjCQualifiedInterface; 17893536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 1790a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 17913536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 17923536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1793a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1794372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1795372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1796878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1797878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 1798a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 179906cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 180006cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1801e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1802e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1803fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1804e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1805a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1806065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 1807a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 180800bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 18094b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1810e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1811e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 18124b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 18134b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 18144b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1815065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1816065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1817065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1818065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1819d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 18204b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 18214b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 18224b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 18231ee0700c7dbe3554df09b4558e0b35a53d487ff2Chris Lattner const ObjCInterfaceDecl *Decl, 1824a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 18254b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1826e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1827a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1828e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1829a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1830e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1831fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1832fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1833fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1834fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1835fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_begin(); 1836fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1837fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1838fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1839fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1840fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1841fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_end(); 1842fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1843fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1844fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1845fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1846fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// interface type, or 0 if there are none. 1847fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1848fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1849fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1850fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->getNumProtocols(); 1851fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1852fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1853fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1854611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 18555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1856ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 1857ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 1858f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 1859f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1860f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 1861f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 1862ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1863ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1864ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 1865ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 18664243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 18674243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1868c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 18694243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 18708e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 1871f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1872f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 1873ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 1874ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1875611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1876d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 1877d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1878d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1879d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1880d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 1881d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1882d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 18834ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian if (const PointerType *PT = CT->getAsPointerType()) 18844ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 1885bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 1886d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1887d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1888e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 1889e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 1890e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 1891e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 1892e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 1893e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 1894e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1895e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1896ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1897ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1898e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1899e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1900e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1901e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1902e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 1903e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 1904e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 1905e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1906e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1907e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1908ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1909ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1910e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 1911e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1912e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1913e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 1914e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 1915e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 1916e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 1917e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 1918e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 1919e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 1920e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 1921e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 1922e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 1923e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1924e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 1925e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 1926e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 1927e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1928e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1929769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 1930769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 1931769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 19322b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 19332b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner if (const PointerType *PT = getAsPointerType()) 19342b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 19352b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 19362b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 19372b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 1938c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1939c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 1940611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 1941ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1942611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1943611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 1944ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1945611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 19465618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 194775b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 19485618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 1949bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 1950bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1951bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 19527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 19537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 19547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 19557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 19567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 19577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 1958498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 195901c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 1960498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 1961498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 1962498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 1963498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 1964f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 1965f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1966f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1967f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 1968f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (const MemberPointerType* T = getAsMemberPointerType()) 1969f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 1970f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 1971f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 1972f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1973611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 1974ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1975611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1976c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 1977c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1978c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1979c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 1980c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1981c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1982c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 1983c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1984c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1985898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 1986898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1987898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1988611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 1989ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1990611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1991f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 1992c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1993f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 1994611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 1995ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1996611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1997213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 1998213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1999611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2000d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 2001d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2002d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 2003a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 2004c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2005368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 2006368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 2007c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 2008e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 2009a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 2010d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { 2011d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 2012d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 2013d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 2014d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 201572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 201672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 201772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 201872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2019e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 2020904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 2021e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 2022e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 2023e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 2024e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 2025e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 2026063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 2027063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 2028063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 2029063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 2030904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 2031904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 20328958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 20338958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 20348958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar isObjCInterfaceType() || isObjCQualifiedIdType() || 20356e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 20368958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 20378958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 2038820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 2039820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian return (isObjCInterfaceType() || isObjCQualifiedIdType() || 2040820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 2041820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 2042820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 204322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 204422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 204522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 204622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 204722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 204822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 204922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 205022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 205122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 20535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2055