Type.h revision d249e1d1f1498b81314459ceda19d6ff25c278ad
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Type interface and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_AST_TYPE_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_AST_TYPE_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner#include "clang/Basic/Diagnostic.h" 181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "clang/Basic/IdentifierTable.h" 19e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor#include "clang/AST/NestedNameSpecifier.h" 207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor#include "clang/AST/TemplateName.h" 215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/Support/Casting.h" 22fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h" 235cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h" 245cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h" 251734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h" 267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa; 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null; 32bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattnernamespace clang { class Type; } 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 36daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 37bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 38bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 39bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 40bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 41bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 42bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 43bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 44bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner enum { NumLowBitsAvailable = 3 }; 45bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TypedefDecl; 5155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 5272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 53aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 547532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 5749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 5921d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 60a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 61a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 62a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 64b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 6692866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 6740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 68e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor class QualifiedNameType; 69d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor class PrintingPolicy; 7072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 7172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 7272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 7372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 74f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 865cf243a883872441d73ca49cea7e20de5802629bChris Lattner llvm::PointerIntPair<Type*, 3> Value; 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian enum GCAttrTypes { 96d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 97d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 98d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 99d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 100d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1015cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1035cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 1045cf243a883872441d73ca49cea7e20de5802629bChris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065cf243a883872441d73ca49cea7e20de5802629bChris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 107a3ab4b85f54090927c2dfa2585b9f0e48509e944Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 1085cf243a883872441d73ca49cea7e20de5802629bChris Lattner Type *getTypePtr() const { return Value.getPointer(); } 1095cf243a883872441d73ca49cea7e20de5802629bChris Lattner 1105cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 1135cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1275cf243a883872441d73ca49cea7e20de5802629bChris Lattner return getTypePtr() == 0; 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 1315cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Const) ? true : false; 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 1345cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 1375cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 139b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 140b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1417effa1aceac1219529af23c776835f855b8d905cChris Lattner 1427effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1437effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1445cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 1455cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1465cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1485cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1495cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1505cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 1511c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 155c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 156c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 157c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 158971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 159971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 160971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 161971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 163e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getUnqualifiedType() const; 164e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 165e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 166e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1682fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 1692fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 1702fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 1712fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1722fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1732fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 174969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 17598cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1795cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value == RHS.Value; 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1825cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value != RHS.Value; 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 184d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 185d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 186d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 188d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 191d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const; 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 193c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 194c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 1953f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek 1963f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 1973f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 1983f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 200368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 202ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 203ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 204ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 205d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 206d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 207f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 208f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 209f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 210f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 211f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 214f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 215f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 216f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 23273af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2334e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 235daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2364e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2394e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2404e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 24311a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2440eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 24673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 26172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 26472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 27872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 27972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 28072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 28172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 283d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 287898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 293ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned TC : 5; 294898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 29516ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 29616ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 298124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 299124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 300898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 301f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 303898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3044b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 30673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 3078b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 308a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 315bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 316bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 317bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 318bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 319bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 320bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 328d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 329d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 330d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 331d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 332d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 333d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 33464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 33564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 33664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 33764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 338d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 339d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 340d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 341d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 343ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 344e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 345e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 346e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 34796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 34896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 34996d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 35113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 35213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 35313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 35477a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 35533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 35902f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 36002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 362f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 366c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 367c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 368c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 369d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 371c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 372ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 373c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 37426d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 37526d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 376befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 3775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 378a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 381bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 382f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 383f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 384c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 385c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 386c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 387c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 388898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 389c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 39099dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner bool isClassType() const; 391c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3924cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 393368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 394368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 395213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 396368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 397368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 398368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 39972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 4006e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 402898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 403898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// that its definition somehow depends on a template parameter 404898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 405898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 406063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 40772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4088958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4098958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4108958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4116e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4128958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4138958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 414820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 415820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 416820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian bool hasObjCPointerRepresentation() const; 417820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 418c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 419f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 420f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 421f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 422f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 42372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 42472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 425befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 4265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 427a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 4287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const LValueReferenceType *getAsLValueReferenceType() const; 4297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const RValueReferenceType *getAsRValueReferenceType() const; 430f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const MemberPointerType *getAsMemberPointerType() const; 431fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor const TagType *getAsTagType() const; 432c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 433769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 434898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 435769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 436c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 437ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 438c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 439c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4404cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 441213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 442368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 443368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 444368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 44572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 44672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4477532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4487532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 44955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 4502b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4512b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4522b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4532b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 454c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 455c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 456c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 457c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 458c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 459dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 460769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 461dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 462dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4633830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 464dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 465969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 466dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 471d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 472d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 473d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 477d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 478d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 479d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 481d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 4839bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4849bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 4853c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 486c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 488c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 489d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const = 0; 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 493f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 494f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 495f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 496f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 497ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 498f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 499f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 500f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 501f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 502f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 50359d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 504ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 505ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 50659d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 507d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 50859d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 50959d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 510d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 511b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 512b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 513b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 514b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 515b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 516ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 517ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 518f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 519d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5204886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 521ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 522d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 523ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 524ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5254886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 526ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 527f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 528d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 529f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 530ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5314886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 532ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 533ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 534f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 535f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 536ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 537ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 538ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 5485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 5532df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 5572ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 5622df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5648e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 5658e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 5666e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 5676e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 568898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 569898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent // This represents the type of a type-dependent expression. 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 574898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor BuiltinType(Kind K) 575898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 576898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 579d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const char *getName(bool CPlusPlus) const; 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 581d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 5855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 587f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 588f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 589f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 590f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 591f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 592f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 593f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 594f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 595f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 596f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 597f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 598f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 599f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 600f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 601f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 602d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 603f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 604f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 605f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 606f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 607f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 614898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 615898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 6165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 6205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 621d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 62203ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 6235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 63468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 635bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 63668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 637bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 64068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 645d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 64768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 64868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6605618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 6615618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 6625618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 6645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 667898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 668898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 6695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 6715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 6725618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 676d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 6795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 6805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6815618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 6835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const Type *T) { 6865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return T->getTypeClass() == BlockPointer; 6875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 6895618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 6905618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 69368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 69468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 69568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6967c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 6977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 6987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 69968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 7005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 70268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 70368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 705bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7127c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 7137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 7147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 7167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 7197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 7217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 7237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 726d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 7307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 7327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 7357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 7377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 7397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 742d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 7467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 748f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 749f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 750f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 751f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 752f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 753f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 754f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 755f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 756f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 757f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 758f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 759f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 760f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 761f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 762f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 763f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 764f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 765f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 766f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 767f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 768f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 769f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 770d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 771f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 772f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 773f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 774f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 775f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 776f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 777f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 778f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 779f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 780f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 781f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 782f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 783f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 784f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7892e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 792898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 793898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 794898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 799fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 800fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 801c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 802ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 803c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 804ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 805c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 806c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 807c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 808c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 809c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 810fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 811898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 812898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 813898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 814898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 815898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 816c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 817c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 818898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 819898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 820898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 821fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 822fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 823fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 824ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 825ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 826ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 827c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 828fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 829fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 830fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 831c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 832898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 833898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 834fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 835fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 836fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 837fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 838da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ConstantArrayType - This class represents C arrays with a specified constant 839da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[100]' has ConstantArrayType where the element type 840da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// is 'int' and the size is 100. 8412e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 842fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 843fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 8440be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 845c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 8460be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 847fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 848fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 849c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 850d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 851fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 852fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8530be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSize(), 8540be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 855fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 856fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8570be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 8580be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 859fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 860fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 8610be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8620be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 863fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 864fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 865fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray; 866fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 867fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 868fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 869fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 870da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 871da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 872da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 873c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 874c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 875c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArraySizeModifier sm, unsigned tq) 876c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 877c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 878c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 879c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 880d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 881c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 882c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 883c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 884c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 885c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 886c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 887c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 888c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 889c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 8900be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 891c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 892c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 8930be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8940be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 895c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 8960be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8970be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 898c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 899c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 900c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 901da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 902da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 903da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 904da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 905da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 906da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 907da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 908da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 909da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 910da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 911da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 912da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 913da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 914da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 915da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 9162e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 917fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 918fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 919b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 921c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 922c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 923b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 9245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 9254b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 9264b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 928c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Expr *getSizeExpr() const { 929b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 930b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 931b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 932b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 934d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 936fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 937fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 939fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 940a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 94192866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 9422bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 9432bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 944bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 9452bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 948898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 949898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 950898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 951898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// template<typename T, int Size> 952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 953898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 954898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 956898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 957898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 958898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 959898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 960898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 961898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 962898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 963898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 964898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 965898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArraySizeModifier sm, unsigned tq) 966898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 967898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 968898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 969898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 970898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 971898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr *getSizeExpr() const { 972898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 973898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 974898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 975898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 976898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 977d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 978898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 979898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const Type *T) { 980898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return T->getTypeClass() == DependentSizedArray; 981898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 982898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 983898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 984898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 985898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 986898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 987bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 988898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 989898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 990898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 99173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 99273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 99373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 99473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 99673322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 100373322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1004898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Vector, canonType, vecType->isDependentType()), 1005898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(vecType), NumElements(nElements) {} 100673322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1007353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman QualType canonType) 1008898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1009898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumElements(nElements) {} 10105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1016d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 101973322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 102173322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 102273322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 102573322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 102673322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 102773322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 1028213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 10295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1033213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1034213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1035213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1036fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1037fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1038213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1039213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1040213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 104173322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 104273322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 104388dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 104488dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 104588dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 104688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 104788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 104888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 104988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 105088dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1051e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1052353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 105388dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1054353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1055353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1056353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1057353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1058353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1059353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1060353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1061353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1062353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1063353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1064353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1065353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1066353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1067353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1068353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1069353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1070353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 107188dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1072e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1073b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 1074b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1075b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1076353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1077b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 1078b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 107988dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1080b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 108188dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 108288dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1083e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1084d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 108531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 10867064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 1087213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == ExtVector; 108873322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1089213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 109073322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 109173322924127c873c13101b705dd823f5539ffa5fSteve Naroff 10925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 109372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1099971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 110072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1101971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 110272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1103971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1104971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1105971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1106971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1107971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1112971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 1114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 1115971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1117971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 11285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 113072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 113272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 113372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType(QualType Result, QualType Canonical) 1134898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 11354b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false) {} 11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1140d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 115272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 115572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1157465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1158465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1159465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 116072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1161898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1162898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1163898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1164898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1165898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 11664b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1167898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1168898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1169898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1170898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 117172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1172465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1173465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 1174465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned numExs, QualType Canonical) 1175898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 11764b4218f48fef71a179c5a8287dae281580faf52fNate Begeman (Result->isDependentType() || 11774b4218f48fef71a179c5a8287dae281580faf52fNate Begeman hasAnyDependentType(ArgArray, numArgs))), 1178465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1179465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1180942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1181465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1184465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1185465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1186465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1187465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 11885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1189465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1191465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1192465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1193465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1194465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1195465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1196465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1197465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1198465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1199465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1200465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1201465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1202942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1203942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1204465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1205465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1206465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1207465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12094b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 12105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 12125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 12135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1214942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 12155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1216465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1217465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1218465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1219465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1220465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1221465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1222465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1223465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1224465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1226971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1229942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1230942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1231942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1232942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1233465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1234465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1235465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1236465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1237465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1238465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1239465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1240465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1241465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1242465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1243d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 12475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 124872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1249465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1252942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1253465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1254465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 1255465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions, exception_iterator Exs); 12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 12605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1261c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 1262c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1263898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 1270a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 1271a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1272fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1273a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1274a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1275a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1276a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1277a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1279d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 128172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 128572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 128672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1287d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 128872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TypeOfExprType(Expr *E, QualType can); 1289d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1290d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1291d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 1292d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1293d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1294d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 129572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 129672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1297d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1298d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1299d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1300d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1301d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 1302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeOfType(QualType T, QualType can) 130372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1304d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1305d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1306d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1307d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1308d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 1309d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1310d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1311d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 131272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1313d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1314d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 13170b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 13180b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 13190b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 13200b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 13210b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1322fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 13234b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 13240b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 13252ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 13262ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 13277da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 13282ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 13292ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorpublic: 13300b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 13315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13320b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 13330b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// defined. 13340b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 13350b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 13360b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 1337d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1338e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 133972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { 134072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 134172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 134372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 134472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 13485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 13495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 135049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1351509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 135272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 135372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 135472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 13552ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 13565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 13575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13585edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 13595edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 13605edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 13615edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 13635edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 13645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 13655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 13665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 13685edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 13695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 13705edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13712daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 13722daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 13732daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 13742daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 13755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 13765edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 13775edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13785edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 13795edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 13805edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1381509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 138272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 13832ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 13845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 13855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 13875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 13885edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 13895edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 13902daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 13912daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 13922daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 13932daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 13945edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 13955edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 13965edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1397fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1398fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Depth : 16; 1399fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 1400fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 140172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1402fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1403fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor QualType Canon) 1404fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1405fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Depth(D), Index(I), Name(N) { } 140672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1407fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmType(unsigned D, unsigned I) 1408fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1409fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Depth(D), Index(I), Name(0) { } 141072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1411fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 141272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1413fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1414fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1415fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 1416fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 1417fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1418d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 14195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1420fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1421fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Profile(ID, Depth, Index, Name); 1422fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1423fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1424fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1425fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index, IdentifierInfo *Name) { 1426fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1427fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 1428fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1429fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1430fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 143172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const Type *T) { 143272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return T->getTypeClass() == TemplateTypeParm; 143372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 143472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 143572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1436fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 14377532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 14387532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 143955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 14407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 14417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 14427532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 14437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 14447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 144555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 14467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// a tag type for the instantiation 144755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 14487532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 14497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 14507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 14517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 14527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorclass TemplateSpecializationType 145355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 145455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14557532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief The name of the template being specialized. 14567532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 145755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 145840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 145940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 146055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 146155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateSpecializationType(TemplateName T, 14637532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 14647532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 146555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 14665908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 14675908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 146855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 146955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 147055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 147140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 147240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 147340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 147440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor unsigned NumArgs); 147540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1476df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1477df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1478df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1479d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 1480d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 1481df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 148240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 148340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 148440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 148540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 148640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 14877532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 14887532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 148955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 149040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 149140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *getArgs() const { 149240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 149340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 149440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 149540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 149655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 149755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 149855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 149955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 150040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 150155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1502d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 150355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 150455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 150540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Profile(ID, Template, getArgs(), NumArgs); 150655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 150755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 15087532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 150940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *Args, unsigned NumArgs); 151055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 151155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor static bool classof(const Type *T) { 15127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return T->getTypeClass() == TemplateSpecialization; 151355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 15147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 151555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 151655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1517e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1518e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1519e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1520e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1521119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1522119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1523119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1524e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1525ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1526ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1527e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1528e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1529e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1530e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1531ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1532ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1533ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1534ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1535e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1536e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1537e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1538e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1539ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1540ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1541e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1542e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1543e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1544e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1545d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1546e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1547e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1548ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1549e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1550e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1551ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1552ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 1553ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 1554ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 1555ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 1556e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1557e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const Type *T) { 1558e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return T->getTypeClass() == QualifiedName; 1559e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1560e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1561e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 1562e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1563d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 1564d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 1565d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 1566d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 1567d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 1568d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 1569d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 1570d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 1571d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 1572d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 1573d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 1574d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 1575d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 1576d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1577d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 1578d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 15791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor typedef llvm::PointerUnion<const IdentifierInfo *, 15801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 15811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1582d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 15831734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 1584d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1585d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1586d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 1587d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1588d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && 1589d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 1590d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1591d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 15921734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 15931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 15941734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 15951734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && 15961734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 15971734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 15981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1599d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 1600d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1601d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 1602d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 1603d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1604d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 16051734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 16061734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 16071734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 16081734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 16091734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 16101734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 16111734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const IdentifierInfo *getIdentifier() const { 16121734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const IdentifierInfo *>(); 16131734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 16141734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 16151734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 16161734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 16171734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 16181734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 16191734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 1620d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1621d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1622d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1623d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1624d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 1625d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1626d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1627d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 16281734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 1629d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 16301734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 1631d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1632d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1633d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const Type *T) { 1634d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return T->getTypeClass() == Typename; 1635d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1636d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 1637d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 1638d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1639fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1640fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 1641fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1642fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 1643fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1644fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1645a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 1646a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 164706cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 1648a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1649898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 16503536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 16513536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 16523536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1653a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 16543536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1655fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1656fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// list of protocols qualifying this interface. If this is an instance of 1657fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1658fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// empty list if there are no qualifying protocols. 1659fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1660fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_begin() const; 1661fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_end() const; 1662fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1663fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1664fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1665fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// interface type, or 0 if there are none. 1666fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline unsigned getNumProtocols() const; 1667fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1668d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 16693536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 1670368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return T->getTypeClass() == ObjCInterface || 1671368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner T->getTypeClass() == ObjCQualifiedInterface; 16723536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 1673a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 16743536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 16753536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1676a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1677372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1678372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1679878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1680878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 1681a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 168206cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 168306cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1684e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1685e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1686fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1687e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1688a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1689065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 1690a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 169100bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 16924b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1693e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1694e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 16954b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 16964b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 16974b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1698065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1699065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1700065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1701065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1702d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 17034b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 17044b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 17054b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 17061ee0700c7dbe3554df09b4558e0b35a53d487ff2Chris Lattner const ObjCInterfaceDecl *Decl, 1707a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 17084b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1709e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1710a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1711e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1712a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1713e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1714fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1715fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1716fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1717fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1718fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_begin(); 1719fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1720fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1721fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1722fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1723fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1724fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_end(); 1725fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1726fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1727fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1728fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1729fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// interface type, or 0 if there are none. 1730fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1731fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1732fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1733fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->getNumProtocols(); 1734fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1735fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1736fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1737372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// ObjCQualifiedIdType - to represent id<protocol-list>. 1738372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1739372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// Duplicate protocols are removed and protocol list is canonicalized to be in 1740372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// alphabetical order. 1741a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedIdType : public Type, 1742c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian public llvm::FoldingSetNode { 1743c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List of protocols for this protocol conforming 'id' type 1744c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1745a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1746c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 174762f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1748898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 17494b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false), 1750c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian Protocols(Protos, Protos+NumP) { } 1751c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1752c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianpublic: 1753c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1754c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian unsigned getNumProtocols() const { 1755c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian return Protocols.size(); 1756c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1757065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1758065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1759065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1760065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1761c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1762d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1763c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1764c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 176562f5f7ffad57e0c2af2b308af3735351505937cbChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, 1766a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 1767c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1768c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian static bool classof(const Type *T) { 1769a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedId; 1770c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian } 1771a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedIdType *) { return true; } 1772c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian 1773c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian}; 1774e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1775611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 17765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1777ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 1778ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 1779f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 1780f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1781f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 1782f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 1783ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1784ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1785ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 1786ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 17874243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 17884243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1789c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 17904243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 17918e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 1792f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1793f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 1794ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 1795ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1796611c1fff195d32df97706e0920c92468b2509900Chris Lattner 1797d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 1798d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1799d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1800d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1801d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 1802d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1803d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 18044ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian if (const PointerType *PT = CT->getAsPointerType()) 18054ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 1806bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 1807d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1808d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1809e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 1810e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 1811e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 1812e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 1813e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 1814e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 1815e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1816e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1817ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1818ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1819e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1820e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1821e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1822e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1823e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 1824e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 1825e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 1826e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1827e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 1828e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 1829ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 1830ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 1831e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 1832e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1833e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1834e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 1835e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 1836e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 1837e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 1838e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 1839e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 1840e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 1841e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 1842e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 1843e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 1844e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1845e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 1846e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 1847e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 1848e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 1849e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 1850769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 1851769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 1852769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 18532b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 18542b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner if (const PointerType *PT = getAsPointerType()) 18552b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 18562b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 18572b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 18582b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 1859c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1860c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 1861611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 1862ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1863611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1864611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 1865ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1866611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 18675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 186875b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 18695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 1870bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 1871bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1872bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 18737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 18747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 18757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 18767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 18777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 18787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 1879498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 188001c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 1881498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 1882498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 1883498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 1884498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 1885f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 1886f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1887f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1888f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 1889f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (const MemberPointerType* T = getAsMemberPointerType()) 1890f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 1891f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 1892f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 1893f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1894611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 1895ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1896611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1897c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 1898c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1899c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1900c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 1901c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1902c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1903c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 1904c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1905c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 1906898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 1907898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1908898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1909611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 1910ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1911611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1912f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 1913c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1914f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 1915611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 1916ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1917611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1918213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 1919213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1920611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 1921a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 1922c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1923368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 1924368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 1925c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1926e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 1927a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 1928c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1929d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 193072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 193172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 193272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 193372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1934e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 1935904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 1936e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 1937e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 1938e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 1939e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 1940e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 1941063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 1942063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 1943063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 1944063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 1945904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 1946904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 19478958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 19488958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 19498958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar isObjCInterfaceType() || isObjCQualifiedIdType() || 19506e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 19518958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 19528958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 1953820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 1954820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian return (isObjCInterfaceType() || isObjCQualifiedIdType() || 1955820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 1956820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 1957820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 195822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 195922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 196022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 196122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 196222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 196322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 196422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 196522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 196622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 19675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 19685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1970