Type.h revision 3b4ea54acf01f72f6eb74d96689dda86d950228f
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; 693b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar struct PrintingPolicy; 7072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 7172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 7272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 7372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 74f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 865cf243a883872441d73ca49cea7e20de5802629bChris Lattner llvm::PointerIntPair<Type*, 3> Value; 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 95d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian enum GCAttrTypes { 96d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 97d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 98d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 99d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 100d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1015cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1035cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 1045cf243a883872441d73ca49cea7e20de5802629bChris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065cf243a883872441d73ca49cea7e20de5802629bChris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 107a3ab4b85f54090927c2dfa2585b9f0e48509e944Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 1085cf243a883872441d73ca49cea7e20de5802629bChris Lattner Type *getTypePtr() const { return Value.getPointer(); } 1095cf243a883872441d73ca49cea7e20de5802629bChris Lattner 1105cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 1135cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1275cf243a883872441d73ca49cea7e20de5802629bChris Lattner return getTypePtr() == 0; 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 1315cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Const) ? true : false; 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 1345cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 1375cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 139b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 140b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1417effa1aceac1219529af23c776835f855b8d905cChris Lattner 1427effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1437effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1445cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 1455cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1465cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1485cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1495cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1505cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 1511c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 155c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 156c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 157c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 158971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 159971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 160971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 161971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 163e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getUnqualifiedType() const; 164e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 165e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 166e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1682fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 1692fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 1702fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 1712fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1722fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1732fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 174969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 17598cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1795cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value == RHS.Value; 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1825cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value != RHS.Value; 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 184d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 185d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 186d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 188d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 191e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 192e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 194c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 195c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 1963f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek 1973f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 1983f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 1993f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 201368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 203ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 204ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 205ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 206d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 207d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 208f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 209f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 210f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 211f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 214f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 215f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 216f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 217f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 23373af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2344e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 236daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2374e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2384e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2394e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2404e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2434e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 24411a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2450eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 24773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 26272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 26572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 27972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 28072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 28172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 28272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 284d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 289898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 290898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 2947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned TC : 6; 295898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 29616ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 29716ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 299124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 300124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 301898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 302f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 303898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 304898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3054b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 30773af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 3088b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 309a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 316bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 317bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 318bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 319bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 320bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 321bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 329d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 330d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 331d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 332d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 333d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 334d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 33564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 33664b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 33764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 33864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 339d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 340d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 341d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 342d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 344ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 345e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 346e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 347e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 34896d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 34996d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 35096d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 35213b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 35313b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 35413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 35577a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 35633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 36002f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 36102f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 363f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 367c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 368c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 369c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 370d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 372c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 373ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 374c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 37526d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 37626d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 377befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 3785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 3797154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 380a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 383bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 384f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 385f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 386c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 387c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 388c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 389c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 390898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 391c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 39299dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner bool isClassType() const; 393c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 3944cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 395368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 396368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 397213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 398d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 39914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 40014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 401368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 402368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 403368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 40414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 40514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 40672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 4076e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 408898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 409898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 410898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// that its definition somehow depends on a template parameter 411898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 412898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 413063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 41472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4158958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4168958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4178958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4186e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4198958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4208958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 421820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 422820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 423820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian bool hasObjCPointerRepresentation() const; 424820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 425c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 426f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 427f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 428f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 429f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 43072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 43172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 432befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner const PointerType *getAsPointerType() const; 4335618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff const BlockPointerType *getAsBlockPointerType() const; 434a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner const ReferenceType *getAsReferenceType() const; 4357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const LValueReferenceType *getAsLValueReferenceType() const; 4367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl const RValueReferenceType *getAsRValueReferenceType() const; 437f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const MemberPointerType *getAsMemberPointerType() const; 438fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor const TagType *getAsTagType() const; 439c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsRecordType() const; 440769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 441898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 442769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 443c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 444ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 445c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 446c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4474cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 448213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 449d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 45014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 45114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 45214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 45314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 454368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 455368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 45672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 45772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 46055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 4612b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4622b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4632b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4642b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 465c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 466c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 467c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 468c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 469c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 47014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// getPointeeType - If this is a pointer or ObjC object pointer, this 47114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// returns the respective pointee. 47214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 47314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 474dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 475769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 476dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 477dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4783830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 479dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 480969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 481dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 486d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 487d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 488d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 4895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 4905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 492d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 493d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 494d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 496d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 4989bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 4999bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 5003c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 501c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 50222b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 50322b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 50422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 50522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 507c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 508d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const = 0; 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 512f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 513f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 514f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 515f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 516ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 517f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 518f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 519f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 520f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 521f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 52259d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 523ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 524ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 52559d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 526d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 52759d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 52859d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 529d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 530b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 531b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 532b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 533b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 534b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 535ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 536ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 537f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 538d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5394886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 540ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 541d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 542ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 543ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5444886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 545ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 546f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 547d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 548f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 549ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5504886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 551ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 552ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 553f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 554f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 555ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 556ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 557ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 5722df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 5762ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 5805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 5812df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5838e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 5848e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 5856e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 5866e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 587898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 588e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson Dependent, // This represents the type of a type-dependent expression. 589e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson 590e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson UndeducedAuto // In C++0x, this represents the type of an auto variable 591e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 5955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 596898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor BuiltinType(Kind K) 597898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 598898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 601e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 603d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 609f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 610f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 611f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 612f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 613f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 614f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 615f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 616f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 617f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 618f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 619f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 620f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 621f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 622f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 623f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 624d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 625f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 626f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 627f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 628f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 629f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 6335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 6345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 6355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 636898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 637898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 643d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 64403ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 6455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 65668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 657bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 65868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 659bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 66268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 667d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 66968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 67068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 6835618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 6845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 6855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 6865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 6875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 6885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 689898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 690898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 6915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 6925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 6935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 6945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 6955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 6965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 6975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 698d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 6995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 7005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 7015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 7025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 7035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 7045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 7055618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 7065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 7075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const Type *T) { 7085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return T->getTypeClass() == BlockPointer; 7095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 7105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 7115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 7125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 7137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 71568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 71668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 71768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 7197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 7207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 72168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 72468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 72568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 727bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 7357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 7367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 7387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 7417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 7437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7447c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 7457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 748d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 7527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 7547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 7557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 7577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 7587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 7597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 7607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 7617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 7637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 764d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 7657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 7667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 7677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 7687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 7697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 770f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 771f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 772f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 773f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 774f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 775f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 776f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 777f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 778f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 779f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 780f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 781f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 782f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 783f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 784f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 785f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 786f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 787f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 788f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 789f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 790f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 791f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 792d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 793f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 794f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 795f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 796f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 797f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 798f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 799f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 800f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 801f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 802f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 803f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 804f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 805f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 806f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 8075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 8085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 8112e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 8135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 814898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 815898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 816898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 8185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 8195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 8205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 821fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 822fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 823c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 824ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 825c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 826ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 827c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 828c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 829c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 830c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 831c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 832fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 833898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 834898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 835898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 836898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 837898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 838c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 839c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 840898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 841898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 842898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 843fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 844fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 845fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 846ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 847ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 848ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 849c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 850fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 851fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 852fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 8537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 8547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr || 855c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 856898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 857898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 858fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 859fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 860fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 861fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 8627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 8637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 8647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 8657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 8662e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 867fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 868fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 8690be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 870c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 8717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 8727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 8737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 8747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 8757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 8767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 877fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 878fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 879c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 880d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 881fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 882fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8830be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSize(), 8840be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 885fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 886fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 8870be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 8880be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 889fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 890fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 8910be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 8920be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 893fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 8947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 8957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArray || 8967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 8977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr; 898fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 899fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 900fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 901fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 9027e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithExprType - This class represents C arrays with a 9037e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size specified by means of an integer constant expression. 9047e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where 9057e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// the element type is 'int' and the size expression is 'sizeof(int)'. 9067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical. 9077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithExprType : public ConstantArrayType { 9087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// SizeExpr - The ICE occurring in the concrete syntax. 9097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *SizeExpr; 9107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 9117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 9127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithExprType(QualType et, QualType can, 9147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, Expr *e, 9157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 9167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 9177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq), 9187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr(e), Brackets(brackets) {} 9197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 9207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void Destroy(ASTContext& C); 9217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 9237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 9247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 9257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 9267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 9277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 9297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 9307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 9327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithExpr; 9337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 9347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithExprType *) { return true; } 9357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 9377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithExprTypes."); 9387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 9397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 9407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithoutExprType - This class represents C arrays with a 9427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size that was not specified by an integer constant expression, 9437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// but inferred by static semantics. 9447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType. 9457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical: the corresponding canonical type, 9467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// having the size specified in an APInt object, is a ConstantArrayType. 9477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithoutExprType : public ConstantArrayType { 9487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithoutExprType(QualType et, QualType can, 9507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, 9517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 9527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {} 9537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 9547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 9567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 9577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 9587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 9607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithoutExpr; 9617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 9627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithoutExprType *) { return true; } 9637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 9647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 9657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithoutExprTypes."); 9667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 9677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 9687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 969da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 970da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 971da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 972c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 9737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 974c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 9757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 976c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 977c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 978c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 979d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 980c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 981c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 982c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 983c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 984c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 985c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 986c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 987c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 988c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 9890be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 990c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 991c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 9920be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 9930be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 994c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 9950be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 9960be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 997c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 998c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 999c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1000da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 1001da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1002da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 1003da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1004da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1005da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 1006da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 1007da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 1008da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1009da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 1010da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 1011da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 1012da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 1013da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 1014da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 10152e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 1016fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 1017fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 1018b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 10197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 10207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 10217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1022c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 10237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 10247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 10257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 10267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 10284b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 10294b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 10305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1031c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Expr *getSizeExpr() const { 1032b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 1033b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1034b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 1035b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 10367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 10377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 10387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 10395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1040d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 10415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1042fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1043fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 10445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1045fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 1046a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 104792866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 10482bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 10492bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 1050bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 10512bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 10535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1054898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 1055898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 1056898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 1057898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// template<typename T, int Size> 1058898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 1059898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 1060898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 1061898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 1062898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 1063898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 1064898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 1065898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 1066898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 1067898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 1068898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 10697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 10707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 1071898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1072898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 10737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 10747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 10757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 10767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 1077898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 1078898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 1079898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1080898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 1081898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr *getSizeExpr() const { 1082898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 1083898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 1084898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 1085898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 10867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 10877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 10887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1089898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1090d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1091898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1092898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const Type *T) { 1093898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return T->getTypeClass() == DependentSizedArray; 1094898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1095898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 1096898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1097898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 1098898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1099898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1100bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 1101898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1102898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1103898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1104f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 11059cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 11069cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 11079cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 11089cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 11099cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 11109cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 11119cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 11129cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorclass DependentSizedExtVectorType : public Type { 11139cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 11149cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 11159cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 11169cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 11179cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 11189cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor DependentSizedExtVectorType(QualType ElementType, QualType can, 11199cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr, SourceLocation loc) 11209cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor : Type (DependentSizedExtVector, can, true), 11219cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {} 11229cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 11239cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 11249cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 11259cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 1126f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor const Expr *getSizeExpr() const { return SizeExpr; } 11279cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 11289cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 11299cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 11309cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 11319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 11329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const Type *T) { 11339cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return T->getTypeClass() == DependentSizedExtVector; 11349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 11359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const DependentSizedExtVectorType *) { return true; } 11369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 11379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 11389cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 113973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 114073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 114173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 114273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 114473322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 11505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 115173322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1152898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Vector, canonType, vecType->isDependentType()), 1153898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(vecType), NumElements(nElements) {} 115473322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1155353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman QualType canonType) 1156898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1157898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumElements(nElements) {} 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1164d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 11655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 116773322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 116973322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 117073322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 117373322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 117473322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 117573322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 1176213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1181213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1182213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1183213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1184fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1185fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1186213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1187213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1188213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 118973322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 119073322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 119188dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 119288dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 119388dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 119488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 119588dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 119688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 119788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 119888dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1199e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1200353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 120188dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1202353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1203353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1204353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1205353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1206353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1207353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1208353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1209353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1210353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1211353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1212353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1213131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1214353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1215131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1216353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1217131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1218353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1219131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1220353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1221131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1222353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1223131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1224353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 122588dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1226e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1227b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 1228b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1229b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1230353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1231b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 1232b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 123388dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1234b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 123588dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 123688dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1237e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1238d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 123931a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 12407064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 1241213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == ExtVector; 124273322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1243213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 124473322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 124573322924127c873c13101b705dd823f5539ffa5fSteve Naroff 12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 124772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 12515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 12525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1253971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 125472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1255971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 125672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1257971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1258971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1259971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1260971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1261971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 12625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 12645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1266971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1267898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor unsigned typeQuals, QualType Canonical, bool Dependent) 1268898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 1269971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1271971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 12785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 12825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 128472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 128672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 128772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType(QualType Result, QualType Canonical) 1288898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 12894b4218f48fef71a179c5a8287dae281580faf52fNate Begeman /*Dependent=*/false) {} 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1294d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getResultType()); 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 13015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 130672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 130972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1311465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1312465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1313465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 131472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1315898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1317898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1318898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1319898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 13204b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1321898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1322898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1323898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1324898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 132572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1326465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1327465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 1328465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned numExs, QualType Canonical) 1329898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 13304b4218f48fef71a179c5a8287dae281580faf52fNate Begeman (Result->isDependentType() || 13314b4218f48fef71a179c5a8287dae281580faf52fNate Begeman hasAnyDependentType(ArgArray, numArgs))), 1332465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1333465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1334942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1335465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1338465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1339465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1340465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1341465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1343465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 13445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1345465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1346465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1347465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1348465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1349465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1350465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1351465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1352465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1353465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1354465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1355465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1356942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1357942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1358465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1359465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1360465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1361465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 13625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 13634b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 13645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 13665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 13675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1368942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 13695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1370465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1371465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1372465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1373465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1374465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1375465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1376465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1377465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1378d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson bool hasEmptyExceptionSpec() const { 1379a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson return hasExceptionSpec() && !hasAnyExceptionSpec() && 1380a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1381d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1382465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1384971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 13855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1387942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1388942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1389942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1390942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1391465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1392465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1393465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1394465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1395465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1396465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1397465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1398465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1399465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1400465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1401d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 14025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 14045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 14055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 140672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1407465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1410942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1411465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1412465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 1413465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions, exception_iterator Exs); 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1419c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 1420c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1421898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 14235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 14255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 1428a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 1429a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1430fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1431a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1432a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1433a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1434a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1435a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1437d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 14385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 143972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 144372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 144472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1445d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 1446dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 1447d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1448d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1449d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 1450d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1451d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1452d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 145372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 145472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1455d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1456d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1457d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1458d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1459d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 1460898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeOfType(QualType T, QualType can) 146172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1462d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1463d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1464d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1465d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1466d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 1467d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1468d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1469d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 147072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1471d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1472d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 14735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1474395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 1475395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 1476395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 1477563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1478563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 1479563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 1480563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 1481563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 1482563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1483563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 1484395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 1485395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 1486395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 1487563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 1488563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1489395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson virtual void getAsStringInternal(std::string &InnerString, 1490395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson const PrintingPolicy &Policy) const; 1491395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1492395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1493395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 1494395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 1495395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 14965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 14970b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 14980b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 14990b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 15000b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 15010b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1502fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 15034b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 15040b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 15052ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 15062ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 15077da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 15082ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 15092ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorpublic: 15100b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15120b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 15130b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// defined. 15140b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 15150b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 15160b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 1517d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1518e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 151972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { 152072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 152172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 152372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 152472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15275edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 15285edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 15295edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 153049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1531509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 153272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 153372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 153472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 15352ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 15365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 15375edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15385edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 15395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 15405edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 15415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 15435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 15445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 15455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 15465edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 15485edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 15495edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 15505edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15512daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 15522daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 15532daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 15542daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 15555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 15565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 15575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15585edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 15595edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 15605edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1561509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 156272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 15632ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 15645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 15655edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15665edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 15675edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 15685edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 15695edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 15702daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 15712daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 15722daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 15732daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 15745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 15755edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 15765edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1577fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 157876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 1579fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 158076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 1581fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 158272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 158376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 1584fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor QualType Canon) 1585fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 158676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 158772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 158876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1589fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 159076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 159172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1592fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 159372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1594fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1595fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1596fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 159776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 1598fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 1599fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1600d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 16015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1602fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 160376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 1604fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1605fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1606fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 160776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Index, bool ParameterPack, 160876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 1609fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1610fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 161176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 1612fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1613fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1614fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 161572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const Type *T) { 161672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return T->getTypeClass() == TemplateTypeParm; 161772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 161872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 161972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1620fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 16217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 16227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 162355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 16247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 16257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 16267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 16277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 16287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 162955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 16307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// a tag type for the instantiation 163155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 16327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 16337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 16347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 16357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 16367532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorclass TemplateSpecializationType 163755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 163855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 16397532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief The name of the template being specialized. 16407532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 164155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 164240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 164340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 164455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 164555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 16467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateSpecializationType(TemplateName T, 16477532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 16487532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 164955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 16505908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 16515908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 165255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 165355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 165455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 165540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 165640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 165740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 165840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor unsigned NumArgs); 165940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1660df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1661df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1662df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1663d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 1664d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 1665df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 166640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 166740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 166840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 166940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 167040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 16717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 16727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 167355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 167440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 167540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *getArgs() const { 167640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 167740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 167840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 167940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 168055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 168155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 168255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 168355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 168440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 168555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1686d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 168755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 168855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 168940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Profile(ID, Template, getArgs(), NumArgs); 169055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 169155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 16927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 169340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *Args, unsigned NumArgs); 169455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 169555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor static bool classof(const Type *T) { 16967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return T->getTypeClass() == TemplateSpecialization; 169755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 16987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 169955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 170055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1701e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1702e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1703e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1704e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1705119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1706119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1707119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1708e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1709ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1710ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1711e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1712e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1713e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1714e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1715ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1716ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1717ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1718ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1719e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1720e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1721e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1722e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1723ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1724ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1725e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1726e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1727e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1728e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1729d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1730e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1731e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1732ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1733e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1734e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1735ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1736ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 1737ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 1738ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 1739ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 1740e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1741e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const Type *T) { 1742e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return T->getTypeClass() == QualifiedName; 1743e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1744e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1745e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 1746e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1747d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 1748d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 1749d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 1750d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 1751d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 1752d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 1753d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 1754d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 1755d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 1756d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 1757d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 1758d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 1759d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 1760d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1761d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 1762d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 17631734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor typedef llvm::PointerUnion<const IdentifierInfo *, 17641734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 17651734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1766d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 17671734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 1768d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1769d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1770d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 1771d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1772d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && 1773d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 1774d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1775d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 17761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 17771734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 17781734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 17791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && 17801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 17811734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 17821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1783d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 1784d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1785d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 1786d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 1787d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1788d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 17891734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 17901734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 17911734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 17921734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 17931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 17941734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 17951734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const IdentifierInfo *getIdentifier() const { 17961734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const IdentifierInfo *>(); 17971734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 17981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 17991734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 18001734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 18011734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 18021734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 18031734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 1804d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1805d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 1806d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1807d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1808d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 1809d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1810d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1811d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 18121734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 1813d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 18141734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 1815d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1816d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1817d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const Type *T) { 1818d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return T->getTypeClass() == Typename; 1819d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1820d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 1821d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 1822d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1823fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1824fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 1825fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1826fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 1827fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1828fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1829a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCInterfaceType : public Type { 1830a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 183106cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanianprotected: 1832a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1833898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 18343536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 183514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 183614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: These can go away when we move ASTContext::canAssignObjCInterfaces 183714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // to this class (as a static helper). 183814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdInterface() const; 183914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassInterface() const; 18403536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 18413536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 1842a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 184314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 1844fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1845fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// list of protocols qualifying this interface. If this is an instance of 1846fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1847fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// empty list if there are no qualifying protocols. 1848fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1849fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_begin() const; 1850fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline qual_iterator qual_end() const; 1851fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1852fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1853fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// getNumProtocols - Return the number of qualifying protocols in this 1854fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// interface type, or 0 if there are none. 1855fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner inline unsigned getNumProtocols() const; 1856fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1857d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 18583536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 1859368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner return T->getTypeClass() == ObjCInterface || 1860368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner T->getTypeClass() == ObjCQualifiedInterface; 18613536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 1862a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 18633536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 18643536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 186514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 186614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// and 'Interface <p> *'. 186714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 186814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 186914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// alphabetical order. 187014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 187114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType PointeeType; // will always point to an interface type. 187214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 187314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List of protocols for this protocol conforming object type 187414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List is sorted on protocol name. No protocol is entered more than once. 187514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 187614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 187714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCObjectPointerType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) : 187814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 187914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff PointeeType(T), Protocols(Protos, Protos+NumP) { } 188014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 188114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ObjCInterfaceType; // To enable 'id' and 'Class' predicates. 188214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 188314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static ObjCInterfaceType *IdInterfaceT; 188414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static ObjCInterfaceType *ClassInterfaceT; 188514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void setIdInterface(QualType T) { 188614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff IdInterfaceT = dyn_cast<ObjCInterfaceType>(T.getTypePtr()); 188714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 188814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void setClassInterface(QualType T) { 188914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ClassInterfaceT = dyn_cast<ObjCInterfaceType>(T.getTypePtr()); 189014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 189114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static ObjCInterfaceType *getIdInterface() { return IdInterfaceT; } 189214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static ObjCInterfaceType *getClassInterface() { return ClassInterfaceT; } 189314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 189414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Get the pointee type. Pointee is required to always be an interface type. 189514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Note: Pointee can be a TypedefType whose canonical type is an interface. 189614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Example: typedef NSObject T; T *var; 189714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 189814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 189914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCInterfaceType *getInterfaceType() const { 190014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PointeeType->getAsObjCInterfaceType(); 190114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 190214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 190314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return getInterfaceType()->getDecl(); 190414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 190514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// isObjCQualifiedIdType - true for "id <p>". 190614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCQualifiedIdType() const { 190714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return getInterfaceType() == IdInterfaceT && Protocols.size(); 190814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 190914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 191014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return getInterfaceType() == IdInterfaceT && !Protocols.size(); 191114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 191214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 191314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return getInterfaceType() == ClassInterfaceT && !Protocols.size(); 191414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 191514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 191614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// list of protocols qualifying this interface. 191714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 191814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 191914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 192014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_end() const { return Protocols.end(); } 192114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool qual_empty() const { return Protocols.size() == 0; } 192214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 192314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 192414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// interface type, or 0 if there are none. 192514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 192614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 192714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 192814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 192914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 193014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff virtual void getAsStringInternal(std::string &InnerString, 193114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const PrintingPolicy &Policy) const; 193214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const Type *T) { 193314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return T->getTypeClass() == ObjCObjectPointer; 193414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 193514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 193614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 193714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 1938a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// ObjCQualifiedInterfaceType - This class represents interface types 1939372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1940372bed091b6b1eca596130208e227e7077154de4Chris Lattner/// 1941878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// Duplicate protocols are removed and protocol list is canonicalized to be in 1942878520b6413663a13b1b56c7e3f256b1ecbb8db4Fariborz Jahanian/// alphabetical order. 194314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// FIXME: Remove this class (converting uses to ObjCObjectPointerType). 1944a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekclass ObjCQualifiedInterfaceType : public ObjCInterfaceType, 194506cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian public llvm::FoldingSetNode { 194606cef25d0b8c383217413f061441c7ea40d1052bFariborz Jahanian 1947e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List of protocols for this protocol conforming object type 1948e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian // List is sorted on protocol name. No protocol is enterred more than once. 1949fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1950e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 1951a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1952065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner ObjCProtocolDecl **Protos, unsigned NumP) : 1953a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceType(ObjCQualifiedInterface, D), 195400bb283ecdfb1d5c69261c7663d166cee3f11a9bChris Lattner Protocols(Protos, Protos+NumP) { } 19554b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian friend class ASTContext; // ASTContext creates these. 1956e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanianpublic: 1957e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian 19584b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian unsigned getNumProtocols() const { 19594b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return Protocols.size(); 19604b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian } 1961065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1962065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_begin() const { return Protocols.begin(); } 1963065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner qual_iterator qual_end() const { return Protocols.end(); } 1964065f0d7b00c3cd2b3139ebd105f50462fc778859Chris Lattner 1965d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; 19664b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 19674b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void Profile(llvm::FoldingSetNodeID &ID); 19684b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian static void Profile(llvm::FoldingSetNodeID &ID, 19691ee0700c7dbe3554df09b4558e0b35a53d487ff2Chris Lattner const ObjCInterfaceDecl *Decl, 1970a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **protocols, unsigned NumProtocols); 19714b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 1972e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian static bool classof(const Type *T) { 1973a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek return T->getTypeClass() == ObjCQualifiedInterface; 1974e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian } 1975a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1976e37882ad335896dedf345102bb425383e6221c37Fariborz Jahanian}; 1977fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1978fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1979fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1980fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1981fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_begin(); 1982fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1983fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1984fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1985fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1986fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1987fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->qual_end(); 1988fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1989fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1990fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 1991fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// getNumProtocols - Return the number of qualifying protocols in this 1992fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// interface type, or 0 if there are none. 1993fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattnerinline unsigned ObjCInterfaceType::getNumProtocols() const { 1994fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner if (const ObjCQualifiedInterfaceType *QIT = 1995fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner dyn_cast<ObjCQualifiedInterfaceType>(this)) 1996fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return QIT->getNumProtocols(); 1997fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner return 0; 1998fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner} 1999fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner 2000611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 20015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2002ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 2003ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 2004f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 2005f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 2006f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 2007f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 2008ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2009ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 2010ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 2011ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 20124243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 20134243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2014c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 20154243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 20168e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 2017f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2018f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 2019ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 2020ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2021611c1fff195d32df97706e0920c92468b2509900Chris Lattner 2022d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 2023d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 2024d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2025d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2026d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 2027d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2028d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 202914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (const ObjCObjectPointerType *PT = CT->getAsObjCObjectPointerType()) 20304ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 2031bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 2032d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 2033d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2034e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 2035e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 2036e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 2037e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 2038e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 2039e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 2040e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2041e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2042ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2043ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2044e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 2045e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2046e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2047e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 2048e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 2049e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 2050e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 2051e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 2052e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2053e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2054ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2055ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2056e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 2057e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2058e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2059e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 2060e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 2061e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 2062e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 2063e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 2064e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 2065e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 2066e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 2067e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 2068e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 2069e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 2070e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 2071e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 2072e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 2073e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2074e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2075769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 2076769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 2077769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 20782b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 20792b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner if (const PointerType *PT = getAsPointerType()) 20802b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 20812b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 20822b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 20832b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 2084c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 2085c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 2086611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 2087ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 2088611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2089611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 2090ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 2091611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 20925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 209375b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 20945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 2095bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 2096bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 2097bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 20987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 20997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 21007c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 21017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 21027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 21037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 2104498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 210501c2c6e3c94a3fa2ac15851b4af5de6dc3ae2af8Ted Kremenek if (const PointerType* T = getAsPointerType()) 2106498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 2107498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 2108498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 2109498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 2110f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 2111f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 2112f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2113f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 2114f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (const MemberPointerType* T = getAsMemberPointerType()) 2115f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 2116f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 2117f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 2118f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2119611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 2120ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 2121611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2122c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 2123c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 2124c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2125c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 2126c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 2127c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2128c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 2129c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 2130c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2131898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 2132898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 2133898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2134611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 2135ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 2136611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2137f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 2138c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 2139f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 2140611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 2141ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 2142611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2143213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 2144213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2145611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2146d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 2147d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2148d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 2149a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 2150c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2151368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 2152368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerinline bool Type::isObjCQualifiedInterfaceType() const { 2153c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 2154e7f64cc250245aa6c0e1ef6da7e9b6f62d5feddeFariborz Jahanian} 2155a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 2156d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { 2157d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 2158d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff } 2159d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 2160d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 216114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 216214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { 216314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 216414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 216514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 216614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 216714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 216814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) { 216914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 217014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 217114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 217214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 217372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 217472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 217572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 217672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2177e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 2178904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 2179e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 2180e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 2181e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 2182e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 2183e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 2184063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 2185063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 2186063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 2187063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 2188904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 2189904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 21908958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 21918958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 219214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff isObjCInterfaceType() || isObjCObjectPointerType() || 21936e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 21948958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 21958958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 2196820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 219714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return (isObjCInterfaceType() || isObjCObjectPointerType() || 2198820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 2199820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 2200820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 220122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 220222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 220322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 220422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 220522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 220622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 220722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 220822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 220922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 22105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 22115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 22125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2213