Type.h revision a91d6a6619a91d0ca7102d8ab5678d855f04d850
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 }; 100efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall 101efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall // 24 bits should be enough for anyone. 102efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall static const unsigned MaxAddressSpace = 0xffffffu; 103d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1045cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1065cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 1075cf243a883872441d73ca49cea7e20de5802629bChris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1095cf243a883872441d73ca49cea7e20de5802629bChris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 110a3ab4b85f54090927c2dfa2585b9f0e48509e944Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 1115cf243a883872441d73ca49cea7e20de5802629bChris Lattner Type *getTypePtr() const { return Value.getPointer(); } 1125cf243a883872441d73ca49cea7e20de5802629bChris Lattner 1135cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 1165cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1305cf243a883872441d73ca49cea7e20de5802629bChris Lattner return getTypePtr() == 0; 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 1345cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Const) ? true : false; 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 1375cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 1405cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 142b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 143b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1447effa1aceac1219529af23c776835f855b8d905cChris Lattner 1457effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1467effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1475cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 1485cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1495cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1515cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1525cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1535cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 1541c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 158c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 159c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 160c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 161971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 162971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 163971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 164971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 166e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getUnqualifiedType() const; 167e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 168e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 169e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1712fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 1722fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 1732fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 1742fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1752fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1762fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 177969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 17898cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator==(const QualType &RHS) const { 1825cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value == RHS.Value; 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool operator!=(const QualType &RHS) const { 1855cf243a883872441d73ca49cea7e20de5802629bChris Lattner return Value != RHS.Value; 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 187d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 188d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 189d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 191d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 194e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 195e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 197c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 198c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 1993f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek 2003f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 2013f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 2023f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 204368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 206ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 207ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 208ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 209d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 210d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 211f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 214f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 215f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 216f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 217f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 218f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 219f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 220f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2212455636163fdd18581d7fdae816433f886d88213Mike Stump 222ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 223ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// false otherwise. 2242455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const; 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 24073af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 2414e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 243daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2444e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2494e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2504e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 25111a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2520eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2534e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 25473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 26972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 27272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 28672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 28772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 28872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 28972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 291d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 295898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 296898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 297898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 3017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned TC : 6; 302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 30316ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 30416ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 306124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 307124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 308898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 309f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 310898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 311898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3124b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 31473af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek 3158b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 316a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 323bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 324bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 325bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 326bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 327bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 328bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// routine will need to determine if the size is actually required. 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 336d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 337d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 338d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 339d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 340d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 341d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 34264b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 34364b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 34464b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 34564b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 346d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 347d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 348d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 349d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff 3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 351ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 352e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 353e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 354e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 35596d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff 35696d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 35796d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 35913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 36013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 36113b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 36277a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 36333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 36702f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 36802f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 370f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 374c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 375c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 376c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 377d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 379c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 380ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 381c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 38226d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 38326d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 384befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 38558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 3865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 3877154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 388a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 391bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 392f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 393f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 394c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 395c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 396c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 397c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 398898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 399c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 40099dc91422144483c20d1c7381bc9ac634b646b04Chris Lattner bool isClassType() const; 401c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isStructureType() const; 4024cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 403368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 404368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 405213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 406d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 40714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 40814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 409368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 410368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 411368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 412470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 41314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 41414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 415de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 41672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 4176e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 418898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 419898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 420898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// that its definition somehow depends on a template parameter 421898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 422898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 423063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 42472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4258958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4268958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4278958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4286e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4298958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4308958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 431820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 432820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 433820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian bool hasObjCPointerRepresentation() const; 434820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 435c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 436f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 437f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 438f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 439f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 44072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 44172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 44235366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const PointerType *getAsPointerType() const; 44335366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const BlockPointerType *getAsBlockPointerType() const; 44435366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const ReferenceType *getAsReferenceType() const; 44535366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const LValueReferenceType *getAsLValueReferenceType() const; 44635366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const RValueReferenceType *getAsRValueReferenceType() const; 44735366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const MemberPointerType *getAsMemberPointerType() const; 44835366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const TagType *getAsTagType() const; 44935366a67baa970c287c714c957cf78a4131cf60dTed Kremenek const RecordType *getAsRecordType() const; 450769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 451898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 452769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 453c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 454ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 455c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 456c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4574cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 458213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 459d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 46014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 46114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 46214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 46314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 464368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 465c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 46672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 467a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 468a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian 4691a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 4701a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // replace the specific getAsXXXX methods above. 4711a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 4721a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek 4737532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4747532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 47555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 4762b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4772b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4782b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4792b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 480c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 481c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 482c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 483c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 484c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 485f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 486f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 48714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 48814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 489dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 490769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 491dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 492dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4933830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 494dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 495969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 496dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 501d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 502d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 503d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 5055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 507d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 508d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 509d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 511d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 5139bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 5149bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 5153c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 516c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 51722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 51822b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 51922b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 52022b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 522c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 523f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 524f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const = 0; 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 528f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 529f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 530f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 531f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 532ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 533f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 534f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 535f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 536f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 537f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 53859d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 539ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 540ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 54159d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 542d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 54359d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 54459d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 545d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 546b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 547b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 548b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 549b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 550b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 551ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 552ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 553f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 554d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5554886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 5562455636163fdd18581d7fdae816433f886d88213Mike Stump 557f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 558f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 559ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 560ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5614886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 562ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 563f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 564d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 565f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 566ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5674886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 568ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 569ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 570f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 571f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 572ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 573ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 574ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5755e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor/// QualifierSet - This class is used to collect qualifiers. 576efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// Clang supports five independent qualifiers: 577efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// * C99: const, volatile, and restrict 578efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// * Embedded C (TR18037): address spaces 579efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 5805e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregorclass QualifierSet { 5815e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregorpublic: 5827a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall QualifierSet() : Mask(0) {} 5835e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 5848fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void removeConst() { removeCVR(QualType::Const); } 5858fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void removeVolatile() { removeCVR(QualType::Volatile); } 5868fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void removeRestrict() { removeCVR(QualType::Restrict); } 5877a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void removeCVR(unsigned mask) { Mask &= ~mask; } 5887a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void removeAddressSpace() { setAddressSpace(0); } 5897a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void removeObjCGCAttrType() { setGCAttrType(QualType::GCNone); } 5908fceb57f6980c67bb8f12e29d75736cf057951e8John McCall 5918fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addConst() { addCVR(QualType::Const); } 5928fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addVolatile() { addCVR(QualType::Volatile); } 5938fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addRestrict() { addCVR(QualType::Restrict); } 5947a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void addCVR(unsigned mask) { Mask |= mask; } 5958fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addAddressSpace(unsigned space) { 5968fceb57f6980c67bb8f12e29d75736cf057951e8John McCall assert(space); 5977a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall setAddressSpace(space); 5988fceb57f6980c67bb8f12e29d75736cf057951e8John McCall } 5997a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void addObjCGCAttrType(QualType::GCAttrTypes type) { 6008fceb57f6980c67bb8f12e29d75736cf057951e8John McCall assert(type); 6017a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall setGCAttrType(type); 6027a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall } 6037a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6047a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasConst() const { return Mask & QualType::Const; } 6057a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasVolatile() const { return Mask & QualType::Volatile; } 6067a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasRestrict() const { return Mask & QualType::Restrict; } 6077a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall unsigned getCVRMask() const { return Mask & CVRMask; } 6087a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6097a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasObjCGCAttrType() const { return Mask & GCAttrMask; } 6107a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall QualType::GCAttrTypes getObjCGCAttrType() const { 6117a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall return QualType::GCAttrTypes((Mask & GCAttrMask) >> GCAttrShift); 6128fceb57f6980c67bb8f12e29d75736cf057951e8John McCall } 6138fceb57f6980c67bb8f12e29d75736cf057951e8John McCall 6147a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 6157a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 6167a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6177a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall /// empty() - Return true if there are no qualifiers collected 6187a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall /// in this set. 6198fceb57f6980c67bb8f12e29d75736cf057951e8John McCall bool empty() { 6207a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall return (Mask == 0); 6218fceb57f6980c67bb8f12e29d75736cf057951e8John McCall } 6228fceb57f6980c67bb8f12e29d75736cf057951e8John McCall 6235e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Collect any qualifiers on the given type and return an 6245e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// unqualified type. 6255e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor const Type *strip(QualType QT) { 6267a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall Mask |= QT.getCVRQualifiers(); 6275e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor return strip(QT.getTypePtr()); 6285e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 6295e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6305e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Collect any qualifiers on the given type and return an 6315e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// unqualified type. 6325e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor const Type *strip(const Type* T); 6335e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6345e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Apply the collected qualifiers to the given type. 6355e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QualType apply(QualType QT, ASTContext& C); 6365e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6375e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Apply the collected qualifiers to the given type. 6385e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QualType apply(const Type* T, ASTContext& C) { 6395e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor return apply(QualType(T, 0), C); 6405e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 6417a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6427a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool operator==(QualifierSet& Other) { return Mask == Other.Mask; } 6435e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6445e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregorprivate: 6457a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void setAddressSpace(unsigned space) { 6467a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall assert(space <= MaxAddressSpace); 6477a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall Mask = (Mask & ~AddressSpaceMask) 6487a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall | (((uint32_t) space) << AddressSpaceShift); 6497a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall } 6507a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6517a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void setGCAttrType(QualType::GCAttrTypes type) { 6527a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 6537a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall } 6547a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6557a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall // bits: |0 1 2|3 .. 4|5 .. 31| 6567a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall // |C R V|GCAttr|AddrSpace| 6577a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall uint32_t Mask; 6587a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6597a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t CVRMask = 0x07; 6607a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t GCAttrMask = 0x18; 6617a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t GCAttrShift = 3; 6627a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 6637a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t AddressSpaceShift = 5; 664efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall static const unsigned MaxAddressSpace = QualType::MaxAddressSpace; 6655e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor}; 6665e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6675e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 678f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 679f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 6815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 6842df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 6882ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 6932df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 6945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6958e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 6968e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 6976e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 6986e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 699898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 700e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson Dependent, // This represents the type of a type-dependent expression. 701e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson 702de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 703e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 704de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCId, // This represents the ObjC 'id' type. 705de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClass // This represents the ObjC 'Class' type. 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 7075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 7085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 7095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 710898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor BuiltinType(Kind K) 711898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 712898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 7135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 715e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 717f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 718f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 724f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 725f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 726f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 727f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 728f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 729f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 730f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 731f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 732f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 733f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 734f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 735f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 736f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 737f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 738f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 739f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 740f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 741f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 742f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 743f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 744f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 745f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 752898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Complex, CanonicalPtr, Element->isDependentType()), 753898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 759f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 760f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 76103ed44061df258e74a40383bda849e14b892a8c6Ted Kremenek 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 7705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 7715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 77368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 774bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 77568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 776bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 77968694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 784f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 785f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 78768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 78868694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 7975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 7985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 8015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 8025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 8035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 8045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 8055618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 8065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 807898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 808898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 8095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 8115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 8125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 8135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 8145618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 8155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 816f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 817f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 8185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 8195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 8215618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 8235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 8245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 8265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const Type *T) { 8275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return T->getTypeClass() == BlockPointer; 8285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8295618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 8305618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 8315618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 8327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 83468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 83568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 83668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 8377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 8387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 8397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 84068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 84368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 84468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 846bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 8537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 8547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 8557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 8577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 8587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 8607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 8617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 8627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 8637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 8647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 8667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 867f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 868f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 8697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 8717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 8727c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 8747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 8757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 8777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 8787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 8797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 8807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 8817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 8837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 884f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 885f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 8867c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 8887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 8897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 891f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 892f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 893f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 894f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 895f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 896f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 897f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 898f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 899f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 900f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 901f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 902f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 903f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 904f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 905f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 906f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 907f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 908f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 909f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 910f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 911f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 912f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 913f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 914f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 915f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 916f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 917f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 918f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 919f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 920f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 921f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 922f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 923f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 924f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 925f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 926f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 927f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 928f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9332e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 936898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 937898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 938898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 943fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 944fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 945c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 946ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 947c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 948ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 949c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 950c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 951c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 952c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 953c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff 954fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 956898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 957898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 958898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 959898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 960c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 961c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 962898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 963898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 964898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 965fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 966fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 967fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 968ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 969ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 970ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 971c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 972fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 973fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 974fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 9757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 9767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr || 977c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 978898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 979898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 980fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 981fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 982fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 983fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 9847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 9857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 9867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 9877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 9882e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 989fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 990fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 9910be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 992c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 9937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 9947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 9957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 9967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 9977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 9987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 999fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 1000fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 1001c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 1002f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1003f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1004fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 1005fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 10060be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSize(), 10070be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 1008fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1009fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 10100be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 10110be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1012fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1013fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 10140be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 10150be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1016fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 10177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 10187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArray || 10197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 10207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr; 1021fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1022fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1023fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1024fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 10257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithExprType - This class represents C arrays with a 10267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size specified by means of an integer constant expression. 10277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where 10287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// the element type is 'int' and the size expression is 'sizeof(int)'. 10297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical. 10307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithExprType : public ConstantArrayType { 10317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// SizeExpr - The ICE occurring in the concrete syntax. 10327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *SizeExpr; 10337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 10347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 10357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithExprType(QualType et, QualType can, 10377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, Expr *e, 10387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 10397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 10407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq), 10417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr(e), Brackets(brackets) {} 10427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 10437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void Destroy(ASTContext& C); 10447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 10467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 10477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 10487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 10497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 10507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 10527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 10537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 10557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithExpr; 10567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithExprType *) { return true; } 10587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 10607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithExprTypes."); 10617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 10637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithoutExprType - This class represents C arrays with a 10657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size that was not specified by an integer constant expression, 10667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// but inferred by static semantics. 10677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType. 10687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical: the corresponding canonical type, 10697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// having the size specified in an APInt object, is a ConstantArrayType. 10707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithoutExprType : public ConstantArrayType { 10717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithoutExprType(QualType et, QualType can, 10737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, 10747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 10757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {} 10767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 10777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 10797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 10807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 10817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 10837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithoutExpr; 10847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithoutExprType *) { return true; } 10867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 10887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithoutExprTypes."); 10897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 10917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1092da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1093da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1094da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1095c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 10967e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1097c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 10987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 1099c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 1100c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 1101c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 1102f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1103f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1104c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1105c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const Type *T) { 1106c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return T->getTypeClass() == IncompleteArray; 1107c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1108c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 1109c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1110c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 1111c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1112c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 11130be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 1114c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1115c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 11160be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 11170be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 1118c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 11190be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 11200be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1121c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1122c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 1123c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1124da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 1125da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1126da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 1127da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1128da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1129da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 1130da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 1131da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 1132da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1133da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 1134da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 1135da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 1136da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 1137da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 1138da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 11392e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 1140fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// SizeExpr - An assignment expression. VLA's are only permitted within 1141fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// a function block. 1142b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 11437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 11447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 11457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1146c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 11477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 11487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 11497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 11507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11524b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 11534b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1155c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Expr *getSizeExpr() const { 1156b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 1157b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1158b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 1159b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 11607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 11617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 11627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1164f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1165f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1167fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 1168fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == VariableArray; 11695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1170fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 1171a4cb4525cf4bf8f61299147f22ffc187ed1eac9eTed Kremenek 117292866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 11732bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek 11742bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 1175bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 11762bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1179898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 1180898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 1181898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 1182898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// template<typename T, int Size> 1183898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 1184898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 1185898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 1186898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 1187898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 1188898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 1189898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 1190898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 1191898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 1192898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 1193898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 11947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 11957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 1196898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1197898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DependentSizedArrayType(QualType et, QualType can, Expr *e, 11987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 11997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 12007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 12017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 1202898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 1203898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 1204898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1205898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 1206898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Expr *getSizeExpr() const { 1207898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 1208898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 1209898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 1210898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 12117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 12127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 12137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 1214898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1215f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1216f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1217898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1218898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const Type *T) { 1219898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return T->getTypeClass() == DependentSizedArray; 1220898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1221898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 1222898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1223898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 1224898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1225898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1226bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique DependentSizedArrayTypes."); 1227898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1228898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1229898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1230f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 12319cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 12329cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 12339cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 12349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 12359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 12369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 12379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 12389cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorclass DependentSizedExtVectorType : public Type { 12399cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 12409cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 12419cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 12429cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 12439cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 12449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor DependentSizedExtVectorType(QualType ElementType, QualType can, 12459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr, SourceLocation loc) 12469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor : Type (DependentSizedExtVector, can, true), 12479cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {} 12489cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 12499cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 12509cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 12519cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 1252f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor const Expr *getSizeExpr() const { return SizeExpr; } 12539cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 12549cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 12559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 1256f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1257f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 12589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 12599cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const Type *T) { 12609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return T->getTypeClass() == DependentSizedExtVector; 12619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 12629cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor static bool classof(const DependentSizedExtVectorType *) { return true; } 12639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 12649cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 12659cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 126673322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 126773322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// __attribute__((vector_size(n)), where "n" specifies the vector size in 126873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// bytes. Since the constructor takes the number of vector elements, the 126973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 12705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 127173322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 12725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 127873322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1279898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(Vector, canonType, vecType->isDependentType()), 1280898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(vecType), NumElements(nElements) {} 128173322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1282353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman QualType canonType) 1283898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1284898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumElements(nElements) {} 12855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumElements() const { return NumElements; } 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1291f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1292f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 129573322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 129773322924127c873c13101b705dd823f5539ffa5fSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 129873322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 130173322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 130273322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 130373322924127c873c13101b705dd823f5539ffa5fSteve Naroff static bool classof(const Type *T) { 1304213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1309213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1310213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1311213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1312fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1313fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1314213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1315213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1316213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType(ExtVector, vecType, nElements, canonType) {} 131773322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 131873322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 131988dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 132088dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 132188dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 132288dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 132388dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 132488dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 132588dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 132688dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1327e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1328353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 132988dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1330353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1331353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1332353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1333353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1334353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1335353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1336353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1337353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1338353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1339353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1340353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1341131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1342353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1343131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1344353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1345131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1346353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1347131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1348353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1349131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1350353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1351131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1352353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 135388dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1354e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1355b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 1356b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1357b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1358353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1359b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 1360b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 136188dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1362b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 136388dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 136488dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1365e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1366f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1367f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 136831a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 13697064f5c95bbdb17680d0ea658d4090898c2592d3Steve Naroff static bool classof(const Type *T) { 1370213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return T->getTypeClass() == ExtVector; 137173322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1372213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 137373322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 137473322924127c873c13101b705dd823f5539ffa5fSteve Naroff 13755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 137672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 13775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 13795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 13815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1382971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 138372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1384971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 138572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1386971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1387971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1388971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1389971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1390971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 13912455636163fdd18581d7fdae816433f886d88213Mike Stump 13922455636163fdd18581d7fdae816433f886d88213Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 13932455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NoReturn : 1; 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1398971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 13992455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 14002455636163fdd18581d7fdae816433f886d88213Mike Stump bool noReturn = false) 1401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 14022455636163fdd18581d7fdae816433f886d88213Mike Stump SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn), 14032455636163fdd18581d7fdae816433f886d88213Mike Stump ResultType(res) {} 14045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1405971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 14065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 14092455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const { return NoReturn; } 14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 14135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 14145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 14155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 14175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 141972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 14205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 142172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 14222455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 14232455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn = false) 1424898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 14252455636163fdd18581d7fdae816433f886d88213Mike Stump /*Dependent=*/false, NoReturn) {} 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1430f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1431f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 14342455636163fdd18581d7fdae816433f886d88213Mike Stump Profile(ID, getResultType(), getNoReturnAttr()); 14355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14362455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 14372455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn) { 14382455636163fdd18581d7fdae816433f886d88213Mike Stump ID.AddInteger(NoReturn); 14395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 14435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 144572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 144872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1450465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1451465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1452465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 145372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1454898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1455898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1456898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1457898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1458898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 14594b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1460898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1461898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1462898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1463898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 146472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1465465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1466465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 14672455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned numExs, QualType Canonical, bool NoReturn) 1468898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 14694b4218f48fef71a179c5a8287dae281580faf52fNate Begeman (Result->isDependentType() || 14702455636163fdd18581d7fdae816433f886d88213Mike Stump hasAnyDependentType(ArgArray, numArgs)), NoReturn), 1471465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1472465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1473942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1474465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 14765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1477465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1478465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1479465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1480465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1482465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1484465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1485465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1486465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1487465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1488465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1489465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1490465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1491465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1492465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1493465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1494465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1495942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1496942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1497465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1498465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1499465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1500465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 15024b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 15055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1507942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 15085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1509465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1510465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1511465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1512465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1513465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1514465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1515465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1516465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1517d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson bool hasEmptyExceptionSpec() const { 1518a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson return hasExceptionSpec() && !hasAnyExceptionSpec() && 1519a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1520d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1521465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1523971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 15245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1526942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1527942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1528942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1529942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1530465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1531465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1532465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1533465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1534465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1535465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1536465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1537465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1538465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1539465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1540f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1541f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 15445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 15455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 154672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1547465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 15495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1550942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1551465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1552465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 15532455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NumExceptions, exception_iterator Exs, 15542455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn); 15555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1560c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 1561c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanian TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1562898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 15635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 15645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 15665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 1569a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner 1570a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1571fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1572a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1573a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1574a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1575a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1576a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1578f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1579f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 158172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 15835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 158572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 158672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1587d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 1588dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 1589d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1590d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1591d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 1592d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1593f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1594f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1595d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 159672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 159772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1598d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1599d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1600d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1601d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1602d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 1603898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeOfType(QualType T, QualType can) 160472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1605d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1606d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1607d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1608d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1609d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 1610d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 1611f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1612f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1613d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 161472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1615d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1616d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1618395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 1619395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 1620395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 1621563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1622563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 1623563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 1624563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 1625563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 1626563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1627563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 1628395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 1629395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 1630395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 1631563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 1632563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 1633395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson virtual void getAsStringInternal(std::string &InnerString, 1634395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson const PrintingPolicy &Policy) const; 1635395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1636395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1637395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 1638395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 1639395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 16405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 16410b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 16420b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 16430b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 16440b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 16450b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1646fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 16474b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 16480b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 16492ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 16502ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 16517da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 16522ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 16532ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorpublic: 16540b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 16555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16560b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 16570b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// defined. 16580b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 16590b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 16600b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 1661f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1662f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1663e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 166472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { 166572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 166672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 166872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 166972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 16705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 16715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16725edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 16735edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 16745edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 167549aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1676509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 167772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 167872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 167972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 16802ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 16815edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 16825edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 16835edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 16845edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 16855edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 16865edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 16875edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: This predicate is a helper to QualType/Type. It needs to 16885edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 16895edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // const, it needs to return false. 16905edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 16915edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 16925edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 16935edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 16945edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 16955edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 16962daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 16972daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 16982daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 16992daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 17005edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 17015edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 17025edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 17035edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 17045edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 17055edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1706509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 170772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 17082ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 17095edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 17105edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 17115edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 17125edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 17135edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 17145edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 17152daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 17162daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 17172daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 17182daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 17195edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 17205edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 17215edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1722fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 172376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 1724fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 172576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 1726fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 172772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 172876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 1729fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor QualType Canon) 1730fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 173176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 173272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 173376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1734fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 173576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 173672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1737fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 173872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1739fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1740fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1741fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 174276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 1743fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 1744fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1745f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1746f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 17475edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1748fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 174976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 1750fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1751fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1752fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 175376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Index, bool ParameterPack, 175476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 1755fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1756fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 175776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 1758fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1759fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1760fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 176172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const Type *T) { 176272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return T->getTypeClass() == TemplateTypeParm; 176372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 176472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 176572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1766fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 17677532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 17687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 176955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 17707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 17717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 17727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 17737532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 17747532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 177555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 17767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// a tag type for the instantiation 177755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 17787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 17797532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 17807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 17817532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 17827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregorclass TemplateSpecializationType 178355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 178455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 17857532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief The name of the template being specialized. 17867532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 178755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 178840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 178940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 179055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 179155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 17927532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateSpecializationType(TemplateName T, 17937532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 17947532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 179555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 17965908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 17975908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 179855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 179955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 180055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 180140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 180240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 180340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 180440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor unsigned NumArgs); 180540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1806df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1807df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1808df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1809d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 1810d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 1811df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 181240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 181340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 181440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 181540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 181640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 18177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 18187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 181955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 182040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 182140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *getArgs() const { 182240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 182340808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 182440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 182540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 182655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 182755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 182855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 182955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 183040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 183155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1832f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1833f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 183455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 183555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 183640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor Profile(ID, Template, getArgs(), NumArgs); 183755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 183855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 18397532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 184040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument *Args, unsigned NumArgs); 184155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 184255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor static bool classof(const Type *T) { 18437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return T->getTypeClass() == TemplateSpecialization; 184455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 18457532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 184655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 184755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1848e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1849e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1850e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1851e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1852119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1853119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1854119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1855e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1856ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1857ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1858e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1859e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1860e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1861e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1862ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1863ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1864ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1865ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1866e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1867e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1868e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1869e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1870ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1871ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1872e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1873e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1874e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1875e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1876f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1877f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1878e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1879e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1880ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1881e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1882e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1883ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1884ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 1885ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 1886ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 1887ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 1888e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1889e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const Type *T) { 1890e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return T->getTypeClass() == QualifiedName; 1891e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1892e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 1893e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 1894e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1895d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 1896d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 1897d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 1898d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 1899d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 1900d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 1901d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 1902d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 1903d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 1904d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 1905d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 1906d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 1907d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 1908d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1909d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 1910d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 19111734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor typedef llvm::PointerUnion<const IdentifierInfo *, 19121734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 19131734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1914d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 19151734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 1916d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1917d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1918d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 1919d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1920d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && 1921d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 1922d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1923d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 19241734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 19251734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 19261734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 19271734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && 19281734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 19291734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 19301734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 1931d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 1932d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1933d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 1934d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 1935d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1936d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 19371734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 19381734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 19391734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 19401734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 19411734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 19421734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 19431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const IdentifierInfo *getIdentifier() const { 19441734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const IdentifierInfo *>(); 19451734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 19461734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 19471734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 19481734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 19491734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 19501734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 19511734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 1952d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1953f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 1954f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1955d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1956d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1957d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 1958d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1959d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1960d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 19611734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 1962d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 19631734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 1964d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1965d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1966d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const Type *T) { 1967d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return T->getTypeClass() == Typename; 1968d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1969d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 1970d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 1971d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1972fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1973fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 1974fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 1975fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 1976c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// "NSString<NSCopyable, NSAmazing>". 1977c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 1978a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 1979c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1980c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // List of protocols for this protocol conforming object type 1981c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // List is sorted on protocol name. No protocol is enterred more than once. 1982c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1983c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1984c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceType(ObjCInterfaceDecl *D, 1985c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCProtocolDecl **Protos, unsigned NumP) : 1986c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Type(ObjCInterface, QualType(), /*Dependent=*/false), 1987c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Decl(D), Protocols(Protos, Protos+NumP) { } 19883536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 19893536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 1990a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 1991c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 1992c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 1993c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 1994c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 199514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 1996fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 1997c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// list of protocols qualifying this interface. 1998fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1999c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 2000c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff qual_iterator qual_end() const { return Protocols.end(); } 2001c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff bool qual_empty() const { return Protocols.size() == 0; } 2002c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2003f8910df57799256c1897a8610dc52685729ae90eSteve Naroff virtual void getAsStringInternal(std::string &InnerString, 2004f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 2005c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2006c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 2007c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff static void Profile(llvm::FoldingSetNodeID &ID, 2008c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceDecl *Decl, 2009c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 2010c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 20113536b443bc50d58a79f14fca9b6842541a434854Steve Naroff static bool classof(const Type *T) { 2012c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff return T->getTypeClass() == ObjCInterface; 20133536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 2014a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 20153536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 20163536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 201714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 201814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// and 'Interface <p> *'. 201914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 202014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 202114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// alphabetical order. 202214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 2023f6265efe7e35fb0fba315da6391368aeee1e57c9Steve Naroff QualType PointeeType; // A builtin or interface type. 202414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 202514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List of protocols for this protocol conforming object type 202614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List is sorted on protocol name. No protocol is entered more than once. 202714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 202814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 202914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCObjectPointerType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) : 203014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 203114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff PointeeType(T), Protocols(Protos, Protos+NumP) { } 203214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 203314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 203414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 20358f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // Get the pointee type. Pointee will either be: 20368f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a built-in type (for 'id' and 'Class'). 20378f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - an interface type (for user-defined types). 20388f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a TypedefType whose canonical type is an interface (as in 'T' below). 20398f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // For example: typedef NSObject T; T *var; 204014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 204114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 204214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCInterfaceType *getInterfaceType() const { 204314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return PointeeType->getAsObjCInterfaceType(); 204414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2045de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// getInterfaceDecl - returns an interface decl for user-defined types. 204614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 2047de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 204814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2049de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCIdType - true for "id". 205014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 2051de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 2052de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff !Protocols.size(); 205314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2054de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCClassType - true for "Class". 205514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 2056de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2057de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff !Protocols.size(); 2058de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2059de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedIdType - true for "id <p>". 2060de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCQualifiedIdType() const { 2061de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 2062de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff Protocols.size(); 2063de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2064de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedClassType - true for "Class <p>". 2065470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 2066de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2067de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff Protocols.size(); 206814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 206914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 207014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// list of protocols qualifying this interface. 207114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 207214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 207314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 207414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_end() const { return Protocols.end(); } 207514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool qual_empty() const { return Protocols.size() == 0; } 207614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 207714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 207814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// interface type, or 0 if there are none. 207914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 208014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 208114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 208214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 208314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 208414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff virtual void getAsStringInternal(std::string &InnerString, 208514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const PrintingPolicy &Policy) const; 208614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const Type *T) { 208714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return T->getTypeClass() == ObjCObjectPointer; 208814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 208914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 209014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 2091c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2092611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 20935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2094ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 2095ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 2096f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 2097f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 2098f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 2099f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 2100ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2101ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 2102ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 2103ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 21044243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 21054243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2106c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 21074243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 21088e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 2109f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2110f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 2111ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 2112ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2113611c1fff195d32df97706e0920c92468b2509900Chris Lattner 2114d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 2115d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 2116d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2117d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2118d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 2119d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2120d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 212114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (const ObjCObjectPointerType *PT = CT->getAsObjCObjectPointerType()) 21224ae1f058902ffd92207af678e1c62e43258127c6Fariborz Jahanian return PT->getPointeeType().getObjCGCAttr(); 2123bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 2124d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 21252455636163fdd18581d7fdae816433f886d88213Mike Stump 2126ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 2127ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// false otherwise. 21282455636163fdd18581d7fdae816433f886d88213Mike Stumpinline bool QualType::getNoReturnAttr() const { 21292455636163fdd18581d7fdae816433f886d88213Mike Stump QualType CT = getTypePtr()->getCanonicalTypeInternal(); 21302455636163fdd18581d7fdae816433f886d88213Mike Stump if (const PointerType *PT = getTypePtr()->getAsPointerType()) { 21312455636163fdd18581d7fdae816433f886d88213Mike Stump if (const FunctionType *FT = PT->getPointeeType()->getAsFunctionType()) 21322455636163fdd18581d7fdae816433f886d88213Mike Stump return FT->getNoReturnAttr(); 21332455636163fdd18581d7fdae816433f886d88213Mike Stump } else if (const FunctionType *FT = getTypePtr()->getAsFunctionType()) 21342455636163fdd18581d7fdae816433f886d88213Mike Stump return FT->getNoReturnAttr(); 21352455636163fdd18581d7fdae816433f886d88213Mike Stump 21362455636163fdd18581d7fdae816433f886d88213Mike Stump return false; 21372455636163fdd18581d7fdae816433f886d88213Mike Stump} 2138d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 2139e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 2140e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 2141e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 2142e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 2143e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 2144e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 2145e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2146e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2147ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2148ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2149e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 2150e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2151e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2152e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 2153e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 2154e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 2155e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 2156e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 2157e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2158e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2159ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2160ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2161e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 2162e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2163e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2164e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 2165e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 2166e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 2167e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 2168e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 2169e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 2170e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 2171e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 2172e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 2173e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 217435366a67baa970c287c714c957cf78a4131cf60dTed Kremenek if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 2175e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 2176e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 2177e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 2178e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2179e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2180769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 2181769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 2182769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 21832b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 218435366a67baa970c287c714c957cf78a4131cf60dTed Kremenek if (const PointerType *PT = getAsPointerType()) 21852b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 21862b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 21872b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 21882b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 2189c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 2190c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 2191611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 2192ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 2193611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2194611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 2195ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<PointerType>(CanonicalType.getUnqualifiedType()); 2196611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 219758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 219858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 219958f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 22005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 220175b163f4c832696edf4d66d8ac1ec0ed5ea59e17Mike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 22025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 2203bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 2204bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 2205bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 22067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 22077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 22087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 22097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 22107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 22117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 2212498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 221335366a67baa970c287c714c957cf78a4131cf60dTed Kremenek if (const PointerType* T = getAsPointerType()) 2214498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 2215498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 2216498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 2217498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 2218f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 2219f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 2220f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2221f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 222235366a67baa970c287c714c957cf78a4131cf60dTed Kremenek if (const MemberPointerType* T = getAsMemberPointerType()) 2223f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 2224f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 2225f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 2226f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2227611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 2228ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 2229611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2230c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 2231c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 2232c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2233c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 2234c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 2235c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2236c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 2237c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 2238c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2239898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 2240898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 2241898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2242611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 2243ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 2244611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2245f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 2246c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 2247f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 2248611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 2249ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 2250611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2251213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 2252213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2253611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2254d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 2255d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2256d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 2257a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 2258c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2259368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 2260a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 2261de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2262d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 2263d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 2264d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 2265470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 2266470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2267470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 2268470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 2269470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 227014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 2271de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 227214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 227314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 227414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 227514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 2276de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 227714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 227814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 227914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 2280de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 2281de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return isObjCIdType() || isObjCClassType(); 2282de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 228372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 228472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 228572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 228672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2287e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 2288904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 2289e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 2290e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 2291e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 2292e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 2293e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 2294063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 2295063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 2296063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 2297063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 2298904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 2299904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 23008958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 23018958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 230214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff isObjCInterfaceType() || isObjCObjectPointerType() || 23036e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 23048958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 23058958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 2306820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 230714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return (isObjCInterfaceType() || isObjCObjectPointerType() || 2308820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 2309820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 2310820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 231122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 231222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 231322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 231422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 231522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 231622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 231722caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 231822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 23191a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek 23201a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 23211a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 23221a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 23231a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 23241a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 23251a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek 23261a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 23271a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (!isa<T>(CanonicalType)) { 23281a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // Look through type qualifiers 23291a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (isa<T>(CanonicalType.getUnqualifiedType())) 23301a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return CanonicalType.getUnqualifiedType()->getAs<T>(); 23311a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 23321a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek } 23331a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek 23341a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is a typedef for a pointer type, strip the typedef off without 23351a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 23361a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return cast<T>(getDesugaredType()); 23371a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek} 233822caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 23395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 23405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2342