Type.h revision e4f2142d00fa5fdb580c4e2413da91882d955381
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 } 191e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 192e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 194c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 195c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 1963f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek 1973f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 1983f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 1993f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 201368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 203ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 204ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 205ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 206d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 207d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 208f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 209f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 210f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 211f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 214f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 215f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 216f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 217f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 23373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 236daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2394e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2404e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2434e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 24411a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2450eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 24773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 26272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 26572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 27972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 28072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 28172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 28272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 284d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 290898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 294ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned TC : 5; 295898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 29616ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 29716ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 299124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 300124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 301898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 302f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 303898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 304898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3054b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 30773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 3088b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 309a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 316bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 317bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 318bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 319bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 320bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 321bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 329d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 330d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 331d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 332d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 333d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 334d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 33564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 33664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 33764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 33864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 339d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 340d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 341d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 342d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 344ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 345e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 346e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 347e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 34896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 34996d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 35096d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 35213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 35313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 35413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 35577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 35633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 36002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 36102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 363f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 367c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 368c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 369c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 370d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 372c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 373ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 374c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 37526d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 37626d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 377befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 3785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 379a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 382bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 383f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 384f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 385c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 386c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 387c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 388c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 389898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 390c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 39199dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner bool isClassType() const; 392c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3934cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 394368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 395368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 396213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 397d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 398368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 399368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 400368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 40172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 4026e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 403898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 404898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 405898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// that its definition somehow depends on a template parameter 406898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 407898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 408063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 40972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4108958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4118958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4128958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4136e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4148958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4158958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 416820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 417820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 418820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian bool hasObjCPointerRepresentation() const; 419820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 420c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 421f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 422f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 423f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 424f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 42572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 42672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 427befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 4285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 429a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 4307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const LValueReferenceType *getAsLValueReferenceType() const; 4317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const RValueReferenceType *getAsRValueReferenceType() const; 432f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const MemberPointerType *getAsMemberPointerType() const; 433fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor const TagType *getAsTagType() const; 434c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 435769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 436898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 437769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 438c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 439ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 440c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 441c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4424cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 443213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 444d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 445368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 446368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 447d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 44872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 44972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 45255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 4532b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4542b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4552b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4562b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 457c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 458c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 459c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 460c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 461c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 462dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 463769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 464dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 465dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4663830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 467dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 468969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 469dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 474d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 475d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 476d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 480d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 481d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 482d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 484d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 4869bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4879bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 4883c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 489c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 49022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 49122b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 49222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 49322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 495c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 496d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const = 0; 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 500f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 501f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 502f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 503f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 504ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 505f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 506f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 507f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 508f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 509f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 51059d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 511ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 512ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 51359d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 514d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 51559d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 51659d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 517d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 518b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 519b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 520b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 521b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 522b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 523ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 524ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 525f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 526d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5274886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 528ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 529d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 530ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 531ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5324886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 533ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 534f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 535d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 536f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 537ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5384886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 539ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 540ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 541f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 542f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 543ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 544ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 545ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 5602df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 5642ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 5692df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5718e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 5728e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 5736e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 5746e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 575898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 576e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson Dependent, // This represents the type of a type-dependent expression. 577e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson 578e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson UndeducedAuto // In C++0x, this represents the type of an auto variable 579e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 584898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor BuiltinType(Kind K) 585898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 586898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 5875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 589e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 591d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 597f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 598f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 599f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 600f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 601f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 602f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 603f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 604f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 605f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 606f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 607f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 608f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 609f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 610f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 611f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 612d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 613f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 614f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 615f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 616f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 617f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 6225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 624898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 625898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 631d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 63203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 64468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 645bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 64668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 647bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 65068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 655d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 65768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 65868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 6715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 6725618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 6745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 677898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 678898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 6795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 6815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 6825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 686d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 6895618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 6905618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 6935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const Type *T) { 6965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return T->getTypeClass() == BlockPointer; 6975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 6995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 7005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 7017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 7025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 70368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 70468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 70568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 7077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 7087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 70968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 71268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 71368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 715bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 7237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 7247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 7267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 7297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 7317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 7337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 736d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 7407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 7427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 7457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 7477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 7497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 752d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 7567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 758f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 759f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 760f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 761f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 762f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 763f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 764f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 765f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 766f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 767f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 768f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 769f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 770f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 771f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 772f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 773f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 774f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 775f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 776f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 777f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 778f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 779f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 780d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 781f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 782f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 783f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 784f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 785f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 786f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 787f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 788f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 789f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 790f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 791f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 792f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 793f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 794f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7992e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 8005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 802898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 803898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 804898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 8055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 8065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 809fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 810fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 811c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 812ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 813c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 814ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 815c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 816c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 817c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 818c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 819c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 820fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 821898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 822898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 823898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 824898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 825898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 826c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 827c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 828898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 829898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 830898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 831fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 832fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 833fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 834ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 835ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 836ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 837c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 838fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 839fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 840fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 841c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 842898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 843898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 844fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 845fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 846fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 847fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 848da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant 849da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[100]' has ConstantArrayType where the element type 850da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// is 'int' and the size is 100. 8512e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 852fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 853fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 8540be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 855c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 8560be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 857fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 858fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 859c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 860d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 861fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 862fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8630be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSize(), 8640be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 865fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 866fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8670be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 8680be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 869fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 870fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 8710be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8720be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 873fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 874fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 875fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray; 876fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 877fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 878fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 879fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 880da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 881da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 882da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 883c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 884c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 885c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArraySizeModifier sm, unsigned tq) 886c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 887c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 888c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 889c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 890d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 891c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 892c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 893c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 894c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 895c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 896c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 897c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 898c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 899c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 9000be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 901c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 902c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 9030be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 9040be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 905c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 9060be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 9070be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 908c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 909c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 910c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 911da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 912da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 913da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 914da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 915da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 916da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 917da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 918da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 919da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 920da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 921da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 922da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 923da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 924da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 925da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 9262e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 927fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 928fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 929b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 931c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 932c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 933b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9354b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 9364b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 938c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Expr *getSizeExpr() const { 939b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 940b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 941b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 942b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 944d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 946fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 947fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 949fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 950a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 95192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 9522bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 9532bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 954bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 9552bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 958898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 959898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 960898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 961898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// template<typename T, int Size> 962898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 963898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 964898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 965898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 966898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 967898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 968898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 969898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 970898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 971898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 972898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 973898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 974898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 975898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArraySizeModifier sm, unsigned tq) 976898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 977898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 978898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 979898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 980898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 981898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr *getSizeExpr() const { 982898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 983898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 984898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 985898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 986898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 987d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 988898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 989898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const Type *T) { 990898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return T->getTypeClass() == DependentSizedArray; 991898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 992898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 993898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 994898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 995898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 996898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 997bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 998898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 999898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1000898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1001f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 10029cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 10039cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 10049cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 10059cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 10069cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 10079cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 10089cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 10099cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorclass DependentSizedExtVectorType : public Type { 10109cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 10119cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 10129cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 10139cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 10149cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10159cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor DependentSizedExtVectorType(QualType ElementType, QualType can, 10169cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr, SourceLocation loc) 10179cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor : Type (DependentSizedExtVector, can, true), 10189cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {} 10199cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 10209cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 10219cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10229cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 1023f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor const Expr *getSizeExpr() const { return SizeExpr; } 10249cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 10259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 10269cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 10289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const Type *T) { 10309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return T->getTypeClass() == DependentSizedExtVector; 10319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 10329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const DependentSizedExtVectorType *) { return true; } 10339cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 10349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 10359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 103673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 103773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 103873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 103973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 10405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 104173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 10425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 10435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 10465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 10475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 104873322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1049898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Vector, canonType, vecType->isDependentType()), 1050898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(vecType), NumElements(nElements) {} 105173322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1052353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman QualType canonType) 1053898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1054898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumElements(nElements) {} 10555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 10605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1061d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 10625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 106473322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 10655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 106673322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 106773322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 107073322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 107173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 107273322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 1073213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 10745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 10765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1078213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1079213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1080213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1081fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1082fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1083213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1084213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1085213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 108673322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 108773322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 108888dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 108988dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 109088dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 109188dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 109288dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 109388dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 109488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 109588dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1096e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1097353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 109888dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1099353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1100353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1101353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1102353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1103353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1104353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1105353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1106353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1107353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1108353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1109353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1110131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1111353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1112131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1113353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1114131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1115353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1116131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1117353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1118131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1119353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1120131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1121353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 112288dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1123e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1124b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 1125b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1126b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1127353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1128b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 1129b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 113088dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1131b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 113288dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 113388dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1134e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1135d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 113631a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 11377064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 1138213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == ExtVector; 113973322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1140213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 114173322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 114273322924127c873c13101b705dd823f5539ffa5fSteve Naroff 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 114472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1150971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 115172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1152971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 115372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1154971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1155971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1156971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1157971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1158971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1163971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 1165898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 1166971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1168971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 118172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 118372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 118472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType(QualType Result, QualType Canonical) 1185898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 11864b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false) {} 11875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1191d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 11985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 12015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 120372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 120672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 12075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1208465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1209465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1210465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 121172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1212898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1213898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1214898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1215898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1216898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 12174b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1218898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1219898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1220898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1221898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 122272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1223465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1224465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 1225465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned numExs, QualType Canonical) 1226898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 12274b4218f48fef71a179c5a8287dae281580faf52fNate Begeman (Result->isDependentType() || 12284b4218f48fef71a179c5a8287dae281580faf52fNate Begeman hasAnyDependentType(ArgArray, numArgs))), 1229465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1230465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1231942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1232465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1235465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1236465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1237465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1238465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1240465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1242465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1243465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1244465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1245465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1246465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1247465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1248465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1249465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1250465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1251465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1252465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1253942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1254942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1255465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1256465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1257465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1258465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12604b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 12615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1265942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1267465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1268465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1269465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1270465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1271465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1272465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1273465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1274465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1275d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson bool hasEmptyExceptionSpec() const { 1276a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson return hasExceptionSpec() && !hasAnyExceptionSpec() && 1277a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1278d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1279465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1281971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1284942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1285942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1286942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1287942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1288465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1289465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1290465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1291465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1292465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1293465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1294465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1295465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1296465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1297465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1298d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 130372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1304465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1307942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1308465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1309465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 1310465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions, exception_iterator Exs); 13115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1316c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 1317c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1318898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 1325a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 1326a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1327fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1328a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1329a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1330a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1331a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1332a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1334d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 133672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 134072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 134172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1342d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 134372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TypeOfExprType(Expr *E, QualType can); 1344d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1345d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1346d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 1347d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1348d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1349d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 135072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 135172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1352d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1353d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1354d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1355d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1356d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 1357898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeOfType(QualType T, QualType can) 135872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1359d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1360d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1361d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1362d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1363d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 1364d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1365d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1366d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 136772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1368d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1369d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1371395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 1372395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 1373395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 1374395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson DecltypeType(Expr *E, QualType can); 1375395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 1376395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 1377395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 1378395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1379395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson virtual void getAsStringInternal(std::string &InnerString, 1380395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson const PrintingPolicy &Policy) const; 1381395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1382395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1383395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 1384395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 1385395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 13870b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 13880b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 13890b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 13900b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 13910b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1392fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 13934b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 13940b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 13952ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 13962ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 13977da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 13982ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 13992ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorpublic: 14000b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 14015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14020b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 14030b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// defined. 14040b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 14050b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 14060b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 1407d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1408e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 140972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { 141072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 141172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 141372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 141472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14175edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 14185edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 14195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 142049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1421509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 142272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 142372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 142472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 14252ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 14265edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 14275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 14295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 14305edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 14315edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 14335edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 14345edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 14355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 14365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14375edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 14385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 14395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 14405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14412daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 14422daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 14432daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 14442daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 14455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 14465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 14475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 14495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 14505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1451509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 145272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 14532ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 14545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 14555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 14575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 14585edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 14595edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 14602daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 14612daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 14622daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 14632daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 14645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 14655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 14665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1467fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 146876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 1469fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 147076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 1471fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 147272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 147376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 1474fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor QualType Canon) 1475fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 147676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 147772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 147876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1479fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 148076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 148172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1482fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 148372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1484fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1485fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1486fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 148776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 1488fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 1489fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1490d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 14915edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1492fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 149376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 1494fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1495fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1496fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 149776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Index, bool ParameterPack, 149876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 1499fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1500fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 150176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 1502fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1503fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1504fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 150572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const Type *T) { 150672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return T->getTypeClass() == TemplateTypeParm; 150772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 150872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 150972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1510fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 15117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 15127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 151355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 15147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 15157532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 15167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 15177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 15187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 151955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 15207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// a tag type for the instantiation 152155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 15227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 15237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 15247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 15257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 15267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorclass TemplateSpecializationType 152755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 152855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief The name of the template being specialized. 15307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 153155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 153240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 153340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 153455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 153555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15367532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateSpecializationType(TemplateName T, 15377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 15387532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 153955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15405908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 15415908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 154255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 154355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 154455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 154540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 154640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 154740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 154840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor unsigned NumArgs); 154940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1550df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1551df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1552df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1553d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 1554d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 1555df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 155640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 155740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 155840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 155940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 156040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 15617532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 15627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 156355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 156440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 156540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *getArgs() const { 156640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 156740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 156840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 156940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 157055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 157155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 157255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 157355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 157440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 157555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1576d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 157755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 157855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 157940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Profile(ID, Template, getArgs(), NumArgs); 158055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 158155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 158340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *Args, unsigned NumArgs); 158455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 158555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor static bool classof(const Type *T) { 15867532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return T->getTypeClass() == TemplateSpecialization; 158755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 15887532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 158955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 159055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1591e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1592e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1593e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1594e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1595119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1596119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1597119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1598e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1599ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1600ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1601e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1602e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1603e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1604e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1605ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1606ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1607ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1608ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1609e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1610e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1611e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1612e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1613ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1614ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1615e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1616e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1617e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1618e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1619d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1620e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1621e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1622ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1623e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1624e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1625ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1626ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 1627ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 1628ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 1629ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 1630e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1631e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const Type *T) { 1632e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return T->getTypeClass() == QualifiedName; 1633e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1634e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1635e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 1636e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1637d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 1638d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 1639d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 1640d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 1641d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 1642d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 1643d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 1644d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 1645d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 1646d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 1647d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 1648d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 1649d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 1650d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1651d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 1652d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16531734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor typedef llvm::PointerUnion<const IdentifierInfo *, 16541734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 16551734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1656d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 16571734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 1658d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1659d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1660d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 1661d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1662d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && 1663d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 1664d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1665d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16661734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 16671734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 16681734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 16691734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && 16701734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 16711734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 16721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1673d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 1674d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1675d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 1676d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 1677d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1678d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 16801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 16811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 16821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 16831734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 16841734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 16851734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const IdentifierInfo *getIdentifier() const { 16861734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const IdentifierInfo *>(); 16871734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 16881734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 16891734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 16901734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 16911734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 16921734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 16931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 1694d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1695d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1696d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1697d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1698d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 1699d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1700d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1701d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 17021734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 1703d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 17041734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 1705d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1706d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1707d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const Type *T) { 1708d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return T->getTypeClass() == Typename; 1709d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1710d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 1711d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 1712d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1713d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 1714d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// and 'Interface <p> *'. 1715d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// 1716d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 1717d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// alphabetical order. 1718d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 1719d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCInterfaceDecl *Decl; 1720d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // List of protocols for this protocol conforming object type 1721d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // List is sorted on protocol name. No protocol is entered more than once. 1722d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1723d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1724d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerType(ObjCInterfaceDecl *D, 1725d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCProtocolDecl **Protos, unsigned NumP) : 1726d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 1727d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff Decl(D), Protocols(Protos, Protos+NumP) { } 1728d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff friend class ASTContext; // ASTContext creates these. 1729d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1730d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffpublic: 1731d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCInterfaceDecl *getDecl() const { return Decl; } 1732d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1733d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// isObjCQualifiedIdType - true for "id <p>". 1734d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCQualifiedIdType() const { return Decl == 0 && Protocols.size(); } 1735d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1736d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 1737d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// list of protocols qualifying this interface. 1738d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1739d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1740d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 1741d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff qual_iterator qual_end() const { return Protocols.end(); } 1742d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool qual_empty() const { return Protocols.size() == 0; } 1743d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1744d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 1745d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff /// interface type, or 0 if there are none. 1746d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 1747d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1748d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 1749d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, 1750d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCInterfaceDecl *Decl, 1751d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 1752d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1753d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const PrintingPolicy &Policy) const; 1754d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff static bool classof(const Type *T) { 1755d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return T->getTypeClass() == ObjCObjectPointer; 1756d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 1757d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 1758d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff}; 1759d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1760fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1761fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 1762fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1763fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 1764fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1765fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1766a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 1767a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 176806cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 1769a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1770898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 17713536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 17723536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 17733536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1774a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 17753536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1776fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1777fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// list of protocols qualifying this interface. If this is an instance of 1778fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1779fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// empty list if there are no qualifying protocols. 1780fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1781fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_begin() const; 1782fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_end() const; 1783fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1784fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1785fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1786fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// interface type, or 0 if there are none. 1787fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline unsigned getNumProtocols() const; 1788fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1789d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 17903536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 1791368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return T->getTypeClass() == ObjCInterface || 1792368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner T->getTypeClass() == ObjCQualifiedInterface; 17933536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 1794a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 17953536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 17963536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1797a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1798372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1799372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1800878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1801878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 1802a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 180306cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 180406cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1805e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1806e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1807fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1808e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1809a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1810065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 1811a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 181200bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 18134b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1814e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1815e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 18164b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 18174b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 18184b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1819065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1820065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1821065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1822065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1823d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 18244b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 18254b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 18264b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 18271ee0700c7dbe3554df09b4558e0b35a53d487ff2Chris Lattner const ObjCInterfaceDecl *Decl, 1828a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 18294b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1830e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1831a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1832e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1833a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1834e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1835fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1836fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1837fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1838fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1839fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_begin(); 1840fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1841fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1842fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1843fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1844fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1845fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_end(); 1846fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1847fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1848fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1849fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1850fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// interface type, or 0 if there are none. 1851fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1852fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1853fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1854fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->getNumProtocols(); 1855fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1856fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1857fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1858611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 18595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1860ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 1861ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 1862f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 1863f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1864f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 1865f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 1866ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1867ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1868ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 1869ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 18704243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 18714243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1872c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 18734243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 18748e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 1875f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1876f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 1877ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 1878ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1879611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1880d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 1881d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1882d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1883d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1884d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 1885d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1886d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 18874ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian if (const PointerType *PT = CT->getAsPointerType()) 18884ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 1889bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 1890d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1891d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1892e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 1893e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 1894e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 1895e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 1896e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 1897e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 1898e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1899e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1900ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1901ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1902e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1903e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1904e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1905e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1906e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 1907e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 1908e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 1909e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1910e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1911e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1912ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1913ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1914e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 1915e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1916e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1917e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 1918e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 1919e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 1920e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 1921e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 1922e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 1923e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 1924e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 1925e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 1926e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 1927e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1928e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 1929e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 1930e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 1931e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1932e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1933769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 1934769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 1935769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 19362b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 19372b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner if (const PointerType *PT = getAsPointerType()) 19382b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 19392b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 19402b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 19412b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 1942c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1943c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 1944611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 1945ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1946611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1947611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 1948ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1949611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 19505618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 195175b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 19525618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 1953bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 1954bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1955bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 19567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 19577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 19587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 19597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 19607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 19617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 1962498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 196301c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 1964498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 1965498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 1966498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 1967498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 1968f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 1969f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1970f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1971f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 1972f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (const MemberPointerType* T = getAsMemberPointerType()) 1973f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 1974f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 1975f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 1976f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1977611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 1978ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1979611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1980c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 1981c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1982c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1983c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 1984c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1985c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1986c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 1987c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1988c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1989898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 1990898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1991898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1992611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 1993ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1994611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1995f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 1996c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1997f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 1998611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 1999ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 2000611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2001213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 2002213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2003611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2004d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 2005d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2006d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 2007a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 2008c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2009368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 2010368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 2011c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 2012e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 2013a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 2014d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { 2015d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 2016d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 2017d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 2018d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 201972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 202072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 202172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 202272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2023e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 2024904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 2025e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 2026e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 2027e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 2028e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 2029e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 2030063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 2031063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 2032063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 2033063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 2034904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 2035904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 20368958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 20378958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 20388958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar isObjCInterfaceType() || isObjCQualifiedIdType() || 20396e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 20408958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 20418958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 2042820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 2043820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian return (isObjCInterfaceType() || isObjCQualifiedIdType() || 2044820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 2045820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 2046820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 204722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 204822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 204922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 205022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 205122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 205222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 205322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 205422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 205522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 20565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 20575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2059