Type.h revision 1eb4433ac451dc16f4133a88af2d002ac26c58ef
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" 2250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor#include "llvm/Support/type_traits.h" 23fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff#include "llvm/ADT/APSInt.h" 245cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/FoldingSet.h" 255cf243a883872441d73ca49cea7e20de5802629bChris Lattner#include "llvm/ADT/PointerIntPair.h" 261734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor#include "llvm/ADT/PointerUnion.h" 277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::isa; 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast; 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::cast_or_null; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing llvm::dyn_cast_or_null; 33bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattnernamespace clang { class Type; } 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 354e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnernamespace llvm { 364e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner template <typename T> 37daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattner class PointerLikeTypeTraits; 38bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner template<> 39bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner class PointerLikeTypeTraits< ::clang::Type*> { 40bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner public: 41bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 42bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner static inline ::clang::Type *getFromVoidPointer(void *P) { 43bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner return static_cast< ::clang::Type*>(P); 44bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner } 45bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner enum { NumLowBitsAvailable = 3 }; 46bfadf55ba5b736b13cc3e0fbc2b184569bc9f304Chris Lattner }; 474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner} 484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TypedefDecl; 5255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor class TemplateDecl; 5372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor class TemplateTypeParmDecl; 54aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor class NonTypeTemplateParmDecl; 557532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor class TemplateTemplateParmDecl; 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TagDecl; 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class RecordDecl; 5849aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis class CXXRecordDecl; 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class EnumDecl; 6021d50e12c3c412d8457071dc419363b7a7e8b855Ted Kremenek class FieldDecl; 61a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCInterfaceDecl; 62a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCProtocolDecl; 63a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek class ObjCMethodDecl; 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Expr; 65b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek class Stmt; 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class SourceLocation; 6792866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek class StmtIteratorBase; 6840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor class TemplateArgument; 69e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor class QualifiedNameType; 703b4ea54acf01f72f6eb74d96689dda86d950228fDaniel Dunbar struct PrintingPolicy; 7172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 7272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // Provide forward declarations for all of the *Type classes 7372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) class Class##Type; 7472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 75f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// their own: instead each reference to a type stores the qualifiers. This 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// greatly reduces the number of nodes we need to allocate for types (for 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// example we only need one for 'int', 'const int', 'volatile int', 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'const volatile int', etc). 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// As an added efficiency bonus, instead of making this a pair, we just store 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the three bits we care about in the low bits of the pointer. To handle the 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// packing/unpacking, we make QualType be a simple wrapper class that acts like 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// a smart pointer. 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass QualType { 875cf243a883872441d73ca49cea7e20de5802629bChris Lattner llvm::PointerIntPair<Type*, 3> Value; 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Const = 0x1, 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Restrict = 0x2, 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Volatile = 0x4, 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CVRFlags = Const|Restrict|Volatile 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 96d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian enum GCAttrTypes { 97d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian GCNone = 0, 98d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Weak, 99d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Strong 100d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian }; 101efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall 102efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall // 24 bits should be enough for anyone. 103efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall static const unsigned MaxAddressSpace = 0xffffffu; 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1055cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType() {} 1061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1075cf243a883872441d73ca49cea7e20de5802629bChris Lattner QualType(const Type *Ptr, unsigned Quals) 1085cf243a883872441d73ca49cea7e20de5802629bChris Lattner : Value(const_cast<Type*>(Ptr), Quals) {} 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1105cf243a883872441d73ca49cea7e20de5802629bChris Lattner unsigned getCVRQualifiers() const { return Value.getInt(); } 111a3ab4b85f54090927c2dfa2585b9f0e48509e944Chris Lattner void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 1125cf243a883872441d73ca49cea7e20de5802629bChris Lattner Type *getTypePtr() const { return Value.getPointer(); } 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1145cf243a883872441d73ca49cea7e20de5802629bChris Lattner void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static QualType getFromOpaquePtr(void *Ptr) { 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType T; 1175cf243a883872441d73ca49cea7e20de5802629bChris Lattner T.Value.setFromOpaqueValue(Ptr); 1185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T; 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type &operator*() const { 1225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *getTypePtr(); 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *operator->() const { 1265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getTypePtr(); 1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNull - Return true if this QualType doesn't point to a type yet. 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isNull() const { 1315cf243a883872441d73ca49cea7e20de5802629bChris Lattner return getTypePtr() == 0; 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isConstQualified() const { 1355cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Const) ? true : false; 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVolatileQualified() const { 1385cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Volatile) ? true : false; 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRestrictQualified() const { 1415cf243a883872441d73ca49cea7e20de5802629bChris Lattner return (getCVRQualifiers() & Restrict) ? true : false; 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 143b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes 144b381aac9bae6d608c72267dd0ed08ec6369e94e4Nuno Lopes bool isConstant(ASTContext& Ctx) const; 1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1467effa1aceac1219529af23c776835f855b8d905cChris Lattner /// addConst/addVolatile/addRestrict - add the specified type qual to this 1477effa1aceac1219529af23c776835f855b8d905cChris Lattner /// QualType. 1485cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addConst() { Value.setInt(Value.getInt() | Const); } 1495cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1505cf243a883872441d73ca49cea7e20de5802629bChris Lattner void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1525cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1535cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1545cf243a883872441d73ca49cea7e20de5802629bChris Lattner void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 1551c6a38bcea17801e9a4738753aee845381af2b6cSanjiv Gupta 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getQualifiedType(unsigned TQs) const { 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(getTypePtr(), TQs); 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 159c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType getWithAdditionalQualifiers(unsigned TQs) const { 160c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return QualType(getTypePtr(), TQs|getCVRQualifiers()); 161c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 162971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 163971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withConst() const { return getWithAdditionalQualifiers(Const); } 164971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 165971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 167e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getUnqualifiedType() const; 168e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isMoreQualifiedThan(QualType Other) const; 169e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor bool isAtLeastAsQualifiedAs(QualType Other) const; 170e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor QualType getNonReferenceType() const; 1711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1722fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 1732fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type. This takes off typedefs, typeof's etc. If the outer level of 1742fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 1752fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1762fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1772fa8c2598c2615da4639b4e42e9079647bd3aea4Chris Lattner /// concrete. 178969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 17998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// operator==/!= - Indicate whether the specified types and qualifiers are 1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// identical. 18250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator==(const QualType &LHS, const QualType &RHS) { 18350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value == RHS.Value; 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor friend bool operator!=(const QualType &LHS, const QualType &RHS) { 18650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return LHS.Value != RHS.Value; 1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 188d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString() const; 189d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 190d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor std::string getAsString(const PrintingPolicy &Policy) const { 1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer std::string S; 192d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor getAsStringInternal(S, Policy); 1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return S; 1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 195e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner void getAsStringInternal(std::string &Str, 196e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const PrintingPolicy &Policy) const; 1971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 198c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump(const char *s) const; 199c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 2001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2013f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) const { 2023f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek ID.AddPointer(getAsOpaquePtr()); 2033f2dcb1ca8bd2d5d3ccc5c80f4ab06f949d88a89Ted Kremenek } 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 205368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattnerpublic: 2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 207ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// getAddressSpace - Return the address space of this type. 208ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb inline unsigned getAddressSpace() const; 2091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 210d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian /// GCAttrTypesAttr - Returns gc attribute of this type. 211d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian inline QualType::GCAttrTypes getObjCGCAttr() const; 212f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 213f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCWeak true when Type is objc's weak. 214f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCWeak() const { 215f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Weak; 216f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 217f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian 218f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian /// isObjCGCStrong true when Type is objc's strong. 219f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian bool isObjCGCStrong() const { 220f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian return getObjCGCAttr() == Strong; 221f6123ca578eb8aabb76ecce7df6857482017f502Fariborz Jahanian } 2222455636163fdd18581d7fdae816433f886d88213Mike Stump 223ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 224ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// false otherwise. 2252455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const; 2265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end clang. 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// to a specific Type class. 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type<const ::clang::QualType> { 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef ::clang::Type* SimpleType; 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Val.getTypePtr(); 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencertemplate<> struct simplify_type< ::clang::QualType> 2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer : public simplify_type<const ::clang::QualType> {}; 2411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2424e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner// Teach SmallPtrSet that QualType is "basically a pointer". 2434e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnertemplate<> 244daae940507f2e93c6fa12e8062fa958e34cc2d1cChris Lattnerclass PointerLikeTypeTraits<clang::QualType> { 2454e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattnerpublic: 2464e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline void *getAsVoidPointer(clang::QualType P) { 2474e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return P.getAsOpaquePtr(); 2484e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 2494e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner static inline clang::QualType getFromVoidPointer(void *P) { 2504e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner return clang::QualType::getFromOpaquePtr(P); 2514e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner } 25211a7f35c2e3a496342031c2ed721f58e691ebfcaChris Lattner // CVR qualifiers go in low bits. 2530eda3b31a672ea486fa92b9bc49a2c91be856b53Chris Lattner enum { NumLowBitsAvailable = 0 }; 2544e7072872e8e2ed76a4c6933424bffa253896e7eChris Lattner}; 2551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25673af669633e13c813f80cd15ecf3e6414778aee4Ted Kremenek} // end namespace llvm 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Type - This is the base class of the type hierarchy. A central concept 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with types is that each type always has a canonical type. A canonical type 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is the type with any typedef names stripped out of it or the types it 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// references. For example, consider: 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef int foo; 2665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// typedef foo* bar; 2675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int *' 'foo *' 'bar' 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// There will be a Type object created for 'int'. Since int is canonical, its 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 27172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// there is a PointerType that represents 'int*', which, like 'int', is 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 27472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// is also 'int*'. 2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Non-canonical types are useful for emitting diagnostics, without losing 2785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// information about typedefs being used. Canonical types are useful for type 2795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comparisons (they allow by-pointer equality tests) and useful for reasoning 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// about whether something has a particular form (e.g. is a function type), 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// because they implicitly, recursively, strip all typedefs out of a type. 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Types, once created, are immutable. 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Type { 2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum TypeClass { 28872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) Class, 28972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 29072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 29172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor TagFirst = Record, TagLast = Enum 2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 2931bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 2941bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidisprotected: 2951bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis enum { TypeClassBitSize = 6 }; 2961bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType CanonicalType; 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 300898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 301898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool Dependent : 1; 302898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Note that this should stay at the end of the ivars for Type so that 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// subclasses can pack their bitfields into the same word. 3061bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis unsigned TC : TypeClassBitSize; 307898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 30816ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner Type(const Type&); // DO NOT IMPLEMENT. 30916ff705a594697f98b9473f9b7e7d378f331fe4bChris Lattner void operator=(const Type&); // DO NOT IMPLEMENT. 3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 311124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser // silence VC++ warning C4355: 'this' : used in base member initializer list 312124dd7b5777e29ecac006822bd4d4623f0dc4264Hartmut Kaiser Type *this_() { return this; } 313898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Type(TypeClass tc, QualType Canonical, bool dependent) 314f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 315898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Dependent(dependent), TC(tc) {} 316898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual ~Type() {} 3174b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; 3191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3208b9023ba35a86838789e2c9034a6128728c547aaChris Lattnerpublic: 321a8ae51f79d35b7c1822ba4a086176b4a8c862862Hartmut Kaiser TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 3221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object types, function types, and incomplete types. 3271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 328bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// \brief Determines whether the type describes an object in memory. 329bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// 330bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// Note that this definition of object type corresponds to the C++ 331bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// definition of object type, which includes incomplete types, as 332bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// opposed to the C definition (which does not include incomplete 333bad0e656c3732e3539a9cd6525de721d7e47408bDouglas Gregor /// types). 3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isObjectType() const; 3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isIncompleteType - Return true if this is an incomplete type. 3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// A type that can describe objects, but which lacks information needed to 3385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// determine its size (e.g. void, or a fwd declared struct). Clients of this 3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// routine will need to determine if the size is actually required. 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIncompleteType() const; 341d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner 342d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// isIncompleteOrObjectType - Return true if this is an incomplete or object 343d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner /// type, in other words, not a function type. 344d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner bool isIncompleteOrObjectType() const { 345d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner return !isFunctionType(); 346d805bec0fbb98aa10abbb41bfdcb2e2fab1bac96Chris Lattner } 34764b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 34864b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 34964b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl bool isPODType() const; 35064b45f7e0d3167f040841ac2920aead7f080730dSebastian Redl 351d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 352d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff /// types that have a non-constant expression. This does not include "[]". 353d7444aac1af1c2c1d5e5b7467ecf6006ee2d8abeSteve Naroff bool isVariablyModifiedType() const; 3541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Helper methods to distinguish type categories. All type predicates 356ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// operate on the canonical type, ignoring typedefs and qualifiers. 357e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 358e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar /// isSpecificBuiltinType - Test for a particular builtin type. 359e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar bool isSpecificBuiltinType(unsigned K) const; 3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36196d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isIntegerType() does *not* include complex integers (a GCC extension). 36296d2c438f5c9ada8229f7f2ac049d2e9957bc954Steve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 36413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isEnumeralType() const; 36513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isBooleanType() const; 36613b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff bool isCharType() const; 36777a52233f7c0f162672652051bfe78b65ad4f789Douglas Gregor bool isWideCharType() const; 36833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian bool isIntegralType() const; 3691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Floating point categories. 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 37202f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexType() does *not* include complex integers (a GCC extension). 37302f62a9fedbc370fba081303399410a3afdde29fSteve Naroff /// isComplexIntegerType() can be used to test for complex integers. 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isComplexType() const; // C99 6.2.5p11 (complex) 375f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 379c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isVoidType() const; // C99 6.2.5p19 380c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isDerivedType() const; // C99 6.2.5p20 381c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 382d7eb846aaf5ee4a8d22c3cd0796d1e7229d46013Douglas Gregor bool isAggregateType() const; 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 384c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Predicates: Check to see if this type is structurally the specified 385ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // type, ignoring typedefs and qualifiers. 386c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isFunctionType() const; 38726d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 38826d1a40edc612f4c53399427480592101acb0dbeChris Lattner bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 389befee48ff2a1dab236c5700f00ecca1cfdcd5837Chris Lattner bool isPointerType() const; 39058f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff bool isAnyPointerType() const; // Any C pointer or ObjC object pointer 3915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff bool isBlockPointerType() const; 3927154a77e7c1f23418342d3b72836ab504aa7821eSteve Naroff bool isVoidPointerType() const; 393a1d9fdea79ba7bbd71862b9f9f78f5f117331fc7Chris Lattner bool isReferenceType() const; 3947c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isLValueReferenceType() const; 3957c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl bool isRValueReferenceType() const; 396bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner bool isFunctionPointerType() const; 397f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberPointerType() const; 398f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl bool isMemberFunctionPointerType() const; 399c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isArrayType() const; 400c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isConstantArrayType() const; 401c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isIncompleteArrayType() const; 402c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner bool isVariableArrayType() const; 403898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentSizedArrayType() const; 404c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner bool isRecordType() const; 4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isClassType() const; 4061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isStructureType() const; 4074cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff bool isUnionType() const; 408368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isComplexIntegerType() const; // GCC _Complex integer type. 409368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isVectorType() const; // GCC vector type. 410213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman bool isExtVectorType() const; // Extended vector type. 411d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff bool isObjCObjectPointerType() const; // Pointer to *any* ObjC object. 41214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // FIXME: change this to 'raw' interface type, so we can used 'interface' type 41314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for the common case. 414368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCInterfaceType() const; // NSString or NSString<foo> 415368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedInterfaceType() const; // NSString<foo> 416368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner bool isObjCQualifiedIdType() const; // id<foo> 417470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const; // Class<foo> 41814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const; // id 41914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const; // Class 420de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff bool isObjCBuiltinType() const; // 'id' or 'Class' 42172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor bool isTemplateTypeParmType() const; // C++ template type parameter 4226e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl bool isNullPtrType() const; // C++0x nullptr_t 423898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 424898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// isDependentType - Whether this type is a dependent type, meaning 4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// that its definition somehow depends on a template parameter 426898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// (C++ [temp.dep.type]). 427898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor bool isDependentType() const { return Dependent; } 428063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor bool isOverloadableType() const; 42972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 4308958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// hasPointerRepresentation - Whether this type is represented 4318958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// natively as a pointer; this includes pointers, references, block 4328958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar /// pointers, and Objective-C interface, qualified id, and qualified 4336e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl /// interface types, as well as nullptr_t. 4348958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar bool hasPointerRepresentation() const; 4358958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 436820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// hasObjCPointerRepresentation - Whether this type can represent 437820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian /// an objective pointer type for the purpose of GC'ability 4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasObjCPointerRepresentation() const; 439820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 440c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner // Type Checking Functions: Check to see if this type is structurally the 441f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // specified type, ignoring typedefs and qualifiers, and return a pointer to 442f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner // the best type we can. 443f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const BuiltinType *getAsBuiltinType() const; 444f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const FunctionType *getAsFunctionType() const; 44572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionNoProtoType *getAsFunctionNoProtoType() const; 44672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *getAsFunctionProtoType() const; 447769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const RecordType *getAsStructureType() const; 448898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// NOTE: getAs*ArrayType are methods on ASTContext. 449769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek const TypedefType *getAsTypedefType() const; 450c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const RecordType *getAsUnionType() const; 451ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const EnumType *getAsEnumType() const; 452c8629630ce3e7f0da231bf10a4b39240caaac68aChris Lattner const VectorType *getAsVectorType() const; // GCC vector type. 453c6fb90a7246c2d5d3233e70107bf9d8c7c9e535bChris Lattner const ComplexType *getAsComplexType() const; 4544cdec1c3ca80124024a787ce32833fd5b20cbb15Steve Naroff const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 455213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 456d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff const ObjCObjectPointerType *getAsObjCObjectPointerType() const; 45714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // The following is a convenience method that returns an ObjCObjectPointerType 45814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // for object declared using an interface. 45914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; 46014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; 461368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner const ObjCInterfaceType *getAsObjCInterfaceType() const; 462c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceType *getAsObjCQualifiedInterfaceType() const; 46372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor const TemplateTypeParmType *getAsTemplateTypeParmType() const; 464a91d6a6619a91d0ca7102d8ab5678d855f04d850Fariborz Jahanian const CXXRecordDecl *getCXXRecordDeclForPointerType() const; 4651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4661a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // Member-template getAs<specific type>'. This scheme will eventually 4671a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // replace the specific getAsXXXX methods above. 4681a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek template <typename T> const T *getAs() const; 4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateSpecializationType * 4717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor getAsTemplateSpecializationType() const; 4721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4732b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 4742b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner /// interface, return the interface type, otherwise return null. 4752b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 4762b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner 477c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// getArrayElementTypeNoTypeQual - If this is an array type, return the 478c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// element type of the array, potentially with type qualifiers missing. 479c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner /// This method should never be used when type qualifiers are meaningful. 480c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const Type *getArrayElementTypeNoTypeQual() const; 4811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 482f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// getPointeeType - If this is a pointer, ObjC object pointer, or block 483f8910df57799256c1897a8610dc52685729ae90eSteve Naroff /// pointer, this returns the respective pointee. 48414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const; 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 486dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// getDesugaredType - Return the specified type with any "sugar" removed from 487769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek /// the type. This takes off typedefs, typeof's etc. If the outer level of 488dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// the type is already concrete, it returns it unmodified. This is similar 489dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// to getting the canonical type, but it doesn't remove *all* typedefs. For 4903830f68e9e461a1b812b70f93103f8fb4ccb8c40Chris Lattner /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 491dea6146deede4b89a1757d46cd92ebf158659c25Chris Lattner /// concrete. 492969c689d893a248eca4f049f5b89f747e66e4bffDouglas Gregor QualType getDesugaredType(bool ForDisplay = false) const; 4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// More type predicates useful for type checking/promotion 4955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isPromotableIntegerType() const; // C99 6.3.1.1p2 4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isSignedIntegerType - Return true if this is an integer type that is 498d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 499d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// an enum decl which has a signed representation, or a vector of signed 500d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// integer element type. 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isSignedIntegerType() const; 5025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isUnsignedIntegerType - Return true if this is an integer type that is 504d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 505d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// decl which has an unsigned representation, or a vector of unsigned integer 506d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner /// element type. 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isUnsignedIntegerType() const; 508d5bbce4382622feb4ca5978c4bb8fcceb7aaec00Chris Lattner 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isConstantSizeType - Return true if this is not a variable sized type, 5109bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// according to the rules of C99 6.7.5p3. It is not legal to call this on 5119bfa73c5ab7bf4b0e749d04f29da6884e8d5bd9fChris Lattner /// incomplete types. 5123c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman bool isConstantSizeType() const; 513c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 51422b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// isSpecifierType - Returns true if this type can be represented by some 51522b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman /// set of type specifiers. 51622b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman bool isSpecifierType() const; 51722b61e937dcd8ba2e14764c367f975a392ec7da0Eli Friedman 5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getCanonicalTypeInternal() const { return CanonicalType; } 519c36d405a02fab41f6c45cb2bc750d64949742903Chris Lattner void dump() const; 5201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 521f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const = 0; 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *) { return true; } 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 526f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// This supports all kinds of type attributes; including, 527f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// address space qualified types, objective-c's __weak and 528f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian/// __strong attributes. 529ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// 530f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanianclass ExtQualType : public Type, public llvm::FoldingSetNode { 531f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// BaseType - This is the underlying type that this qualifies. All CVR 532f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// qualifiers are stored on the QualType that references this type, so we 533f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner /// can't have any here. 534f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *BaseType; 53559d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian 536ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb /// Address Space ID - The address space ID this type is qualified with. 537ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb unsigned AddressSpace; 53859d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian /// GC __weak/__strong attributes 539d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes GCAttrType; 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54159d16d1402d76a298ab7fc5f362e9d3dfd744aa5Fariborz Jahanian ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 542d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes gcAttr) : 543b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 544b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace(AddrSpace), GCAttrType(gcAttr) { 545b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(!isa<ExtQualType>(BaseType) && 546b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Cannot have ExtQualType of ExtQualType"); 547b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 548ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb friend class ASTContext; // ASTContext creates these. 549ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambpublic: 550f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *getBaseType() const { return BaseType; } 551d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 5524886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian unsigned getAddressSpace() const { return AddressSpace; } 5532455636163fdd18581d7fdae816433f886d88213Mike Stump 5541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 555f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void Profile(llvm::FoldingSetNodeID &ID) { 5584886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian Profile(ID, getBaseType(), AddressSpace, GCAttrType); 559ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 5601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 561d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 562f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner ID.AddPointer(Base); 563ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb ID.AddInteger(AddrSpace); 5644886a4204ff2b20bc226ce70d837de5fcd4a79abFariborz Jahanian ID.AddInteger(gcAttr); 565ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 567f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 568f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian static bool classof(const ExtQualType *) { return true; } 569ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb}; 570ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 571ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 5725e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor/// QualifierSet - This class is used to collect qualifiers. 573efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// Clang supports five independent qualifiers: 574efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// * C99: const, volatile, and restrict 575efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// * Embedded C (TR18037): address spaces 576efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall/// * Objective C: the GC attributes (none, weak, or strong) 5775e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregorclass QualifierSet { 5785e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregorpublic: 5797a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall QualifierSet() : Mask(0) {} 5805e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 5818fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void removeConst() { removeCVR(QualType::Const); } 5828fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void removeVolatile() { removeCVR(QualType::Volatile); } 5838fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void removeRestrict() { removeCVR(QualType::Restrict); } 5847a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void removeCVR(unsigned mask) { Mask &= ~mask; } 5857a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void removeAddressSpace() { setAddressSpace(0); } 5867a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void removeObjCGCAttrType() { setGCAttrType(QualType::GCNone); } 5878fceb57f6980c67bb8f12e29d75736cf057951e8John McCall 5888fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addConst() { addCVR(QualType::Const); } 5898fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addVolatile() { addCVR(QualType::Volatile); } 5908fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addRestrict() { addCVR(QualType::Restrict); } 5917a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void addCVR(unsigned mask) { Mask |= mask; } 5928fceb57f6980c67bb8f12e29d75736cf057951e8John McCall void addAddressSpace(unsigned space) { 5938fceb57f6980c67bb8f12e29d75736cf057951e8John McCall assert(space); 5947a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall setAddressSpace(space); 5958fceb57f6980c67bb8f12e29d75736cf057951e8John McCall } 5967a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void addObjCGCAttrType(QualType::GCAttrTypes type) { 5978fceb57f6980c67bb8f12e29d75736cf057951e8John McCall assert(type); 5987a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall setGCAttrType(type); 5997a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall } 6007a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6017a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasConst() const { return Mask & QualType::Const; } 6027a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasVolatile() const { return Mask & QualType::Volatile; } 6037a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasRestrict() const { return Mask & QualType::Restrict; } 6047a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall unsigned getCVRMask() const { return Mask & CVRMask; } 6057a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6067a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasObjCGCAttrType() const { return Mask & GCAttrMask; } 6077a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall QualType::GCAttrTypes getObjCGCAttrType() const { 6087a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall return QualType::GCAttrTypes((Mask & GCAttrMask) >> GCAttrShift); 6098fceb57f6980c67bb8f12e29d75736cf057951e8John McCall } 6108fceb57f6980c67bb8f12e29d75736cf057951e8John McCall 6117a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool hasAddressSpace() const { return Mask & AddressSpaceMask; } 6127a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; } 6137a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6147a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall /// empty() - Return true if there are no qualifiers collected 6157a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall /// in this set. 6168fceb57f6980c67bb8f12e29d75736cf057951e8John McCall bool empty() { 6177a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall return (Mask == 0); 6188fceb57f6980c67bb8f12e29d75736cf057951e8John McCall } 6198fceb57f6980c67bb8f12e29d75736cf057951e8John McCall 6205e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Collect any qualifiers on the given type and return an 6215e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// unqualified type. 6225e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor const Type *strip(QualType QT) { 6237a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall Mask |= QT.getCVRQualifiers(); 6245e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor return strip(QT.getTypePtr()); 6255e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 6265e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6275e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Collect any qualifiers on the given type and return an 6285e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// unqualified type. 6295e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor const Type *strip(const Type* T); 6305e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6315e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Apply the collected qualifiers to the given type. 6325e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QualType apply(QualType QT, ASTContext& C); 6335e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6345e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor /// Apply the collected qualifiers to the given type. 6355e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QualType apply(const Type* T, ASTContext& C) { 6365e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor return apply(QualType(T, 0), C); 6375e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 6387a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6397a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall bool operator==(QualifierSet& Other) { return Mask == Other.Mask; } 6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6415e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregorprivate: 6427a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void setAddressSpace(unsigned space) { 6437a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall assert(space <= MaxAddressSpace); 6447a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall Mask = (Mask & ~AddressSpaceMask) 6457a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall | (((uint32_t) space) << AddressSpaceShift); 6467a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall } 6477a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6487a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall void setGCAttrType(QualType::GCAttrTypes type) { 6497a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); 6507a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall } 6517a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6527a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall // bits: |0 1 2|3 .. 4|5 .. 31| 6537a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall // |C R V|GCAttr|AddrSpace| 6547a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall uint32_t Mask; 6557a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall 6567a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t CVRMask = 0x07; 6577a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t GCAttrMask = 0x18; 6587a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t GCAttrShift = 3; 6597a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t AddressSpaceMask = ~(CVRMask | GCAttrMask); 6607a1bcdf26d48c2c40e900a973f7ffca45f451526John McCall static const uint32_t AddressSpaceShift = 5; 661efadb7768e7c7418185f5a4010ecd8b21ca9731bJohn McCall static const unsigned MaxAddressSpace = QualType::MaxAddressSpace; 6625e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor}; 6635e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6645e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// BuiltinType - This class is used for builtin types like 'int'. Builtin 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types are always canonical and have a literal name field. 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass BuiltinType : public Type { 6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 6695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum Kind { 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Void, 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Bool, // This is bool and/or _Bool. 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_U, // This is 'char' for targets where char is unsigned. 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UChar, // This is explicitly qualified unsigned char. 675f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16, // This is 'char16_t' for C++. 676f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32, // This is 'char32_t' for C++. 6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UShort, 6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer UInt, 6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULong, 6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ULongLong, 6812df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner UInt128, // __uint128_t 6821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Char_S, // This is 'char' for targets where char is signed. 6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer SChar, // This is explicitly qualified signed char. 6852ff9b4c7c8fed9233a0b8de2e9507368c451aab6Argyrios Kyrtzidis WChar, // This is 'wchar_t' for C++. 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Short, 6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Int, 6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Long, 6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongLong, 6902df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner Int128, // __int128_t 6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6928e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor Float, Double, LongDouble, 6938e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 6946e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl NullPtr, // This is the type of C++0x 'nullptr'. 6956e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 696898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Overload, // This represents the type of an overloaded function declaration. 697e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson Dependent, // This represents the type of a type-dependent expression. 6981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 699de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff UndeducedAuto, // In C++0x, this represents the type of an auto variable 700e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // that has not been deduced yet. 701de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCId, // This represents the ObjC 'id' type. 702de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClass // This represents the ObjC 'Class' type. 7035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind TypeKind; 7065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinType(Kind K) 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 709898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor TypeKind(K) {} 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Kind getKind() const { return TypeKind; } 712e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner const char *getName(const LangOptions &LO) const; 7131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 715f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 7185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const BuiltinType *) { return true; } 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 721f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// FixedWidthIntType - Used for arbitrary width types that we either don't 722f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// want to or can't map to named integer types. These always have a lower 723f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman/// integer rank than builtin types of the same width. 724f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanclass FixedWidthIntType : public Type { 725f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanprivate: 726f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned Width; 727f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool Signed; 728f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanpublic: 729f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 730f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width(W), Signed(S) {} 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 732f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman unsigned getWidth() const { return Width; } 733f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman bool isSigned() const { return Signed; } 734f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman const char *getName() const; 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 737f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 739f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 740f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman static bool classof(const FixedWidthIntType *) { return true; } 741f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman}; 742f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// types (_Complex float etc) as well as the GCC integer complex extensions. 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass ComplexType : public Type, public llvm::FoldingSetNode { 7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType(QualType Element, QualType CanonicalPtr) : 7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(Complex, CanonicalPtr, Element->isDependentType()), 750898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(Element) { 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 7551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 757f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 7581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getElementType()); 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Element.getAsOpaquePtr()); 7645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ComplexType *) { return true; } 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 77068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar/// PointerType - C99 6.7.5.1 - Pointer Declarators. 771bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner/// 77268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass PointerType : public Type, public llvm::FoldingSetNode { 773bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner QualType PointeeType; 7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType(QualType Pointee, QualType CanonicalPtr) : 77668694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 7775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 7801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 782f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78468694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 78568694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Profile(ID, getPointeeType()); 7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 7905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Pointee.getAsOpaquePtr()); 7915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const PointerType *) { return true; } 7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 7975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// BlockPointerType - pointer to a block type. 7985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// This type is to represent types syntactically represented as 7995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// "void (^)(int)", etc. Pointee is required to always be a function type. 8005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// 8015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffclass BlockPointerType : public Type, public llvm::FoldingSetNode { 8025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType PointeeType; // Block is some kind of pointer type 8035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType(QualType Pointee, QualType CanonicalCls) : 8041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 805898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor PointeeType(Pointee) { 8065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff friend class ASTContext; // ASTContext creates these. 8085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffpublic: 8091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the pointee type. Pointee is required to always be a function type. 8115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType getPointeeType() const { return PointeeType; } 8125618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 814f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 8151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 8175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Profile(ID, getPointeeType()); 8185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8195618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 8205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff ID.AddPointer(Pointee.getAsOpaquePtr()); 8215618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 8241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == BlockPointer; 8255618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 8265618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff static bool classof(const BlockPointerType *) { return true; } 8275618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff}; 8285618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 8297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 8305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 83168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbarclass ReferenceType : public Type, public llvm::FoldingSetNode { 83268694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType PointeeType; 83368694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 8347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlprotected: 8357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 8367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Type(tc, CanonicalRef, Referencee->isDependentType()), 83768694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar PointeeType(Referencee) { 8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 84068694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar QualType getPointeeType() const { return PointeeType; } 84168694ada8f4d8f6c4b00ea5b900df96428b28fc8Daniel Dunbar 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 843bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner Profile(ID, getPointeeType()); 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(Referencee.getAsOpaquePtr()); 8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 8507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference || 8517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl T->getTypeClass() == RValueReference; 8527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const ReferenceType *) { return true; } 8547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 8557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 8577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 8587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass LValueReferenceType : public ReferenceType { 8597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 8607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(LValueReference, Referencee, CanonicalRef) { 8617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 8637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 8641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 865f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 8667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 8687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == LValueReference; 8697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const LValueReferenceType *) { return true; } 8717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl}; 8727c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 8747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// 8757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlclass RValueReferenceType : public ReferenceType { 8767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 8777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType(RValueReference, Referencee, CanonicalRef) { 8787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8797c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl friend class ASTContext; // ASTContext creates these 8807c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlpublic: 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 882f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 8837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8847c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const Type *T) { 8857c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return T->getTypeClass() == RValueReference; 8867c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 8877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl static bool classof(const RValueReferenceType *) { return true; } 888f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl}; 889f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 890f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// MemberPointerType - C++ 8.3.3 - Pointers to members 891f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// 892f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlclass MemberPointerType : public Type, public llvm::FoldingSetNode { 893f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType PointeeType; 894f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// The class of which the pointee is a member. Must ultimately be a 895f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl /// RecordType, but could be a typedef or a template parameter too. 896f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class; 897f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 898f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 899f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Type(MemberPointer, CanonicalPtr, 900f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Cls->isDependentType() || Pointee->isDependentType()), 901f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl PointeeType(Pointee), Class(Cls) { 902f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 903f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl friend class ASTContext; // ASTContext creates these. 904f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlpublic: 905f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 906f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType getPointeeType() const { return PointeeType; } 907f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 908f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *getClass() const { return Class; } 909f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 9101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 911f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 912f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 913f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void Profile(llvm::FoldingSetNodeID &ID) { 914f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Profile(ID, getPointeeType(), getClass()); 915f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 916f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 917f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl const Type *Class) { 918f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Pointee.getAsOpaquePtr()); 919f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl ID.AddPointer(Class); 920f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 921f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 922f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const Type *T) { 923f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getTypeClass() == MemberPointer; 924f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 925f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl static bool classof(const MemberPointerType *) { return true; } 9265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 9275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// ArrayType - C99 6.7.5.2 - Array Declarators. 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 9302e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ArrayType : public Type, public llvm::FoldingSetNode { 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 933898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// an array with a static size (e.g. int X[static 4]), or an array 934898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// with a star size (e.g. int X[*]). 935898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// 'static' is only allowed on function parameters. 9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer enum ArraySizeModifier { 9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Normal, Static, Star 9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer }; 9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 940fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff /// ElementType - The element type of the array. 941fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType ElementType; 9421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 943ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 944c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// NOTE: These fields are packed into the bitfields space in the Type class. 945ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek unsigned SizeModifier : 2; 9461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 947c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// IndexTypeQuals - Capture qualifiers in declarations like: 948c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff /// 'int X[static restrict 4]'. For function parameters only. 949c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned IndexTypeQuals : 3; 9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 951fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffprotected: 952898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // C++ [temp.dep.type]p1: 953898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // A type is dependent if it is... 954898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // - an array type constructed from any dependent type or whose 955898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // size is specified by a constant expression that is 956898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // value-dependent, 957c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType(TypeClass tc, QualType et, QualType can, 958c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 959898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 960898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 961898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 962fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 963fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 964fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff QualType getElementType() const { return ElementType; } 965ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek ArraySizeModifier getSizeModifier() const { 966ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek return ArraySizeModifier(SizeModifier); 967ca63fa00786e51c207c829f4182f11a6c6b552beTed Kremenek } 968c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 9691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 970fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const Type *T) { 971fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff return T->getTypeClass() == ConstantArray || 9727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 9737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr || 974c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman T->getTypeClass() == VariableArray || 975898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == IncompleteArray || 976898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor T->getTypeClass() == DependentSizedArray; 977fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 978fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ArrayType *) { return true; } 979fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 980fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 9817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayType - This class represents the canonical version of 9827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// C arrays with a specified constant size. For example, the canonical 9837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element 9847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// type is 'int' and the size is 404. 9852e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass ConstantArrayType : public ArrayType { 986fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff llvm::APInt Size; // Allows us to unique the type. 9871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9880be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 989c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArraySizeModifier sm, unsigned tq) 9907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(ConstantArray, et, can, sm, tq), 9917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Size(size) {} 9927e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorprotected: 9937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayType(TypeClass tc, QualType et, QualType can, 9947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, ArraySizeModifier sm, unsigned tq) 9957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(tc, et, can, sm, tq), Size(size) {} 996fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff friend class ASTContext; // ASTContext creates these. 997fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroffpublic: 998c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const llvm::APInt &getSize() const { return Size; } 9991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1000f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1002fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff void Profile(llvm::FoldingSetNodeID &ID) { 10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, getElementType(), getSize(), 10040be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner getSizeModifier(), getIndexTypeQualifier()); 1005fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1006fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 10070be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 10080be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner unsigned TypeQuals) { 1009fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddPointer(ET.getAsOpaquePtr()); 1010fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff ID.AddInteger(ArraySize.getZExtValue()); 10110be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 10120be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1013fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 10147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 10157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArray || 10167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithExpr || 10177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor T->getTypeClass() == ConstantArrayWithoutExpr; 1018fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff } 1019fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const ConstantArrayType *) { return true; } 1020fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff}; 1021fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 10227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithExprType - This class represents C arrays with a 10237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size specified by means of an integer constant expression. 10247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where 10257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// the element type is 'int' and the size expression is 'sizeof(int)'. 10267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical. 10277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithExprType : public ConstantArrayType { 10287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// SizeExpr - The ICE occurring in the concrete syntax. 10297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *SizeExpr; 10307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 10317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 10327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithExprType(QualType et, QualType can, 10347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, Expr *e, 10357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 10367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 10377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq), 10387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr(e), Brackets(brackets) {} 10397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 10407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void Destroy(ASTContext& C); 10417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 10437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 10447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 10457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 10467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 10477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 10497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 10507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 10527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithExpr; 10537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithExprType *) { return true; } 10557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 10577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithExprTypes."); 10587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 10607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// ConstantArrayWithoutExprType - This class represents C arrays with a 10627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// constant size that was not specified by an integer constant expression, 10637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// but inferred by static semantics. 10647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType. 10657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// These types are non-canonical: the corresponding canonical type, 10667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// having the size specified in an APInt object, is a ConstantArrayType. 10677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorclass ConstantArrayWithoutExprType : public ConstantArrayType { 10687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithoutExprType(QualType et, QualType can, 10707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &size, 10717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 10727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {} 10737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor friend class ASTContext; // ASTContext creates these. 10747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregorpublic: 10767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor virtual void getAsStringInternal(std::string &InnerString, 10777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const PrintingPolicy &Policy) const; 10787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const Type *T) { 10807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return T->getTypeClass() == ConstantArrayWithoutExpr; 10817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor static bool classof(const ConstantArrayWithoutExprType *) { return true; } 10837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 10847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 10857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor assert(0 && "Cannot unique ConstantArrayWithoutExprTypes."); 10867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor } 10877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor}; 10887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1089da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// IncompleteArrayType - This class represents C arrays with an unspecified 1090da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// size. For example 'int A[]' has an IncompleteArrayType where the element 1091da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// type is 'int' and the size is unspecified. 1092c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanclass IncompleteArrayType : public ArrayType { 10937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1094c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType(QualType et, QualType can, 10957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq) 1096c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman : ArrayType(IncompleteArray, et, can, sm, tq) {} 1097c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class ASTContext; // ASTContext creates these. 1098c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedmanpublic: 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1100f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1101c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == IncompleteArray; 1104c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1105c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman static bool classof(const IncompleteArrayType *) { return true; } 11061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1107c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman friend class StmtIteratorBase; 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1109c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void Profile(llvm::FoldingSetNodeID &ID) { 11100be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 1111c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11130be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 11140be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ArraySizeModifier SizeMod, unsigned TypeQuals) { 1115c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ID.AddPointer(ET.getAsOpaquePtr()); 11160be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(SizeMod); 11170be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ID.AddInteger(TypeQuals); 1118c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman } 1119c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman}; 1120c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1121da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// VariableArrayType - This class represents C arrays with a specified size 1122da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 1123da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Since the size expression is an arbitrary expression, we store it as such. 1124da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1125da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 1126da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// should not be: two lexically equivalent variable array types could mean 1127da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// different things, for example, these variables do not have the same type 1128da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// dynamically: 1129da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 1130da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// void foo(int x) { 1131da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Y[x]; 1132da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// ++x; 1133da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// int Z[x]; 1134da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// } 1135da2d71a50fe724c881b148fcc2c05a5e9b56e3a5Chris Lattner/// 11362e7d352dbec06755105237afba183492d31d03cbTed Kremenekclass VariableArrayType : public ArrayType { 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// SizeExpr - An assignment expression. VLA's are only permitted within 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// a function block. 1139b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek Stmt *SizeExpr; 11407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 11417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 11427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1143c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff VariableArrayType(QualType et, QualType can, Expr *e, 11447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArraySizeModifier sm, unsigned tq, 11457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 11467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(VariableArray, et, can, sm, tq), 11477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SizeExpr((Stmt*) e), Brackets(brackets) {} 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 11494b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek virtual void Destroy(ASTContext& C); 11504b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 11521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1153b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // We use C-style casts instead of cast<> here because we do not wish 1154b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek // to have a dependency of Type.h on Stmt.h/Expr.h. 1155b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek return (Expr*) SizeExpr; 1156b3064041583eb134fbf56906728bf752bc65b572Ted Kremenek } 11577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 11587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 11597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1162f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 11631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == VariableArray; 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1167fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff static bool classof(const VariableArrayType *) { return true; } 11681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116992866e2e90f6d93fb95e25a7ac4438e239d89ce6Ted Kremenek friend class StmtIteratorBase; 11701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11712bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek void Profile(llvm::FoldingSetNodeID &ID) { 1172bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner assert(0 && "Cannnot unique VariableArrayTypes."); 11732bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 11755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1176898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// DependentSizedArrayType - This type represents an array type in 1177898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// C++ whose size is a value-dependent expression. For example: 1178898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @code 11791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// template<typename T, int Size> 1180898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// class array { 1181898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// T data[Size]; 1182898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// }; 1183898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// @endcode 1184898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// For these types, we won't actually know what the array bound is 1185898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// until template instantiation occurs, at which point this will 1186898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// become either a ConstantArrayType or a VariableArrayType. 1187898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorclass DependentSizedArrayType : public ArrayType { 118804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASTContext &Context; 11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1190898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// SizeExpr - An assignment expression that will instantiate to the 1191898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// size of the array. 1192898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Stmt *SizeExpr; 11937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// Brackets - The left and right array brackets. 11947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets; 11951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedArrayType(ASTContext &Context, QualType et, QualType can, 119704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Expr *e, ArraySizeModifier sm, unsigned tq, 11987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange brackets) 11997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor : ArrayType(DependentSizedArray, et, can, sm, tq), 120004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} 1201898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class ASTContext; // ASTContext creates these. 1202898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor virtual void Destroy(ASTContext& C); 1203898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1204898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorpublic: 12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *getSizeExpr() const { 1206898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // We use C-style casts instead of cast<> here because we do not wish 1207898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // to have a dependency of Type.h on Stmt.h/Expr.h. 1208898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return (Expr*) SizeExpr; 1209898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 12107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange getBracketsRange() const { return Brackets; } 12117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } 12127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } 12131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1215f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 12161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 12181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedArray; 1219898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1220898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool classof(const DependentSizedArrayType *) { return true; } 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1222898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor friend class StmtIteratorBase; 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1225898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 12261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Profile(ID, Context, getElementType(), 122704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor getSizeModifier(), getIndexTypeQualifier(), getSizeExpr()); 1228898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 12291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 12311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType ET, ArraySizeModifier SizeMod, 123204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor unsigned TypeQuals, Expr *E); 1233898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor}; 1234898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1235f6ddb737cb882ffbf0b75a9abd50b930cc2b9068Douglas Gregor/// DependentSizedExtVectorType - This type represent an extended vector type 12369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// where either the type or size is dependent. For example: 12379cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @code 12389cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// template<typename T, int Size> 12399cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// class vector { 12409cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// typedef T __attribute__((ext_vector_type(Size))) type; 12419cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// } 12429cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor/// @endcode 12432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregorclass DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { 12442ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor ASTContext &Context; 12459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr; 12469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor /// ElementType - The element type of the array. 12479cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType ElementType; 12489cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation loc; 12491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 12512ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType can, Expr *SizeExpr, SourceLocation loc) 12521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type (DependentSizedExtVector, can, true), 12531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 12542ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor loc(loc) {} 12559cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor friend class ASTContext; 12569cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor virtual void Destroy(ASTContext& C); 12579cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 12589cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregorpublic: 12592ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Expr *getSizeExpr() const { return SizeExpr; } 12609cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor QualType getElementType() const { return ElementType; } 12619cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation getAttributeLoc() const { return loc; } 12629cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 12631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1264f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 12651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 12671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == DependentSizedExtVector; 12689cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor } 12691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const DependentSizedExtVectorType *) { return true; } 12702ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 12712ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 12722ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor Profile(ID, Context, getElementType(), getSizeExpr()); 12732ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 12741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12752ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 12762ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType ElementType, Expr *SizeExpr); 12779cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor}; 12781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12799cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 128073322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// VectorType - GCC generic vector type. This type is created using 12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// __attribute__((vector_size(n)), where "n" specifies the vector size in 12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// bytes. Since the constructor takes the number of vector elements, the 128373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// client is responsible for converting the size into the number of elements. 12845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass VectorType : public Type, public llvm::FoldingSetNode { 128573322924127c873c13101b705dd823f5539ffa5fSteve Naroffprotected: 12865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ElementType - The element type of the vector. 12875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ElementType; 12881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumElements - The number of elements in the vector. 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned NumElements; 12911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129273322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType(QualType vecType, unsigned nElements, QualType canonType) : 12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(Vector, canonType, vecType->isDependentType()), 12941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ElementType(vecType), NumElements(nElements) {} 12951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(TypeClass tc, QualType vecType, unsigned nElements, 12961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType canonType) 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 12981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NumElements(nElements) {} 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 13011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getElementType() const { return ElementType; } 13031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned getNumElements() const { return NumElements; } 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1306f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 13071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 130973322924127c873c13101b705dd823f5539ffa5fSteve Naroff Profile(ID, getElementType(), getNumElements(), getTypeClass()); 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 131273322924127c873c13101b705dd823f5539ffa5fSteve Naroff unsigned NumElements, TypeClass TypeClass) { 13135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ElementType.getAsOpaquePtr()); 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddInteger(NumElements); 131573322924127c873c13101b705dd823f5539ffa5fSteve Naroff ID.AddInteger(TypeClass); 131673322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 13171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const VectorType *) { return true; } 13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1323213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// ExtVectorType - Extended vector type. This type is created using 1324213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1325213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1326fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// class enables syntactic extensions, like Vector Components for accessing 1327fcac0fff877a461bc5d5a57e6c6727a4c819d95aSteve Naroff/// points, colors, and textures (modeled after OpenGL Shading Language). 1328213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanclass ExtVectorType : public VectorType { 1329213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType(ExtVector, vecType, nElements, canonType) {} 133173322924127c873c13101b705dd823f5539ffa5fSteve Naroff friend class ASTContext; // ASTContext creates these. 133273322924127c873c13101b705dd823f5539ffa5fSteve Naroffpublic: 133388dca0464804b8b26ae605f89784c927e8493dddChris Lattner static int getPointAccessorIdx(char c) { 133488dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 133588dca0464804b8b26ae605f89784c927e8493dddChris Lattner default: return -1; 133688dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'x': return 0; 133788dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'y': return 1; 133888dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'z': return 2; 133988dca0464804b8b26ae605f89784c927e8493dddChris Lattner case 'w': return 3; 134088dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1341e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 1342353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman static int getNumericAccessorIdx(char c) { 134388dca0464804b8b26ae605f89784c927e8493dddChris Lattner switch (c) { 1344353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman default: return -1; 1345353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '0': return 0; 1346353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '1': return 1; 1347353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '2': return 2; 1348353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '3': return 3; 1349353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '4': return 4; 1350353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '5': return 5; 1351353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '6': return 6; 1352353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '7': return 7; 1353353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '8': return 8; 1354353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case '9': return 9; 1355131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'A': 1356353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'a': return 10; 1357131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'B': 1358353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'b': return 11; 1359131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'C': 1360353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'c': return 12; 1361131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'D': 1362353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'd': return 13; 1363131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'E': 1364353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'e': return 14; 1365131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman case 'F': 1366353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman case 'f': return 15; 136788dca0464804b8b26ae605f89784c927e8493dddChris Lattner } 1368e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 13691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1370b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner static int getAccessorIdx(char c) { 1371b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1372353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman return getNumericAccessorIdx(c); 1373b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 137588dca0464804b8b26ae605f89784c927e8493dddChris Lattner bool isAccessorWithinNumElements(char c) const { 1376b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner if (int idx = getAccessorIdx(c)+1) 137788dca0464804b8b26ae605f89784c927e8493dddChris Lattner return unsigned(idx-1) < NumElements; 137888dca0464804b8b26ae605f89784c927e8493dddChris Lattner return false; 1379e1b31fedbc006e6e4071bbb4f74c6116b56cfa9fSteve Naroff } 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1381f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 138231a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ExtVector; 138573322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1386213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman static bool classof(const ExtVectorType *) { return true; } 138773322924127c873c13101b705dd823f5539ffa5fSteve Naroff}; 138873322924127c873c13101b705dd823f5539ffa5fSteve Naroff 13895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 139072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// class of FunctionNoProtoType and FunctionProtoType. 13915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 13925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass FunctionType : public Type { 13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// SubClassData - This field is owned by the subclass, put here to pack 13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tightly with the ivars in Type. 13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool SubClassData : 1; 1396971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis 139772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1398971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// other bitfields. 139972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor /// The qualifiers are part of FunctionProtoType because... 1400971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1401971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// C++ 8.3.5p4: The return type, the parameter type list and the 1402971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// cv-qualifier-seq, [...], are part of the function type. 1403971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis /// 1404971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned TypeQuals : 3; 14052455636163fdd18581d7fdae816433f886d88213Mike Stump 14062455636163fdd18581d7fdae816433f886d88213Mike Stump /// NoReturn - Indicates if the function type is attribute noreturn. 14072455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NoReturn : 1; 14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // The type returned by the function. 14105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType ResultType; 14115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprotected: 1412971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 14132455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned typeQuals, QualType Canonical, bool Dependent, 14142455636163fdd18581d7fdae816433f886d88213Mike Stump bool noReturn = false) 1415898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, Canonical, Dependent), 14162455636163fdd18581d7fdae816433f886d88213Mike Stump SubClassData(SubclassInfo), TypeQuals(typeQuals), NoReturn(noReturn), 14172455636163fdd18581d7fdae816433f886d88213Mike Stump ResultType(res) {} 14185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getSubClassData() const { return SubClassData; } 1419971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return TypeQuals; } 14205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getResultType() const { return ResultType; } 14232455636163fdd18581d7fdae816433f886d88213Mike Stump bool getNoReturnAttr() const { return NoReturn; } 14245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 14275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto || 14285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer T->getTypeClass() == FunctionProto; 14295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const FunctionType *) { return true; } 14315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 143372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 14345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// no information available about its arguments. 143572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 14362455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType(QualType Result, QualType Canonical, 14372455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn = false) 14381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 14392455636163fdd18581d7fdae816433f886d88213Mike Stump /*Dependent=*/false, NoReturn) {} 14405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 14415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // No additional state past what FunctionType provides. 14431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1445f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 14465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID) { 14482455636163fdd18581d7fdae816433f886d88213Mike Stump Profile(ID, getResultType(), getNoReturnAttr()); 14495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14502455636163fdd18581d7fdae816433f886d88213Mike Stump static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, 14512455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn) { 14522455636163fdd18581d7fdae816433f886d88213Mike Stump ID.AddInteger(NoReturn); 14535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ID.AddPointer(ResultType.getAsOpaquePtr()); 14545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 14551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 14575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionNoProto; 14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 145972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionNoProtoType *) { return true; } 14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 146272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// FunctionProtoType - Represents a prototype with argument type info, e.g. 14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1464465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// arguments, not as having a single void argument. Such a type can have an 1465465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// exception specification, but this specification is not part of the canonical 1466465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl/// type. 146772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1468898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// hasAnyDependentType - Determine whether there are any dependent 1469898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor /// types within the arguments passed in. 1470898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1471898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1472898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (ArgArray[Idx]->isDependentType()) 14734b4218f48fef71a179c5a8287dae281580faf52fNate Begeman return true; 1474898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1475898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1476898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor } 1477898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 147872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1479465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned typeQuals, bool hasExs, 1480465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExs, const QualType *ExArray, 14812455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned numExs, QualType Canonical, bool NoReturn) 1482898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (Result->isDependentType() || 14842455636163fdd18581d7fdae816433f886d88213Mike Stump hasAnyDependentType(ArgArray, numArgs)), NoReturn), 1485465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), 1486465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl AnyExceptionSpec(hasAnyExs) { 1487942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner // Fill in the trailing argument array. 1488465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *ArgInfo = reinterpret_cast<QualType*>(this+1); 14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numArgs; ++i) 14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ArgInfo[i] = ArgArray[i]; 1491465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Fill in the exception array. 1492465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType *Ex = ArgInfo + numArgs; 1493465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl for (unsigned i = 0; i != numExs; ++i) 1494465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl Ex[i] = ExArray[i]; 14955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1496465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 14975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// NumArgs - The number of arguments this function has, not counting '...'. 1498465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumArgs : 20; 1499465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1500465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// NumExceptions - The number of types in the exception spec, if any. 1501465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned NumExceptions : 10; 1502465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1503465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// HasExceptionSpec - Whether this function has an exception spec at all. 1504465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool HasExceptionSpec : 1; 1505465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1506465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// AnyExceptionSpec - Whether this function has a throw(...) spec. 1507465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool AnyExceptionSpec : 1; 1508465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1509942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// ArgInfo - There is an variable size array after the class in memory that 1510942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner /// holds the argument types. 1511465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1512465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// Exceptions - There is another variable size array after ArgInfo that 1513465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl /// holds the exception types. 1514465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 15164b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek 15175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned getNumArgs() const { return NumArgs; } 15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType getArgType(unsigned i) const { 15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(i < NumArgs && "Invalid argument number!"); 1521942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return arg_type_begin()[i]; 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1523465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1524465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec() const { return HasExceptionSpec; } 1525465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec() const { return AnyExceptionSpec; } 1526465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned getNumExceptions() const { return NumExceptions; } 1527465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl QualType getExceptionType(unsigned i) const { 1528465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(i < NumExceptions && "Invalid exception number!"); 1529465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin()[i]; 1530465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 15311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool hasEmptyExceptionSpec() const { 15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return hasExceptionSpec() && !hasAnyExceptionSpec() && 1533a12823f6c0ec9e0e644a9d0ee153e973f49c63fcAnders Carlsson getNumExceptions() == 0; 1534d3fd6bad1249d3f34d71b73e2333fab0db51cce4Anders Carlsson } 1535465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isVariadic() const { return getSubClassData(); } 1537971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer typedef const QualType *arg_type_iterator; 1540942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_begin() const { 1541942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner return reinterpret_cast<const QualType *>(this+1); 1542942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner } 1543942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1544465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1545465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl typedef const QualType *exception_iterator; 1546465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_begin() const { 1547465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // exceptions begin where arguments end 1548465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return arg_type_end(); 1549465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1550465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl exception_iterator exception_end() const { 1551465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl return exception_begin() + NumExceptions; 1552465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl } 1553465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1555f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const Type *T) { 15585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return T->getTypeClass() == FunctionProto; 15595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 156072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const FunctionProtoType *) { return true; } 1561465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 15625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void Profile(llvm::FoldingSetNodeID &ID); 15635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1564942cfd37297528918616d06cd6e4e8bd6e4915a2Chris Lattner arg_type_iterator ArgTys, unsigned NumArgs, 1565465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool isVariadic, unsigned TypeQuals, 1566465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasExceptionSpec, bool anyExceptionSpec, 15672455636163fdd18581d7fdae816433f886d88213Mike Stump unsigned NumExceptions, exception_iterator Exs, 15682455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn); 15695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TypedefType : public Type { 15735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *Decl; 1574c569249ca0ab755ac79d8cbbfcb2bcae19743624Fariborz Jahanianprotected: 15751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1576898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Type(tc, can, can->isDependentType()), Decl(D) { 15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(!isa<TypedefType>(can) && "Invalid canonical type"); 15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class ASTContext; // ASTContext creates these. 15805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TypedefDecl *getDecl() const { return Decl; } 15831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1584a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1585fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor /// potentially looking through *all* consecutive typedefs. This returns the 1586a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// sum of the type qualifiers, so if you have: 1587a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef const int A; 1588a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// typedef volatile A B; 1589a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner /// looking through the typedefs for B will give you "const volatile A". 1590a2c7767ce7d8feb10253f4b650826a20f3324c6fChris Lattner QualType LookThroughTypedefs() const; 15911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1593f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 15945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 159572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 15965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TypedefType *) { return true; } 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 159972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType (GCC extension). 160072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregorclass TypeOfExprType : public Type { 1601d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *TOExpr; 16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1603b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorprotected: 1604dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType(Expr *E, QualType can = QualType()); 1605d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1606d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1607d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff Expr *getUnderlyingExpr() const { return TOExpr; } 16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1610f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1611d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 161272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 161372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const TypeOfExprType *) { return true; } 1614d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 1615d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 16161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclass of TypeOfExprType that is used for canonical, dependent 16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typeof(expr) types. 16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass DependentTypeOfExprType 1619b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : public TypeOfExprType, public llvm::FoldingSetNode { 1620b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor ASTContext &Context; 16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1622b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregorpublic: 16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentTypeOfExprType(ASTContext &Context, Expr *E) 1624b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor : TypeOfExprType(E), Context(Context) { } 16251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1626b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1627b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 1628b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1630b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 1631b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Expr *E); 1632b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor}; 16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1634d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff/// TypeOfType (GCC extension). 1635d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffclass TypeOfType : public Type { 1636d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType TOType; 16371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypeOfType(QualType T, QualType can) 163872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1639d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1640d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff } 1641d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff friend class ASTContext; // ASTContext creates these. 1642d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroffpublic: 1643d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff QualType getUnderlyingType() const { return TOType; } 16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1646f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1647d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 164872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1649d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff static bool classof(const TypeOfType *) { return true; } 1650d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff}; 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1652395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType (C++0x) 1653395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonclass DecltypeType : public Type { 1654395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *E; 16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1656563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to 1657563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr 1658563a03b1338d31c2462def43253a722bc885d384Anders Carlsson // from it. 1659563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType UnderlyingType; 16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16619d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorprotected: 1662563a03b1338d31c2462def43253a722bc885d384Anders Carlsson DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); 1663395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson friend class ASTContext; // ASTContext creates these. 1664395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlssonpublic: 1665395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Expr *getUnderlyingExpr() const { return E; } 1666563a03b1338d31c2462def43253a722bc885d384Anders Carlsson QualType getUnderlyingType() const { return UnderlyingType; } 1667563a03b1338d31c2462def43253a722bc885d384Anders Carlsson 16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1669395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson const PrintingPolicy &Policy) const; 16701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1671395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } 1672395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson static bool classof(const DecltypeType *) { return true; } 1673395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson}; 16741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclass of DecltypeType that is used for canonical, dependent 16761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C++0x decltype types. 16779d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorclass DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { 16789d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor ASTContext &Context; 16791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16809d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregorpublic: 16819d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType(ASTContext &Context, Expr *E); 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16839d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 16849d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Profile(ID, Context, getUnderlyingExpr()); 16859d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 16861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16879d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 16881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *E); 16899d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor}; 16901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass TagType : public Type { 16920b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// Stores the TagDecl associated with this type. The decl will 16930b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// point to the TagDecl that actually defines the entity (or is a 16940b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// definition in progress), if there is such a definition. The 16950b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// single-bit value will be non-zero when this tag is in the 16960b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// process of being defined. 1697fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor mutable llvm::PointerIntPair<TagDecl *, 1> decl; 16984b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek friend class ASTContext; 16990b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor friend class TagDecl; 17002ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 17012ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregorprotected: 17027da97d0f31e1ec16998d3de2cfd2e88fe3736673Douglas Gregor TagType(TypeClass TC, TagDecl *D, QualType can); 17032ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 17050b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor TagDecl *getDecl() const { return decl.getPointer(); } 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17070b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor /// @brief Determines whether this type is in the process of being 17081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// defined. 17090b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor bool isBeingDefined() const { return decl.getInt(); } 17100b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 17110b7a158d120ac8d78c114a823e17eedfec6b6658Douglas Gregor 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1713f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1714e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 171672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 171772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor } 17185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool classof(const TagType *) { return true; } 171972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const RecordType *) { return true; } 172072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor static bool classof(const EnumType *) { return true; } 17215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 17225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17235edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 17245edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of structs/unions/classes. 17255edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass RecordType : public TagType { 172649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidisprotected: 1727509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit RecordType(RecordDecl *D) 172872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 172972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor explicit RecordType(TypeClass TC, RecordDecl *D) 173072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 17312ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 17325edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 17331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17345edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner RecordDecl *getDecl() const { 17355edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 17365edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: This predicate is a helper to QualType/Type. It needs to 17395edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // recursively check all fields for const-ness. If any field is declared 17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // const, it needs to return false. 17415edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner bool hasConstFields() const { return false; } 17425edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 17435edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // FIXME: RecordType needs to check when it is created that all fields are in 17445edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner // the same address space, and return that. 17455edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner unsigned getAddressSpace() const { return 0; } 17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17472daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 17482daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 17492daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 17502daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 17515edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const RecordType *) { return true; } 17525edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 17535edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 17545edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 17555edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner/// to detect TagType objects of enums. 17565edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerclass EnumType : public TagType { 1757509447e7cb9c24a9f2bd149fe95030050b088622Argyrios Kyrtzidis explicit EnumType(EnumDecl *D) 175872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 17592ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor friend class ASTContext; // ASTContext creates these. 17605edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattnerpublic: 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17625edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner EnumDecl *getDecl() const { 17635edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 17645edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner } 17651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17662daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const TagType *T); 17672daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner static bool classof(const Type *T) { 17682daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner return isa<TagType>(T) && classof(cast<TagType>(T)); 17692daa5df1b53f7ef745d724771384409f6f5df5c1Chris Lattner } 17705edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner static bool classof(const EnumType *) { return true; } 17715edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner}; 17725edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 17737da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ElaboratedType - A non-canonical type used to represents uses of 17747da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// elaborated type specifiers in C++. For example: 17757da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// 17767da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// void foo(union MyUnion); 17777da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// ^^^^^^^^^^^^^ 17787da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// 17797da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// At the moment, for efficiency we do not create elaborated types in 17807da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// C, since outside of typedefs all references to structs would 17817da2431c23ef1ee8acb114e39692246e1801afc2John McCall/// necessarily be elaborated. 17827da2431c23ef1ee8acb114e39692246e1801afc2John McCallclass ElaboratedType : public Type, public llvm::FoldingSetNode { 17837da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic: 17847da2431c23ef1ee8acb114e39692246e1801afc2John McCall enum TagKind { 17857da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_struct, 17867da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_union, 17877da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_class, 17887da2431c23ef1ee8acb114e39692246e1801afc2John McCall TK_enum 17897da2431c23ef1ee8acb114e39692246e1801afc2John McCall }; 17907da2431c23ef1ee8acb114e39692246e1801afc2John McCall 17917da2431c23ef1ee8acb114e39692246e1801afc2John McCallprivate: 17927da2431c23ef1ee8acb114e39692246e1801afc2John McCall /// The tag that was used in this elaborated type specifier. 17937da2431c23ef1ee8acb114e39692246e1801afc2John McCall TagKind Tag; 17947da2431c23ef1ee8acb114e39692246e1801afc2John McCall 17957da2431c23ef1ee8acb114e39692246e1801afc2John McCall /// The underlying type. 17967da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType UnderlyingType; 17977da2431c23ef1ee8acb114e39692246e1801afc2John McCall 17987da2431c23ef1ee8acb114e39692246e1801afc2John McCall explicit ElaboratedType(QualType Ty, TagKind Tag, QualType Canon) 17997da2431c23ef1ee8acb114e39692246e1801afc2John McCall : Type(Elaborated, Canon, Canon->isDependentType()), 18007da2431c23ef1ee8acb114e39692246e1801afc2John McCall Tag(Tag), UnderlyingType(Ty) { } 18017da2431c23ef1ee8acb114e39692246e1801afc2John McCall friend class ASTContext; // ASTContext creates these. 18027da2431c23ef1ee8acb114e39692246e1801afc2John McCall 18037da2431c23ef1ee8acb114e39692246e1801afc2John McCallpublic: 18047da2431c23ef1ee8acb114e39692246e1801afc2John McCall TagKind getTagKind() const { return Tag; } 18057da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType getUnderlyingType() const { return UnderlyingType; } 18067da2431c23ef1ee8acb114e39692246e1801afc2John McCall 18077da2431c23ef1ee8acb114e39692246e1801afc2John McCall static const char *getNameForTagKind(TagKind Kind) { 18087da2431c23ef1ee8acb114e39692246e1801afc2John McCall switch (Kind) { 18097da2431c23ef1ee8acb114e39692246e1801afc2John McCall default: assert(0 && "Unknown TagKind!"); 18107da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_struct: return "struct"; 18117da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_union: return "union"; 18127da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_class: return "class"; 18137da2431c23ef1ee8acb114e39692246e1801afc2John McCall case TK_enum: return "enum"; 18147da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 18157da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 18167da2431c23ef1ee8acb114e39692246e1801afc2John McCall 18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 18187da2431c23ef1ee8acb114e39692246e1801afc2John McCall const PrintingPolicy &Policy) const; 18197da2431c23ef1ee8acb114e39692246e1801afc2John McCall 18207da2431c23ef1ee8acb114e39692246e1801afc2John McCall void Profile(llvm::FoldingSetNodeID &ID) { 18217da2431c23ef1ee8acb114e39692246e1801afc2John McCall Profile(ID, getUnderlyingType(), getTagKind()); 18227da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 18237da2431c23ef1ee8acb114e39692246e1801afc2John McCall static void Profile(llvm::FoldingSetNodeID &ID, QualType T, TagKind Tag) { 18247da2431c23ef1ee8acb114e39692246e1801afc2John McCall ID.AddPointer(T.getAsOpaquePtr()); 18257da2431c23ef1ee8acb114e39692246e1801afc2John McCall ID.AddInteger(Tag); 18267da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 18277da2431c23ef1ee8acb114e39692246e1801afc2John McCall 18287da2431c23ef1ee8acb114e39692246e1801afc2John McCall static bool classof(const ElaboratedType*) { return true; } 18297da2431c23ef1ee8acb114e39692246e1801afc2John McCall static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } 18307da2431c23ef1ee8acb114e39692246e1801afc2John McCall}; 18317da2431c23ef1ee8acb114e39692246e1801afc2John McCall 1832fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorclass TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 183376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned Depth : 15; 1834fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned Index : 16; 183576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson unsigned ParameterPack : 1; 1836fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name; 183772c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 18381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP, IdentifierInfo *N, 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Canon) 1840fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 184176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(N) { } 184272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 18431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType(unsigned D, unsigned I, bool PP) 1844fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 184576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Depth(D), Index(I), ParameterPack(PP), Name(0) { } 184672c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1847fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor friend class ASTContext; // ASTContext creates these 184872c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 1849fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregorpublic: 1850fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getDepth() const { return Depth; } 1851fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor unsigned getIndex() const { return Index; } 185276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool isParameterPack() const { return ParameterPack; } 1853fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *getName() const { return Name; } 18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1856f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 18575edb8bfe8472e7d7bf6a82386394ef27359eb846Chris Lattner 1858fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 185976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Profile(ID, Depth, Index, ParameterPack, Name); 1860fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1861fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 18621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 18631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned Index, bool ParameterPack, 186476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson IdentifierInfo *Name) { 1865fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Depth); 1866fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddInteger(Index); 186776e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson ID.AddBoolean(ParameterPack); 1868fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor ID.AddPointer(Name); 1869fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor } 1870fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 18711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateTypeParm; 187372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor } 187472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor static bool classof(const TemplateTypeParmType *T) { return true; } 187572c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor}; 1876fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 18777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Represents the type of a template specialization as written 18787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// in the source code. 187955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// 18807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Template specialization types represent the syntactic form of a 18817532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template-id that refers to a type, e.g., @c vector<int>. Some 18827532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template specialization types are syntactic sugar, whose canonical 18837532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// type will point to some other type node that represents the 18847532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// instantiation or class template specialization. For example, a 188555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// class template specialization type of @c vector<int> will refer to 18861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// a tag type for the instantiation 188755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor/// @c std::vector<int, std::allocator<int>>. 18887532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// 18897532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// Other template specialization types, for which the template name 18907532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// is dependent, may be canonical types. These types are always 18917532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// dependent. 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpclass TemplateSpecializationType 189355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor : public Type, public llvm::FoldingSetNode { 189455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1895828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor // FIXME: Currently needed for profiling expressions; can we avoid this? 1896828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context; 18971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1898828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor /// \brief The name of the template being specialized. 18997532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Template; 190055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 190140808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief - The number of template arguments named in this class 190240808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// template specialization. 190355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned NumArgs; 190455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1905828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateSpecializationType(ASTContext &Context, 1906828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor TemplateName T, 19077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 19087532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, QualType Canon); 190955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19105908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor virtual void Destroy(ASTContext& C); 19115908e9f25bc9a334c99c095e0b1e6a515445be2dDouglas Gregor 191255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor friend class ASTContext; // ASTContext creates these 191355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 191455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregorpublic: 191540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Determine whether any of the given template arguments are 191640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// dependent. 191740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor static bool anyDependentTemplateArguments(const TemplateArgument *Args, 19181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned NumArgs); 191940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 1920df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// \brief Print a template argument list, including the '<' and '>' 1921df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor /// enclosing the template arguments. 1922df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1923d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned NumArgs, 1924d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor const PrintingPolicy &Policy); 1925df667e71b1daadeacb230cf94fc717843f1a138aDouglas Gregor 192640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor typedef const TemplateArgument * iterator; 192740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 192840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator begin() const { return getArgs(); } 192940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor iterator end() const; 193040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 19317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor /// \brief Retrieve the name of the template that we are specializing. 19327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName getTemplateName() const { return Template; } 193355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 193440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the template arguments. 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const TemplateArgument *getArgs() const { 193640808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor return reinterpret_cast<const TemplateArgument *>(this + 1); 193740808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor } 193840808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 193940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor /// \brief Retrieve the number of template arguments. 194055f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor unsigned getNumArgs() const { return NumArgs; } 194155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 194255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \brief Retrieve a specific template argument as a type. 194355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor /// \precondition @c isArgType(Arg) 194440808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor const TemplateArgument &getArg(unsigned Idx) const; 194555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1947f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 194855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 194955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1950828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Profile(ID, Template, getArgs(), NumArgs, Context); 195155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 195255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 1954828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor const TemplateArgument *Args, unsigned NumArgs, 1955828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor ASTContext &Context); 195655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 19571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 19581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == TemplateSpecialization; 195955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor } 19607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor static bool classof(const TemplateSpecializationType *T) { return true; } 196155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor}; 196255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1963e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// \brief Represents a type that was referred to via a qualified 1964e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// name, e.g., N::M::type. 1965e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// 1966e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor/// This type is used to keep track of a type name as written in the 1967119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// source code, including any nested-name-specifiers. The type itself 1968119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// is always "sugar", used to express what was written in the source 1969119057adf21237d53dcd490cec9700dca2465e3eDouglas Gregor/// code but containing no additional semantic information. 1970e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorclass QualifiedNameType : public Type, public llvm::FoldingSetNode { 1971ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief The nested name specifier containing the qualifier. 1972ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *NNS; 1973e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1974e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief The type that this qualified name refers to. 1975e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType; 1976e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1977ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1978ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType CanonType) 1979ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1980ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NNS(NNS), NamedType(NamedType) { } 1981e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1982e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor friend class ASTContext; // ASTContext creates these 1983e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1984e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregorpublic: 1985ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor /// \brief Retrieve the qualification on this type. 1986ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 1987e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1988e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor /// \brief Retrieve the type named by the qualified-id. 1989e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType getNamedType() const { return NamedType; } 1990e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 19911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 1992f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 1993e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1994e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 1995ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor Profile(ID, NNS, NamedType); 1996e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 1997e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1998ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1999ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualType NamedType) { 2000ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor ID.AddPointer(NNS); 2001ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor NamedType.Profile(ID); 2002ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor } 2003e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 20041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 20051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == QualifiedName; 2006e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor } 2007e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor static bool classof(const QualifiedNameType *T) { return true; } 2008e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor}; 2009e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2010d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// \brief Represents a 'typename' specifier that names a type within 2011d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// a dependent type, e.g., "typename T::type". 2012d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// 2013d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// TypenameType has a very similar structure to QualifiedNameType, 2014d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// which also involves a nested-name-specifier following by a type, 2015d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// and (FIXME!) both can even be prefixed by the 'typename' 2016d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// keyword. However, the two types serve very different roles: 2017d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// QualifiedNameType is a non-semantic type that serves only as sugar 2018d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// to show how a particular type was written in the source 2019d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// code. TypenameType, on the other hand, only occurs when the 2020d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// nested-name-specifier is dependent, such that we cannot resolve 2021d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor/// the actual type until after instantiation. 2022d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorclass TypenameType : public Type, public llvm::FoldingSetNode { 2023d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The nested name specifier containing the qualifier. 2024d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *NNS; 2025d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 20261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump typedef llvm::PointerUnion<const IdentifierInfo *, 20271734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *> NameType; 20281734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2029d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief The type that this typename specifier refers to. 20301734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name; 2031d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2032d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 2033d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType CanonType) 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 20351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 2036d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 2037d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2038d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 20391734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 20401734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType) 20411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 20421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(NNS->isDependent() && 20431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "TypenameType requires a dependent nested-name-specifier"); 20441734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 20451734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 2046d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor friend class ASTContext; // ASTContext creates these 2047d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2048d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregorpublic: 2049d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor /// \brief Retrieve the qualification on this type. 2050d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *getQualifier() const { return NNS; } 2051d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 20521734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as an 20531734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// identifier. 20541734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// 20551734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// This routine will return a non-NULL identifier pointer when the 20561734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// form of the original typename was terminated by an identifier, 20571734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// e.g., "typename T::type". 20581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo *getIdentifier() const { 20591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return Name.dyn_cast<const IdentifierInfo *>(); 20601734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 20611734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 20621734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// \brief Retrieve the type named by the typename specifier as a 20631734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor /// type specialization. 20641734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *getTemplateId() const { 20651734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return Name.dyn_cast<const TemplateSpecializationType *>(); 20661734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 2067d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2069f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 2070d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2071d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void Profile(llvm::FoldingSetNodeID &ID) { 2072d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Profile(ID, NNS, Name); 2073d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2074d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2075d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 20761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NameType Name) { 2077d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor ID.AddPointer(NNS); 20781734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor ID.AddPointer(Name.getOpaqueValue()); 2079d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2080d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 20821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == Typename; 2083d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2084d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor static bool classof(const TypenameType *T) { return true; } 2085d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor}; 2086d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2087fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 2088fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// object oriented design. They basically correspond to C++ classes. There 2089fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// are two kinds of interface types, normal interfaces like "NSString" and 2090fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner/// qualified interfaces, which are qualified with a protocol list like 2091c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// "NSString<NSCopyable, NSAmazing>". 2092c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroffclass ObjCInterfaceType : public Type, public llvm::FoldingSetNode { 2093a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *Decl; 2094c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2095c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // List of protocols for this protocol conforming object type 2096c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // List is sorted on protocol name. No protocol is enterred more than once. 2097c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 2098c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff 2099c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceType(ObjCInterfaceDecl *D, 21001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl **Protos, unsigned NumP) : 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Type(ObjCInterface, QualType(), /*Dependent=*/false), 2102c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Decl(D), Protocols(Protos, Protos+NumP) { } 21033536b443bc50d58a79f14fca9b6842541a434854Steve Naroff friend class ASTContext; // ASTContext creates these. 21043536b443bc50d58a79f14fca9b6842541a434854Steve Naroffpublic: 2105a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCInterfaceDecl *getDecl() const { return Decl; } 21061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2107c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 2108c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// interface type, or 0 if there are none. 2109c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 211014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 2111fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner /// qual_iterator and friends: this provides access to the (potentially empty) 2112c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff /// list of protocols qualifying this interface. 2113fb7701df5401fa1f5b3396d269fb33e731a00089Chris Lattner typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 2114c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 2115c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff qual_iterator qual_end() const { return Protocols.end(); } 2116c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff bool qual_empty() const { return Protocols.size() == 0; } 21171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 2119f8910df57799256c1897a8610dc52685729ae90eSteve Naroff const PrintingPolicy &Policy) const; 21201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2121c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff void Profile(llvm::FoldingSetNodeID &ID); 21221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static void Profile(llvm::FoldingSetNodeID &ID, 2123c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff const ObjCInterfaceDecl *Decl, 2124c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 21251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 21271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCInterface; 21283536b443bc50d58a79f14fca9b6842541a434854Steve Naroff } 2129a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek static bool classof(const ObjCInterfaceType *) { return true; } 21303536b443bc50d58a79f14fca9b6842541a434854Steve Naroff}; 21313536b443bc50d58a79f14fca9b6842541a434854Steve Naroff 213214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// ObjCObjectPointerType - Used to represent 'id', 'Interface *', 'id <p>', 213314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// and 'Interface <p> *'. 213414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// 213514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// Duplicate protocols are removed and protocol list is canonicalized to be in 213614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff/// alphabetical order. 213714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffclass ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { 2138f6265efe7e35fb0fba315da6391368aeee1e57c9Steve Naroff QualType PointeeType; // A builtin or interface type. 21391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 214014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List of protocols for this protocol conforming object type 214114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // List is sorted on protocol name. No protocol is entered more than once. 214214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 214314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 214414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCObjectPointerType(QualType T, ObjCProtocolDecl **Protos, unsigned NumP) : 214514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff Type(ObjCObjectPointer, QualType(), /*Dependent=*/false), 214614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff PointeeType(T), Protocols(Protos, Protos+NumP) { } 214714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff friend class ASTContext; // ASTContext creates these. 21481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 214914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffpublic: 21508f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // Get the pointee type. Pointee will either be: 21518f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a built-in type (for 'id' and 'Class'). 21528f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - an interface type (for user-defined types). 21538f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // - a TypedefType whose canonical type is an interface (as in 'T' below). 21548f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff // For example: typedef NSObject T; T *var; 215514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff QualType getPointeeType() const { return PointeeType; } 215614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 21571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ObjCInterfaceType *getInterfaceType() const { 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PointeeType->getAsObjCInterfaceType(); 215914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2160de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// getInterfaceDecl - returns an interface decl for user-defined types. 216114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCInterfaceDecl *getInterfaceDecl() const { 2162de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return getInterfaceType() ? getInterfaceType()->getDecl() : 0; 216314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2164de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCIdType - true for "id". 216514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCIdType() const { 21661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 2167de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff !Protocols.size(); 216814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 2169de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCClassType - true for "Class". 217014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool isObjCClassType() const { 21711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2172de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff !Protocols.size(); 2173de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2174de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedIdType - true for "id <p>". 21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool isObjCQualifiedIdType() const { 21761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCId) && 21771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Protocols.size(); 2178de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 2179de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff /// isObjCQualifiedClassType - true for "Class <p>". 2180470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff bool isObjCQualifiedClassType() const { 21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCClass) && 2182de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff Protocols.size(); 218314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 218414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// qual_iterator and friends: this provides access to the (potentially empty) 218514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// list of protocols qualifying this interface. 218614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 218714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 218814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_begin() const { return Protocols.begin(); } 218914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff qual_iterator qual_end() const { return Protocols.end(); } 219014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff bool qual_empty() const { return Protocols.size() == 0; } 219114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 219214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// getNumProtocols - Return the number of qualifying protocols in this 219314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff /// interface type, or 0 if there are none. 219414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff unsigned getNumProtocols() const { return Protocols.size(); } 219514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 219614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff void Profile(llvm::FoldingSetNodeID &ID); 219714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static void Profile(llvm::FoldingSetNodeID &ID, QualType T, 219814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCProtocolDecl **protocols, unsigned NumProtocols); 21991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void getAsStringInternal(std::string &InnerString, 220014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const PrintingPolicy &Policy) const; 22011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Type *T) { 22021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return T->getTypeClass() == ObjCObjectPointer; 220314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 220414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff static bool classof(const ObjCObjectPointerType *) { return true; } 220514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff}; 22061bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 2207611c1fff195d32df97706e0920c92468b2509900Chris Lattner// Inline function definitions. 22085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2209ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getUnqualifiedType - Return the type without any qualifiers. 2210ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline QualType QualType::getUnqualifiedType() const { 2211f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner Type *TP = getTypePtr(); 2212f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 2213f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian TP = EXTQT->getBaseType(); 2214f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return QualType(TP, 0); 2215ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2216ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 2217ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb/// getAddressSpace - Return the address space of this type. 2218ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lambinline unsigned QualType::getAddressSpace() const { 22194243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner QualType CT = getTypePtr()->getCanonicalTypeInternal(); 22204243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2221c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT->getElementType().getAddressSpace(); 22224243a94b43ef6207938f3023dfcfb804dd545363Chris Lattner if (const RecordType *RT = dyn_cast<RecordType>(CT)) 22238e7dafec4b70303dfaff95151cd06bfc5532720cNate Begeman return RT->getAddressSpace(); 2224f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2225f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return EXTQT->getAddressSpace(); 2226ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return 0; 2227ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 2228611c1fff195d32df97706e0920c92468b2509900Chris Lattner 2229d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian/// getObjCGCAttr - Return the gc attribute of this type. 2230d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanianinline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 2231d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CT = getTypePtr()->getCanonicalTypeInternal(); 2232d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 2233d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return AT->getElementType().getObjCGCAttr(); 2234d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 2235d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return EXTQT->getObjCGCAttr(); 223614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (const ObjCObjectPointerType *PT = CT->getAsObjCObjectPointerType()) 22371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 2238ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian // We most look at all pointer types, not just pointer to interface types. 2239ac423ba85bb59cc7cc1d43081b20d7e8d40355ffFariborz Jahanian if (const PointerType *PT = CT->getAs<PointerType>()) 22401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return PT->getPointeeType().getObjCGCAttr(); 2241bc5e150b6d94cf131f7d01bc715571b741c5b408Chris Lattner return GCNone; 2242d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 22432455636163fdd18581d7fdae816433f886d88213Mike Stump 2244ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// getNoReturnAttr - Returns true if the type has the noreturn attribute, 2245ae92140b542d5c1c096e39e74e59526184819b30Mike Stump /// false otherwise. 22462455636163fdd18581d7fdae816433f886d88213Mike Stumpinline bool QualType::getNoReturnAttr() const { 22472455636163fdd18581d7fdae816433f886d88213Mike Stump QualType CT = getTypePtr()->getCanonicalTypeInternal(); 22486217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getTypePtr()->getAs<PointerType>()) { 22492455636163fdd18581d7fdae816433f886d88213Mike Stump if (const FunctionType *FT = PT->getPointeeType()->getAsFunctionType()) 22502455636163fdd18581d7fdae816433f886d88213Mike Stump return FT->getNoReturnAttr(); 22512455636163fdd18581d7fdae816433f886d88213Mike Stump } else if (const FunctionType *FT = getTypePtr()->getAsFunctionType()) 22522455636163fdd18581d7fdae816433f886d88213Mike Stump return FT->getNoReturnAttr(); 22532455636163fdd18581d7fdae816433f886d88213Mike Stump 22542455636163fdd18581d7fdae816433f886d88213Mike Stump return false; 22552455636163fdd18581d7fdae816433f886d88213Mike Stump} 22561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2257e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isMoreQualifiedThan - Determine whether this type is more 2258e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// qualified than the Other type. For example, "const volatile int" 2259e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// is more qualified than "const int", "volatile int", and 2260e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int". However, it is not more qualified than "const volatile 2261e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int". 2262e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isMoreQualifiedThan(QualType Other) const { 2263e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2264e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2265ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2266ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2267e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 2268e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2269e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2270e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// isAtLeastAsQualifiedAs - Determine whether this type is at last 2271e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// as qualified as the Other type. For example, "const volatile 2272e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int" is at least as qualified as "const int", "volatile int", 2273e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// "int", and "const volatile int". 2274e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 2275e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned MyQuals = this->getCVRQualifiers(); 2276e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor unsigned OtherQuals = Other.getCVRQualifiers(); 2277ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner if (getAddressSpace() != Other.getAddressSpace()) 2278ecca7536488e425417dcb005c39cc15ae1947aabChris Lattner return false; 2279e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return (MyQuals | OtherQuals) == MyQuals; 2280e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2281e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2282e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// getNonReferenceType - If Type is a reference type (e.g., const 2283e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int&), returns the type that the reference refers to ("const 2284e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// int"). Otherwise, returns the type itself. This routine is used 2285e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// throughout Sema to implement C++ 5p6: 2286e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 2287e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// If an expression initially has the type "reference to T" (8.3.2, 2288e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// 8.5.3), the type is adjusted to "T" prior to any further 2289e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// analysis, the expression designates the object or function 2290e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor/// denoted by the reference, and the expression is an lvalue. 2291e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregorinline QualType QualType::getNonReferenceType() const { 22926217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RefType = (*this)->getAs<ReferenceType>()) 2293e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return RefType->getPointeeType(); 2294e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor else 2295e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor return *this; 2296e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor} 2297e0a5d5fe8eab573f7764bf6d2ddb02bee8dceaf9Douglas Gregor 2298769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenekinline const TypedefType* Type::getAsTypedefType() const { 2299769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek return dyn_cast<TypedefType>(this); 2300769c9cfc6e06bd9d8ffe7a4397b939f19b0e4dc3Ted Kremenek} 23012b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattnerinline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 23026217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = getAs<PointerType>()) 23032b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return PT->getPointeeType()->getAsObjCInterfaceType(); 23042b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner return 0; 23052b1cc8be4dda4cd122485be0168b3c43d7dff15fChris Lattner} 23061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2307c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// NOTE: All of these methods use "getUnqualifiedType" to strip off address 2308c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner// space qualifiers if present. 2309611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isFunctionType() const { 2310ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 2311611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2312611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isPointerType() const { 23131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isa<PointerType>(CanonicalType.getUnqualifiedType()); 2314611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 231558f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroffinline bool Type::isAnyPointerType() const { 231658f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff return isPointerType() || isObjCObjectPointerType(); 231758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff} 23185618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroffinline bool Type::isBlockPointerType() const { 23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 23205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 2321bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattnerinline bool Type::isReferenceType() const { 2322bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 2323bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner} 23247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isLValueReferenceType() const { 23257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 23267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 23277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redlinline bool Type::isRValueReferenceType() const { 23287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 23297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 2330498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenekinline bool Type::isFunctionPointerType() const { 23316217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType* T = getAs<PointerType>()) 2332498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return T->getPointeeType()->isFunctionType(); 2333498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek else 2334498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek return false; 2335498b0d1aba38f5ec64d566d1dd9e6be237ecc50fTed Kremenek} 2336f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberPointerType() const { 2337f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 2338f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2339f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlinline bool Type::isMemberFunctionPointerType() const { 23406217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const MemberPointerType* T = getAs<MemberPointerType>()) 2341f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return T->getPointeeType()->isFunctionType(); 2342f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl else 2343f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return false; 2344f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2345611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isArrayType() const { 2346ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 2347611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2348c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isConstantArrayType() const { 2349c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 2350c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2351c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isIncompleteArrayType() const { 2352c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 2353c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2354c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerinline bool Type::isVariableArrayType() const { 2355c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 2356c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2357898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorinline bool Type::isDependentSizedArrayType() const { 2358898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 2359898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 2360611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isRecordType() const { 2361ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<RecordType>(CanonicalType.getUnqualifiedType()); 2362611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2363f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattnerinline bool Type::isAnyComplexType() const { 2364c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 2365f23d364084d1aabea688222780d6fc1dd8c7f78cChris Lattner} 2366611c1fff195d32df97706e0920c92468b2509900Chris Lattnerinline bool Type::isVectorType() const { 2367ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb return isa<VectorType>(CanonicalType.getUnqualifiedType()); 2368611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2369213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemaninline bool Type::isExtVectorType() const { 2370213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 2371611c1fff195d32df97706e0920c92468b2509900Chris Lattner} 2372d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroffinline bool Type::isObjCObjectPointerType() const { 2373d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return isa<ObjCObjectPointerType>(CanonicalType.getUnqualifiedType()); 2374d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 2375a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCInterfaceType() const { 2376c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 2377368eefa081d12f0a265ee90ee8ec61b54168d57dChris Lattner} 2378a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekinline bool Type::isObjCQualifiedIdType() const { 2379de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2380d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return OPT->isObjCQualifiedIdType(); 2381d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return false; 2382d58fabf7ed279be18a5e82617f809c9deff9be67Fariborz Jahanian} 2383470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroffinline bool Type::isObjCQualifiedClassType() const { 2384470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 2385470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return OPT->isObjCQualifiedClassType(); 2386470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff return false; 2387470301bac9c8abfc6b451b3b669c6695a9fd1518Steve Naroff} 238814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCIdType() const { 2389de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 239014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCIdType(); 239114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 239214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 239314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroffinline bool Type::isObjCClassType() const { 2394de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) 239514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return OPT->isObjCClassType(); 239614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return false; 239714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 2398de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroffinline bool Type::isObjCBuiltinType() const { 2399de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return isObjCIdType() || isObjCClassType(); 2400de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff} 240172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregorinline bool Type::isTemplateTypeParmType() const { 240272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 240372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor} 240472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 2405e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbarinline bool Type::isSpecificBuiltinType(unsigned K) const { 2406904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor if (const BuiltinType *BT = getAsBuiltinType()) 2407e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar if (BT->getKind() == (BuiltinType::Kind) K) 2408e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return true; 2409e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar return false; 2410e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar} 2411e00d5c00f35163308a18ec1d3d2b9dfa1ecaf234Daniel Dunbar 2412063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// \brief Determines whether this is a type for which one can define 2413063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor/// an overloaded operator. 2414063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregorinline bool Type::isOverloadableType() const { 2415063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return isDependentType() || isRecordType() || isEnumeralType(); 2416904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor} 2417904eed3f6148758d39a2d3c88f3133274460d645Douglas Gregor 24188958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbarinline bool Type::hasPointerRepresentation() const { 24198958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar return (isPointerType() || isReferenceType() || isBlockPointerType() || 24201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump isObjCInterfaceType() || isObjCObjectPointerType() || 24216e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl isObjCQualifiedInterfaceType() || isNullPtrType()); 24228958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar} 24238958891f5fa1e593c4519a36b3df427ee019d70bDaniel Dunbar 2424820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanianinline bool Type::hasObjCPointerRepresentation() const { 24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return (isObjCInterfaceType() || isObjCObjectPointerType() || 2426820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian isObjCQualifiedInterfaceType()); 2427820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian} 2428820e0203079afd64b0de422832f9e0b31a27c0c8Fariborz Jahanian 242922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// Insertion operator for diagnostics. This allows sending QualType's into a 243022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner/// diagnostic with <<. 243122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 243222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner QualType T) { 243322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 243422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner Diagnostic::ak_qualtype); 243522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DB; 243622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner} 24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24381a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek/// Member-template getAs<specific type>'. 24391a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenektemplate <typename T> const T *Type::getAs() const { 24401a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is directly a T type, return it. 24411a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (const T *Ty = dyn_cast<T>(this)) 24421a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return Ty; 24431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24441a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If the canonical form of this type isn't the right kind, reject it. 24451a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (!isa<T>(CanonicalType)) { 24461a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // Look through type qualifiers 24471a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek if (isa<T>(CanonicalType.getUnqualifiedType())) 24481a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return CanonicalType.getUnqualifiedType()->getAs<T>(); 24491a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return 0; 24501a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek } 24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24521a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // If this is a typedef for a pointer type, strip the typedef off without 24531a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek // losing all typedef information. 24541a1a6e2bd4c5aefd7fd643cf25915f9623a02e59Ted Kremenek return cast<T>(getDesugaredType()); 24551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 245622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner 24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 24585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 2460