Type.h revision 5d0ead717d57405b4a3b34a55b77579ea8b2774e
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The LLVM Compiler Infrastructure 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// This file is distributed under the University of Illinois Open Source 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// License. See LICENSE.TXT for details. 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//===----------------------------------------------------------------------===// 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This file defines the Type interface and subclasses. 11c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci//===----------------------------------------------------------------------===// 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef LLVM_CLANG_AST_TYPE_H 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define LLVM_CLANG_AST_TYPE_H 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/Basic/Diagnostic.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/Basic/IdentifierTable.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/AST/NestedNameSpecifier.h" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/AST/TemplateName.h" 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "llvm/Support/Casting.h" 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "llvm/ADT/APSInt.h" 2323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "llvm/ADT/FoldingSet.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "llvm/ADT/PointerIntPair.h" 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "llvm/ADT/PointerUnion.h" 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using llvm::isa; 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using llvm::cast; 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using llvm::cast_or_null; 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using llvm::dyn_cast; 3123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)using llvm::dyn_cast_or_null; 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace clang { class Type; } 33c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 34c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace llvm { 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) template <typename T> 3623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) class PointerLikeTypeTraits; 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) template<> 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class PointerLikeTypeTraits< ::clang::Type*> { 3923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) public: 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static inline void *getAsVoidPointer(::clang::Type *P) { return P; } 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static inline ::clang::Type *getFromVoidPointer(void *P) { 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return static_cast< ::clang::Type*>(P); 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) enum { NumLowBitsAvailable = 3 }; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 4623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 4723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace clang { 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class ASTContext; 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class TypedefDecl; 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class TemplateDecl; 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class TemplateTypeParmDecl; 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class NonTypeTemplateParmDecl; 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class TemplateTemplateParmDecl; 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class TagDecl; 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class RecordDecl; 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class CXXRecordDecl; 58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) class EnumDecl; 59f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) class FieldDecl; 60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) class ObjCInterfaceDecl; 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class ObjCProtocolDecl; 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class ObjCMethodDecl; 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class Expr; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class Stmt; 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class SourceLocation; 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class StmtIteratorBase; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) class TemplateArgument; 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci class QualifiedNameType; 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Provide forward declarations for all of the *Type classes 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define TYPE(Class, Base) class Class##Type; 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "clang/AST/TypeNodes.def" 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 7523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)/// their own: instead each reference to a type stores the qualifiers. This 7623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)/// greatly reduces the number of nodes we need to allocate for types (for 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// example we only need one for 'int', 'const int', 'volatile int', 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// 'const volatile int', etc). 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/// 80f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// As an added efficiency bonus, instead of making this a pair, we just store 81f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// the three bits we care about in the low bits of the pointer. To handle the 82f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// packing/unpacking, we make QualType be a simple wrapper class that acts like 83f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/// a smart pointer. 84f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class QualType { 85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) llvm::PointerIntPair<Type*, 3> Value; 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public: 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Const = 0x1, 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Restrict = 0x2, 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Volatile = 0x4, 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CVRFlags = Const|Restrict|Volatile 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 93c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 9423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) enum GCAttrTypes { 9523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) GCNone = 0, 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Weak, 97c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Strong 98c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch }; 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType() {} 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType(const Type *Ptr, unsigned Quals) 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : Value(const_cast<Type*>(Ptr), Quals) {} 104f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 105f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) unsigned getCVRQualifiers() const { return Value.getInt(); } 106f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 107f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) Type *getTypePtr() const { return Value.getPointer(); } 108f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 109f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) static QualType getFromOpaquePtr(void *Ptr) { 111f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) QualType T; 112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) T.Value.setFromOpaqueValue(Ptr); 113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return T; 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Type &operator*() const { 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return *getTypePtr(); 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Type *operator->() const { 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return getTypePtr(); 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// isNull - Return true if this QualType doesn't point to a type yet. 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isNull() const { 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return getTypePtr() == 0; 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isConstQualified() const { 13023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) return (getCVRQualifiers() & Const) ? true : false; 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isVolatileQualified() const { 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return (getCVRQualifiers() & Volatile) ? true : false; 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isRestrictQualified() const { 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return (getCVRQualifiers() & Restrict) ? true : false; 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isConstant(ASTContext& Ctx) const; 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// addConst/addVolatile/addRestrict - add the specified type qual to this 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// QualType. 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void addConst() { Value.setInt(Value.getInt() | Const); } 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void removeConst() { Value.setInt(Value.getInt() & ~Const); } 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 15023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType getQualifiedType(unsigned TQs) const { 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return QualType(getTypePtr(), TQs); 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType getWithAdditionalQualifiers(unsigned TQs) const { 1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return QualType(getTypePtr(), TQs|getCVRQualifiers()); 15623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) } 15723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType withConst() const { return getWithAdditionalQualifiers(Const); } 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType getUnqualifiedType() const; 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isMoreQualifiedThan(QualType Other) const; 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool isAtLeastAsQualifiedAs(QualType Other) const; 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType getNonReferenceType() const; 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// getDesugaredType - Return the specified type with any "sugar" removed from 16823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) /// the type. This takes off typedefs, typeof's etc. If the outer level of 16923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) /// the type is already concrete, it returns it unmodified. This is similar 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// to getting the canonical type, but it doesn't remove *all* typedefs. For 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// concrete. 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) QualType getDesugaredType(bool ForDisplay = false) const; 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// operator==/!= - Indicate whether the specified types and qualifiers are 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// identical. 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool operator==(const QualType &RHS) const { 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return Value == RHS.Value; 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 18023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) bool operator!=(const QualType &RHS) const { 18123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) return Value != RHS.Value; 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string getAsString() const { 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string S; 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) getAsStringInternal(S); 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return S; 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void getAsStringInternal(std::string &Str) const; 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void dump(const char *s) const; 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void dump() const; 19223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 19323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) void Profile(llvm::FoldingSetNodeID &ID) const { 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ID.AddPointer(getAsOpaquePtr()); 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 19723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)public: 19823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) /// getAddressSpace - Return the address space of this type. 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) inline unsigned getAddressSpace() const; 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 202 /// GCAttrTypesAttr - Returns gc attribute of this type. 203 inline QualType::GCAttrTypes getObjCGCAttr() const; 204 205 /// isObjCGCWeak true when Type is objc's weak. 206 bool isObjCGCWeak() const { 207 return getObjCGCAttr() == Weak; 208 } 209 210 /// isObjCGCStrong true when Type is objc's strong. 211 bool isObjCGCStrong() const { 212 return getObjCGCAttr() == Strong; 213 } 214}; 215 216} // end clang. 217 218namespace llvm { 219/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 220/// to a specific Type class. 221template<> struct simplify_type<const ::clang::QualType> { 222 typedef ::clang::Type* SimpleType; 223 static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 224 return Val.getTypePtr(); 225 } 226}; 227template<> struct simplify_type< ::clang::QualType> 228 : public simplify_type<const ::clang::QualType> {}; 229 230// Teach SmallPtrSet that QualType is "basically a pointer". 231template<> 232class PointerLikeTypeTraits<clang::QualType> { 233public: 234 static inline void *getAsVoidPointer(clang::QualType P) { 235 return P.getAsOpaquePtr(); 236 } 237 static inline clang::QualType getFromVoidPointer(void *P) { 238 return clang::QualType::getFromOpaquePtr(P); 239 } 240 // CVR qualifiers go in low bits. 241 enum { NumLowBitsAvailable = 0 }; 242}; 243} // end namespace llvm 244 245namespace clang { 246 247/// Type - This is the base class of the type hierarchy. A central concept 248/// with types is that each type always has a canonical type. A canonical type 249/// is the type with any typedef names stripped out of it or the types it 250/// references. For example, consider: 251/// 252/// typedef int foo; 253/// typedef foo* bar; 254/// 'int *' 'foo *' 'bar' 255/// 256/// There will be a Type object created for 'int'. Since int is canonical, its 257/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 258/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next 259/// there is a PointerType that represents 'int*', which, like 'int', is 260/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 261/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type 262/// is also 'int*'. 263/// 264/// Non-canonical types are useful for emitting diagnostics, without losing 265/// information about typedefs being used. Canonical types are useful for type 266/// comparisons (they allow by-pointer equality tests) and useful for reasoning 267/// about whether something has a particular form (e.g. is a function type), 268/// because they implicitly, recursively, strip all typedefs out of a type. 269/// 270/// Types, once created, are immutable. 271/// 272class Type { 273public: 274 enum TypeClass { 275#define TYPE(Class, Base) Class, 276#define ABSTRACT_TYPE(Class, Base) 277#include "clang/AST/TypeNodes.def" 278 TagFirst = Record, TagLast = Enum 279 }; 280 281private: 282 QualType CanonicalType; 283 284 /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 285 bool Dependent : 1; 286 287 /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 288 /// Note that this should stay at the end of the ivars for Type so that 289 /// subclasses can pack their bitfields into the same word. 290 unsigned TC : 5; 291 292 Type(const Type&); // DO NOT IMPLEMENT. 293 void operator=(const Type&); // DO NOT IMPLEMENT. 294protected: 295 // silence VC++ warning C4355: 'this' : used in base member initializer list 296 Type *this_() { return this; } 297 Type(TypeClass tc, QualType Canonical, bool dependent) 298 : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 299 Dependent(dependent), TC(tc) {} 300 virtual ~Type() {} 301 virtual void Destroy(ASTContext& C); 302 friend class ASTContext; 303 304public: 305 TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 306 307 bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 308 309 /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 310 /// object types, function types, and incomplete types. 311 312 /// \brief Determines whether the type describes an object in memory. 313 /// 314 /// Note that this definition of object type corresponds to the C++ 315 /// definition of object type, which includes incomplete types, as 316 /// opposed to the C definition (which does not include incomplete 317 /// types). 318 bool isObjectType() const; 319 320 /// isIncompleteType - Return true if this is an incomplete type. 321 /// A type that can describe objects, but which lacks information needed to 322 /// determine its size (e.g. void, or a fwd declared struct). Clients of this 323 /// routine will need to determine if the size is actually required. 324 bool isIncompleteType() const; 325 326 /// isIncompleteOrObjectType - Return true if this is an incomplete or object 327 /// type, in other words, not a function type. 328 bool isIncompleteOrObjectType() const { 329 return !isFunctionType(); 330 } 331 332 /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 333 bool isPODType() const; 334 335 /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 336 /// types that have a non-constant expression. This does not include "[]". 337 bool isVariablyModifiedType() const; 338 339 /// Helper methods to distinguish type categories. All type predicates 340 /// operate on the canonical type, ignoring typedefs and qualifiers. 341 342 /// isSpecificBuiltinType - Test for a particular builtin type. 343 bool isSpecificBuiltinType(unsigned K) const; 344 345 /// isIntegerType() does *not* include complex integers (a GCC extension). 346 /// isComplexIntegerType() can be used to test for complex integers. 347 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 348 bool isEnumeralType() const; 349 bool isBooleanType() const; 350 bool isCharType() const; 351 bool isWideCharType() const; 352 bool isIntegralType() const; 353 354 /// Floating point categories. 355 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 356 /// isComplexType() does *not* include complex integers (a GCC extension). 357 /// isComplexIntegerType() can be used to test for complex integers. 358 bool isComplexType() const; // C99 6.2.5p11 (complex) 359 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 360 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 361 bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 362 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 363 bool isVoidType() const; // C99 6.2.5p19 364 bool isDerivedType() const; // C99 6.2.5p20 365 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 366 bool isAggregateType() const; 367 368 // Type Predicates: Check to see if this type is structurally the specified 369 // type, ignoring typedefs and qualifiers. 370 bool isFunctionType() const; 371 bool isFunctionNoProtoType() const { return getAsFunctionNoProtoType() != 0; } 372 bool isFunctionProtoType() const { return getAsFunctionProtoType() != 0; } 373 bool isPointerType() const; 374 bool isBlockPointerType() const; 375 bool isReferenceType() const; 376 bool isLValueReferenceType() const; 377 bool isRValueReferenceType() const; 378 bool isFunctionPointerType() const; 379 bool isMemberPointerType() const; 380 bool isMemberFunctionPointerType() const; 381 bool isArrayType() const; 382 bool isConstantArrayType() const; 383 bool isIncompleteArrayType() const; 384 bool isVariableArrayType() const; 385 bool isDependentSizedArrayType() const; 386 bool isRecordType() const; 387 bool isClassType() const; 388 bool isStructureType() const; 389 bool isUnionType() const; 390 bool isComplexIntegerType() const; // GCC _Complex integer type. 391 bool isVectorType() const; // GCC vector type. 392 bool isExtVectorType() const; // Extended vector type. 393 bool isObjCInterfaceType() const; // NSString or NSString<foo> 394 bool isObjCQualifiedInterfaceType() const; // NSString<foo> 395 bool isObjCQualifiedIdType() const; // id<foo> 396 bool isTemplateTypeParmType() const; // C++ template type parameter 397 bool isNullPtrType() const; // C++0x nullptr_t 398 399 /// isDependentType - Whether this type is a dependent type, meaning 400 /// that its definition somehow depends on a template parameter 401 /// (C++ [temp.dep.type]). 402 bool isDependentType() const { return Dependent; } 403 bool isOverloadableType() const; 404 405 /// hasPointerRepresentation - Whether this type is represented 406 /// natively as a pointer; this includes pointers, references, block 407 /// pointers, and Objective-C interface, qualified id, and qualified 408 /// interface types, as well as nullptr_t. 409 bool hasPointerRepresentation() const; 410 411 /// hasObjCPointerRepresentation - Whether this type can represent 412 /// an objective pointer type for the purpose of GC'ability 413 bool hasObjCPointerRepresentation() const; 414 415 // Type Checking Functions: Check to see if this type is structurally the 416 // specified type, ignoring typedefs and qualifiers, and return a pointer to 417 // the best type we can. 418 const BuiltinType *getAsBuiltinType() const; 419 const FunctionType *getAsFunctionType() const; 420 const FunctionNoProtoType *getAsFunctionNoProtoType() const; 421 const FunctionProtoType *getAsFunctionProtoType() const; 422 const PointerType *getAsPointerType() const; 423 const BlockPointerType *getAsBlockPointerType() const; 424 const ReferenceType *getAsReferenceType() const; 425 const LValueReferenceType *getAsLValueReferenceType() const; 426 const RValueReferenceType *getAsRValueReferenceType() const; 427 const MemberPointerType *getAsMemberPointerType() const; 428 const TagType *getAsTagType() const; 429 const RecordType *getAsRecordType() const; 430 const RecordType *getAsStructureType() const; 431 /// NOTE: getAs*ArrayType are methods on ASTContext. 432 const TypedefType *getAsTypedefType() const; 433 const RecordType *getAsUnionType() const; 434 const EnumType *getAsEnumType() const; 435 const VectorType *getAsVectorType() const; // GCC vector type. 436 const ComplexType *getAsComplexType() const; 437 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 438 const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 439 const ObjCInterfaceType *getAsObjCInterfaceType() const; 440 const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 441 const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 442 const TemplateTypeParmType *getAsTemplateTypeParmType() const; 443 444 const TemplateSpecializationType * 445 getAsTemplateSpecializationType() const; 446 447 /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 448 /// interface, return the interface type, otherwise return null. 449 const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 450 451 /// getArrayElementTypeNoTypeQual - If this is an array type, return the 452 /// element type of the array, potentially with type qualifiers missing. 453 /// This method should never be used when type qualifiers are meaningful. 454 const Type *getArrayElementTypeNoTypeQual() const; 455 456 /// getDesugaredType - Return the specified type with any "sugar" removed from 457 /// the type. This takes off typedefs, typeof's etc. If the outer level of 458 /// the type is already concrete, it returns it unmodified. This is similar 459 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 460 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 461 /// concrete. 462 QualType getDesugaredType(bool ForDisplay = false) const; 463 464 /// More type predicates useful for type checking/promotion 465 bool isPromotableIntegerType() const; // C99 6.3.1.1p2 466 467 /// isSignedIntegerType - Return true if this is an integer type that is 468 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 469 /// an enum decl which has a signed representation, or a vector of signed 470 /// integer element type. 471 bool isSignedIntegerType() const; 472 473 /// isUnsignedIntegerType - Return true if this is an integer type that is 474 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 475 /// decl which has an unsigned representation, or a vector of unsigned integer 476 /// element type. 477 bool isUnsignedIntegerType() const; 478 479 /// isConstantSizeType - Return true if this is not a variable sized type, 480 /// according to the rules of C99 6.7.5p3. It is not legal to call this on 481 /// incomplete types. 482 bool isConstantSizeType() const; 483 484 QualType getCanonicalTypeInternal() const { return CanonicalType; } 485 void dump() const; 486 virtual void getAsStringInternal(std::string &InnerString) const = 0; 487 static bool classof(const Type *) { return true; } 488}; 489 490/// ExtQualType - TR18037 (C embedded extensions) 6.2.5p26 491/// This supports all kinds of type attributes; including, 492/// address space qualified types, objective-c's __weak and 493/// __strong attributes. 494/// 495class ExtQualType : public Type, public llvm::FoldingSetNode { 496 /// BaseType - This is the underlying type that this qualifies. All CVR 497 /// qualifiers are stored on the QualType that references this type, so we 498 /// can't have any here. 499 Type *BaseType; 500 501 /// Address Space ID - The address space ID this type is qualified with. 502 unsigned AddressSpace; 503 /// GC __weak/__strong attributes 504 QualType::GCAttrTypes GCAttrType; 505 506 ExtQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace, 507 QualType::GCAttrTypes gcAttr) : 508 Type(ExtQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 509 AddressSpace(AddrSpace), GCAttrType(gcAttr) { 510 assert(!isa<ExtQualType>(BaseType) && 511 "Cannot have ExtQualType of ExtQualType"); 512 } 513 friend class ASTContext; // ASTContext creates these. 514public: 515 Type *getBaseType() const { return BaseType; } 516 QualType::GCAttrTypes getObjCGCAttr() const { return GCAttrType; } 517 unsigned getAddressSpace() const { return AddressSpace; } 518 519 virtual void getAsStringInternal(std::string &InnerString) const; 520 521 void Profile(llvm::FoldingSetNodeID &ID) { 522 Profile(ID, getBaseType(), AddressSpace, GCAttrType); 523 } 524 static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 525 unsigned AddrSpace, QualType::GCAttrTypes gcAttr) { 526 ID.AddPointer(Base); 527 ID.AddInteger(AddrSpace); 528 ID.AddInteger(gcAttr); 529 } 530 531 static bool classof(const Type *T) { return T->getTypeClass() == ExtQual; } 532 static bool classof(const ExtQualType *) { return true; } 533}; 534 535 536/// BuiltinType - This class is used for builtin types like 'int'. Builtin 537/// types are always canonical and have a literal name field. 538class BuiltinType : public Type { 539public: 540 enum Kind { 541 Void, 542 543 Bool, // This is bool and/or _Bool. 544 Char_U, // This is 'char' for targets where char is unsigned. 545 UChar, // This is explicitly qualified unsigned char. 546 UShort, 547 UInt, 548 ULong, 549 ULongLong, 550 UInt128, // __uint128_t 551 552 Char_S, // This is 'char' for targets where char is signed. 553 SChar, // This is explicitly qualified signed char. 554 WChar, // This is 'wchar_t' for C++. 555 Short, 556 Int, 557 Long, 558 LongLong, 559 Int128, // __int128_t 560 561 Float, Double, LongDouble, 562 563 NullPtr, // This is the type of C++0x 'nullptr'. 564 565 Overload, // This represents the type of an overloaded function declaration. 566 Dependent // This represents the type of a type-dependent expression. 567 }; 568private: 569 Kind TypeKind; 570public: 571 BuiltinType(Kind K) 572 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 573 TypeKind(K) {} 574 575 Kind getKind() const { return TypeKind; } 576 const char *getName() const; 577 578 virtual void getAsStringInternal(std::string &InnerString) const; 579 580 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 581 static bool classof(const BuiltinType *) { return true; } 582}; 583 584/// FixedWidthIntType - Used for arbitrary width types that we either don't 585/// want to or can't map to named integer types. These always have a lower 586/// integer rank than builtin types of the same width. 587class FixedWidthIntType : public Type { 588private: 589 unsigned Width; 590 bool Signed; 591public: 592 FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 593 Width(W), Signed(S) {} 594 595 unsigned getWidth() const { return Width; } 596 bool isSigned() const { return Signed; } 597 const char *getName() const; 598 599 virtual void getAsStringInternal(std::string &InnerString) const; 600 601 static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 602 static bool classof(const FixedWidthIntType *) { return true; } 603}; 604 605/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 606/// types (_Complex float etc) as well as the GCC integer complex extensions. 607/// 608class ComplexType : public Type, public llvm::FoldingSetNode { 609 QualType ElementType; 610 ComplexType(QualType Element, QualType CanonicalPtr) : 611 Type(Complex, CanonicalPtr, Element->isDependentType()), 612 ElementType(Element) { 613 } 614 friend class ASTContext; // ASTContext creates these. 615public: 616 QualType getElementType() const { return ElementType; } 617 618 virtual void getAsStringInternal(std::string &InnerString) const; 619 620 void Profile(llvm::FoldingSetNodeID &ID) { 621 Profile(ID, getElementType()); 622 } 623 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 624 ID.AddPointer(Element.getAsOpaquePtr()); 625 } 626 627 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 628 static bool classof(const ComplexType *) { return true; } 629}; 630 631/// PointerType - C99 6.7.5.1 - Pointer Declarators. 632/// 633class PointerType : public Type, public llvm::FoldingSetNode { 634 QualType PointeeType; 635 636 PointerType(QualType Pointee, QualType CanonicalPtr) : 637 Type(Pointer, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 638 } 639 friend class ASTContext; // ASTContext creates these. 640public: 641 642 virtual void getAsStringInternal(std::string &InnerString) const; 643 644 QualType getPointeeType() const { return PointeeType; } 645 646 void Profile(llvm::FoldingSetNodeID &ID) { 647 Profile(ID, getPointeeType()); 648 } 649 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 650 ID.AddPointer(Pointee.getAsOpaquePtr()); 651 } 652 653 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 654 static bool classof(const PointerType *) { return true; } 655}; 656 657/// BlockPointerType - pointer to a block type. 658/// This type is to represent types syntactically represented as 659/// "void (^)(int)", etc. Pointee is required to always be a function type. 660/// 661class BlockPointerType : public Type, public llvm::FoldingSetNode { 662 QualType PointeeType; // Block is some kind of pointer type 663 BlockPointerType(QualType Pointee, QualType CanonicalCls) : 664 Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 665 PointeeType(Pointee) { 666 } 667 friend class ASTContext; // ASTContext creates these. 668public: 669 670 // Get the pointee type. Pointee is required to always be a function type. 671 QualType getPointeeType() const { return PointeeType; } 672 673 virtual void getAsStringInternal(std::string &InnerString) const; 674 675 void Profile(llvm::FoldingSetNodeID &ID) { 676 Profile(ID, getPointeeType()); 677 } 678 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 679 ID.AddPointer(Pointee.getAsOpaquePtr()); 680 } 681 682 static bool classof(const Type *T) { 683 return T->getTypeClass() == BlockPointer; 684 } 685 static bool classof(const BlockPointerType *) { return true; } 686}; 687 688/// ReferenceType - Base for LValueReferenceType and RValueReferenceType 689/// 690class ReferenceType : public Type, public llvm::FoldingSetNode { 691 QualType PointeeType; 692 693protected: 694 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef) : 695 Type(tc, CanonicalRef, Referencee->isDependentType()), 696 PointeeType(Referencee) { 697 } 698public: 699 QualType getPointeeType() const { return PointeeType; } 700 701 void Profile(llvm::FoldingSetNodeID &ID) { 702 Profile(ID, getPointeeType()); 703 } 704 static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 705 ID.AddPointer(Referencee.getAsOpaquePtr()); 706 } 707 708 static bool classof(const Type *T) { 709 return T->getTypeClass() == LValueReference || 710 T->getTypeClass() == RValueReference; 711 } 712 static bool classof(const ReferenceType *) { return true; } 713}; 714 715/// LValueReferenceType - C++ [dcl.ref] - Lvalue reference 716/// 717class LValueReferenceType : public ReferenceType { 718 LValueReferenceType(QualType Referencee, QualType CanonicalRef) : 719 ReferenceType(LValueReference, Referencee, CanonicalRef) { 720 } 721 friend class ASTContext; // ASTContext creates these 722public: 723 virtual void getAsStringInternal(std::string &InnerString) const; 724 725 static bool classof(const Type *T) { 726 return T->getTypeClass() == LValueReference; 727 } 728 static bool classof(const LValueReferenceType *) { return true; } 729}; 730 731/// RValueReferenceType - C++0x [dcl.ref] - Rvalue reference 732/// 733class RValueReferenceType : public ReferenceType { 734 RValueReferenceType(QualType Referencee, QualType CanonicalRef) : 735 ReferenceType(RValueReference, Referencee, CanonicalRef) { 736 } 737 friend class ASTContext; // ASTContext creates these 738public: 739 virtual void getAsStringInternal(std::string &InnerString) const; 740 741 static bool classof(const Type *T) { 742 return T->getTypeClass() == RValueReference; 743 } 744 static bool classof(const RValueReferenceType *) { return true; } 745}; 746 747/// MemberPointerType - C++ 8.3.3 - Pointers to members 748/// 749class MemberPointerType : public Type, public llvm::FoldingSetNode { 750 QualType PointeeType; 751 /// The class of which the pointee is a member. Must ultimately be a 752 /// RecordType, but could be a typedef or a template parameter too. 753 const Type *Class; 754 755 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 756 Type(MemberPointer, CanonicalPtr, 757 Cls->isDependentType() || Pointee->isDependentType()), 758 PointeeType(Pointee), Class(Cls) { 759 } 760 friend class ASTContext; // ASTContext creates these. 761public: 762 763 QualType getPointeeType() const { return PointeeType; } 764 765 const Type *getClass() const { return Class; } 766 767 virtual void getAsStringInternal(std::string &InnerString) const; 768 769 void Profile(llvm::FoldingSetNodeID &ID) { 770 Profile(ID, getPointeeType(), getClass()); 771 } 772 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 773 const Type *Class) { 774 ID.AddPointer(Pointee.getAsOpaquePtr()); 775 ID.AddPointer(Class); 776 } 777 778 static bool classof(const Type *T) { 779 return T->getTypeClass() == MemberPointer; 780 } 781 static bool classof(const MemberPointerType *) { return true; } 782}; 783 784/// ArrayType - C99 6.7.5.2 - Array Declarators. 785/// 786class ArrayType : public Type, public llvm::FoldingSetNode { 787public: 788 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 789 /// an array with a static size (e.g. int X[static 4]), or an array 790 /// with a star size (e.g. int X[*]). 791 /// 'static' is only allowed on function parameters. 792 enum ArraySizeModifier { 793 Normal, Static, Star 794 }; 795private: 796 /// ElementType - The element type of the array. 797 QualType ElementType; 798 799 // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 800 /// NOTE: These fields are packed into the bitfields space in the Type class. 801 unsigned SizeModifier : 2; 802 803 /// IndexTypeQuals - Capture qualifiers in declarations like: 804 /// 'int X[static restrict 4]'. For function parameters only. 805 unsigned IndexTypeQuals : 3; 806 807protected: 808 // C++ [temp.dep.type]p1: 809 // A type is dependent if it is... 810 // - an array type constructed from any dependent type or whose 811 // size is specified by a constant expression that is 812 // value-dependent, 813 ArrayType(TypeClass tc, QualType et, QualType can, 814 ArraySizeModifier sm, unsigned tq) 815 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 816 ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 817 818 friend class ASTContext; // ASTContext creates these. 819public: 820 QualType getElementType() const { return ElementType; } 821 ArraySizeModifier getSizeModifier() const { 822 return ArraySizeModifier(SizeModifier); 823 } 824 unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 825 826 static bool classof(const Type *T) { 827 return T->getTypeClass() == ConstantArray || 828 T->getTypeClass() == VariableArray || 829 T->getTypeClass() == IncompleteArray || 830 T->getTypeClass() == DependentSizedArray; 831 } 832 static bool classof(const ArrayType *) { return true; } 833}; 834 835/// ConstantArrayType - This class represents C arrays with a specified constant 836/// size. For example 'int A[100]' has ConstantArrayType where the element type 837/// is 'int' and the size is 100. 838class ConstantArrayType : public ArrayType { 839 llvm::APInt Size; // Allows us to unique the type. 840 841 ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, 842 ArraySizeModifier sm, unsigned tq) 843 : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {} 844 friend class ASTContext; // ASTContext creates these. 845public: 846 const llvm::APInt &getSize() const { return Size; } 847 virtual void getAsStringInternal(std::string &InnerString) const; 848 849 void Profile(llvm::FoldingSetNodeID &ID) { 850 Profile(ID, getElementType(), getSize(), 851 getSizeModifier(), getIndexTypeQualifier()); 852 } 853 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 854 const llvm::APInt &ArraySize, ArraySizeModifier SizeMod, 855 unsigned TypeQuals) { 856 ID.AddPointer(ET.getAsOpaquePtr()); 857 ID.AddInteger(ArraySize.getZExtValue()); 858 ID.AddInteger(SizeMod); 859 ID.AddInteger(TypeQuals); 860 } 861 static bool classof(const Type *T) { 862 return T->getTypeClass() == ConstantArray; 863 } 864 static bool classof(const ConstantArrayType *) { return true; } 865}; 866 867/// IncompleteArrayType - This class represents C arrays with an unspecified 868/// size. For example 'int A[]' has an IncompleteArrayType where the element 869/// type is 'int' and the size is unspecified. 870class IncompleteArrayType : public ArrayType { 871 IncompleteArrayType(QualType et, QualType can, 872 ArraySizeModifier sm, unsigned tq) 873 : ArrayType(IncompleteArray, et, can, sm, tq) {} 874 friend class ASTContext; // ASTContext creates these. 875public: 876 877 virtual void getAsStringInternal(std::string &InnerString) const; 878 879 static bool classof(const Type *T) { 880 return T->getTypeClass() == IncompleteArray; 881 } 882 static bool classof(const IncompleteArrayType *) { return true; } 883 884 friend class StmtIteratorBase; 885 886 void Profile(llvm::FoldingSetNodeID &ID) { 887 Profile(ID, getElementType(), getSizeModifier(), getIndexTypeQualifier()); 888 } 889 890 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 891 ArraySizeModifier SizeMod, unsigned TypeQuals) { 892 ID.AddPointer(ET.getAsOpaquePtr()); 893 ID.AddInteger(SizeMod); 894 ID.AddInteger(TypeQuals); 895 } 896}; 897 898/// VariableArrayType - This class represents C arrays with a specified size 899/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 900/// Since the size expression is an arbitrary expression, we store it as such. 901/// 902/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 903/// should not be: two lexically equivalent variable array types could mean 904/// different things, for example, these variables do not have the same type 905/// dynamically: 906/// 907/// void foo(int x) { 908/// int Y[x]; 909/// ++x; 910/// int Z[x]; 911/// } 912/// 913class VariableArrayType : public ArrayType { 914 /// SizeExpr - An assignment expression. VLA's are only permitted within 915 /// a function block. 916 Stmt *SizeExpr; 917 918 VariableArrayType(QualType et, QualType can, Expr *e, 919 ArraySizeModifier sm, unsigned tq) 920 : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 921 friend class ASTContext; // ASTContext creates these. 922 virtual void Destroy(ASTContext& C); 923 924public: 925 Expr *getSizeExpr() const { 926 // We use C-style casts instead of cast<> here because we do not wish 927 // to have a dependency of Type.h on Stmt.h/Expr.h. 928 return (Expr*) SizeExpr; 929 } 930 931 virtual void getAsStringInternal(std::string &InnerString) const; 932 933 static bool classof(const Type *T) { 934 return T->getTypeClass() == VariableArray; 935 } 936 static bool classof(const VariableArrayType *) { return true; } 937 938 friend class StmtIteratorBase; 939 940 void Profile(llvm::FoldingSetNodeID &ID) { 941 assert(0 && "Cannnot unique VariableArrayTypes."); 942 } 943}; 944 945/// DependentSizedArrayType - This type represents an array type in 946/// C++ whose size is a value-dependent expression. For example: 947/// @code 948/// template<typename T, int Size> 949/// class array { 950/// T data[Size]; 951/// }; 952/// @endcode 953/// For these types, we won't actually know what the array bound is 954/// until template instantiation occurs, at which point this will 955/// become either a ConstantArrayType or a VariableArrayType. 956class DependentSizedArrayType : public ArrayType { 957 /// SizeExpr - An assignment expression that will instantiate to the 958 /// size of the array. 959 Stmt *SizeExpr; 960 961 DependentSizedArrayType(QualType et, QualType can, Expr *e, 962 ArraySizeModifier sm, unsigned tq) 963 : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 964 friend class ASTContext; // ASTContext creates these. 965 virtual void Destroy(ASTContext& C); 966 967public: 968 Expr *getSizeExpr() const { 969 // We use C-style casts instead of cast<> here because we do not wish 970 // to have a dependency of Type.h on Stmt.h/Expr.h. 971 return (Expr*) SizeExpr; 972 } 973 974 virtual void getAsStringInternal(std::string &InnerString) const; 975 976 static bool classof(const Type *T) { 977 return T->getTypeClass() == DependentSizedArray; 978 } 979 static bool classof(const DependentSizedArrayType *) { return true; } 980 981 friend class StmtIteratorBase; 982 983 void Profile(llvm::FoldingSetNodeID &ID) { 984 assert(0 && "Cannnot unique DependentSizedArrayTypes."); 985 } 986}; 987 988/// VectorType - GCC generic vector type. This type is created using 989/// __attribute__((vector_size(n)), where "n" specifies the vector size in 990/// bytes. Since the constructor takes the number of vector elements, the 991/// client is responsible for converting the size into the number of elements. 992class VectorType : public Type, public llvm::FoldingSetNode { 993protected: 994 /// ElementType - The element type of the vector. 995 QualType ElementType; 996 997 /// NumElements - The number of elements in the vector. 998 unsigned NumElements; 999 1000 VectorType(QualType vecType, unsigned nElements, QualType canonType) : 1001 Type(Vector, canonType, vecType->isDependentType()), 1002 ElementType(vecType), NumElements(nElements) {} 1003 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 1004 QualType canonType) 1005 : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 1006 NumElements(nElements) {} 1007 friend class ASTContext; // ASTContext creates these. 1008public: 1009 1010 QualType getElementType() const { return ElementType; } 1011 unsigned getNumElements() const { return NumElements; } 1012 1013 virtual void getAsStringInternal(std::string &InnerString) const; 1014 1015 void Profile(llvm::FoldingSetNodeID &ID) { 1016 Profile(ID, getElementType(), getNumElements(), getTypeClass()); 1017 } 1018 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 1019 unsigned NumElements, TypeClass TypeClass) { 1020 ID.AddPointer(ElementType.getAsOpaquePtr()); 1021 ID.AddInteger(NumElements); 1022 ID.AddInteger(TypeClass); 1023 } 1024 static bool classof(const Type *T) { 1025 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 1026 } 1027 static bool classof(const VectorType *) { return true; } 1028}; 1029 1030/// ExtVectorType - Extended vector type. This type is created using 1031/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1032/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1033/// class enables syntactic extensions, like Vector Components for accessing 1034/// points, colors, and textures (modeled after OpenGL Shading Language). 1035class ExtVectorType : public VectorType { 1036 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1037 VectorType(ExtVector, vecType, nElements, canonType) {} 1038 friend class ASTContext; // ASTContext creates these. 1039public: 1040 static int getPointAccessorIdx(char c) { 1041 switch (c) { 1042 default: return -1; 1043 case 'x': return 0; 1044 case 'y': return 1; 1045 case 'z': return 2; 1046 case 'w': return 3; 1047 } 1048 } 1049 static int getNumericAccessorIdx(char c) { 1050 switch (c) { 1051 default: return -1; 1052 case '0': return 0; 1053 case '1': return 1; 1054 case '2': return 2; 1055 case '3': return 3; 1056 case '4': return 4; 1057 case '5': return 5; 1058 case '6': return 6; 1059 case '7': return 7; 1060 case '8': return 8; 1061 case '9': return 9; 1062 case 'a': return 10; 1063 case 'b': return 11; 1064 case 'c': return 12; 1065 case 'd': return 13; 1066 case 'e': return 14; 1067 case 'f': return 15; 1068 } 1069 } 1070 1071 static int getAccessorIdx(char c) { 1072 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1073 return getNumericAccessorIdx(c); 1074 } 1075 1076 bool isAccessorWithinNumElements(char c) const { 1077 if (int idx = getAccessorIdx(c)+1) 1078 return unsigned(idx-1) < NumElements; 1079 return false; 1080 } 1081 virtual void getAsStringInternal(std::string &InnerString) const; 1082 1083 static bool classof(const Type *T) { 1084 return T->getTypeClass() == ExtVector; 1085 } 1086 static bool classof(const ExtVectorType *) { return true; } 1087}; 1088 1089/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 1090/// class of FunctionNoProtoType and FunctionProtoType. 1091/// 1092class FunctionType : public Type { 1093 /// SubClassData - This field is owned by the subclass, put here to pack 1094 /// tightly with the ivars in Type. 1095 bool SubClassData : 1; 1096 1097 /// TypeQuals - Used only by FunctionProtoType, put here to pack with the 1098 /// other bitfields. 1099 /// The qualifiers are part of FunctionProtoType because... 1100 /// 1101 /// C++ 8.3.5p4: The return type, the parameter type list and the 1102 /// cv-qualifier-seq, [...], are part of the function type. 1103 /// 1104 unsigned TypeQuals : 3; 1105 1106 // The type returned by the function. 1107 QualType ResultType; 1108protected: 1109 FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1110 unsigned typeQuals, QualType Canonical, bool Dependent) 1111 : Type(tc, Canonical, Dependent), 1112 SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 1113 bool getSubClassData() const { return SubClassData; } 1114 unsigned getTypeQuals() const { return TypeQuals; } 1115public: 1116 1117 QualType getResultType() const { return ResultType; } 1118 1119 1120 static bool classof(const Type *T) { 1121 return T->getTypeClass() == FunctionNoProto || 1122 T->getTypeClass() == FunctionProto; 1123 } 1124 static bool classof(const FunctionType *) { return true; } 1125}; 1126 1127/// FunctionNoProtoType - Represents a K&R-style 'int foo()' function, which has 1128/// no information available about its arguments. 1129class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { 1130 FunctionNoProtoType(QualType Result, QualType Canonical) 1131 : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1132 /*Dependent=*/false) {} 1133 friend class ASTContext; // ASTContext creates these. 1134public: 1135 // No additional state past what FunctionType provides. 1136 1137 virtual void getAsStringInternal(std::string &InnerString) const; 1138 1139 void Profile(llvm::FoldingSetNodeID &ID) { 1140 Profile(ID, getResultType()); 1141 } 1142 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 1143 ID.AddPointer(ResultType.getAsOpaquePtr()); 1144 } 1145 1146 static bool classof(const Type *T) { 1147 return T->getTypeClass() == FunctionNoProto; 1148 } 1149 static bool classof(const FunctionNoProtoType *) { return true; } 1150}; 1151 1152/// FunctionProtoType - Represents a prototype with argument type info, e.g. 1153/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1154/// arguments, not as having a single void argument. 1155class FunctionProtoType : public FunctionType, public llvm::FoldingSetNode { 1156 /// hasAnyDependentType - Determine whether there are any dependent 1157 /// types within the arguments passed in. 1158 static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1159 for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1160 if (ArgArray[Idx]->isDependentType()) 1161 return true; 1162 1163 return false; 1164 } 1165 1166 FunctionProtoType(QualType Result, const QualType *ArgArray, unsigned numArgs, 1167 bool isVariadic, unsigned typeQuals, QualType Canonical) 1168 : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1169 (Result->isDependentType() || 1170 hasAnyDependentType(ArgArray, numArgs))), 1171 NumArgs(numArgs) { 1172 // Fill in the trailing argument array. 1173 QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 1174 for (unsigned i = 0; i != numArgs; ++i) 1175 ArgInfo[i] = ArgArray[i]; 1176 } 1177 1178 /// NumArgs - The number of arguments this function has, not counting '...'. 1179 unsigned NumArgs; 1180 1181 /// ArgInfo - There is an variable size array after the class in memory that 1182 /// holds the argument types. 1183 1184 friend class ASTContext; // ASTContext creates these. 1185 1186public: 1187 unsigned getNumArgs() const { return NumArgs; } 1188 QualType getArgType(unsigned i) const { 1189 assert(i < NumArgs && "Invalid argument number!"); 1190 return arg_type_begin()[i]; 1191 } 1192 1193 bool isVariadic() const { return getSubClassData(); } 1194 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 1195 1196 typedef const QualType *arg_type_iterator; 1197 arg_type_iterator arg_type_begin() const { 1198 return reinterpret_cast<const QualType *>(this+1); 1199 } 1200 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1201 1202 virtual void getAsStringInternal(std::string &InnerString) const; 1203 1204 static bool classof(const Type *T) { 1205 return T->getTypeClass() == FunctionProto; 1206 } 1207 static bool classof(const FunctionProtoType *) { return true; } 1208 1209 void Profile(llvm::FoldingSetNodeID &ID); 1210 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1211 arg_type_iterator ArgTys, unsigned NumArgs, 1212 bool isVariadic, unsigned TypeQuals); 1213}; 1214 1215 1216class TypedefType : public Type { 1217 TypedefDecl *Decl; 1218protected: 1219 TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1220 : Type(tc, can, can->isDependentType()), Decl(D) { 1221 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1222 } 1223 friend class ASTContext; // ASTContext creates these. 1224public: 1225 1226 TypedefDecl *getDecl() const { return Decl; } 1227 1228 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1229 /// potentially looking through *all* consecutive typedefs. This returns the 1230 /// sum of the type qualifiers, so if you have: 1231 /// typedef const int A; 1232 /// typedef volatile A B; 1233 /// looking through the typedefs for B will give you "const volatile A". 1234 QualType LookThroughTypedefs() const; 1235 1236 virtual void getAsStringInternal(std::string &InnerString) const; 1237 1238 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } 1239 static bool classof(const TypedefType *) { return true; } 1240}; 1241 1242/// TypeOfExprType (GCC extension). 1243class TypeOfExprType : public Type { 1244 Expr *TOExpr; 1245 TypeOfExprType(Expr *E, QualType can); 1246 friend class ASTContext; // ASTContext creates these. 1247public: 1248 Expr *getUnderlyingExpr() const { return TOExpr; } 1249 1250 virtual void getAsStringInternal(std::string &InnerString) const; 1251 1252 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } 1253 static bool classof(const TypeOfExprType *) { return true; } 1254}; 1255 1256/// TypeOfType (GCC extension). 1257class TypeOfType : public Type { 1258 QualType TOType; 1259 TypeOfType(QualType T, QualType can) 1260 : Type(TypeOf, can, T->isDependentType()), TOType(T) { 1261 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1262 } 1263 friend class ASTContext; // ASTContext creates these. 1264public: 1265 QualType getUnderlyingType() const { return TOType; } 1266 1267 virtual void getAsStringInternal(std::string &InnerString) const; 1268 1269 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } 1270 static bool classof(const TypeOfType *) { return true; } 1271}; 1272 1273class TagType : public Type { 1274 /// Stores the TagDecl associated with this type. The decl will 1275 /// point to the TagDecl that actually defines the entity (or is a 1276 /// definition in progress), if there is such a definition. The 1277 /// single-bit value will be non-zero when this tag is in the 1278 /// process of being defined. 1279 mutable llvm::PointerIntPair<TagDecl *, 1> decl; 1280 friend class ASTContext; 1281 friend class TagDecl; 1282 1283protected: 1284 // FIXME: We'll need the user to pass in information about whether 1285 // this type is dependent or not, because we don't have enough 1286 // information to compute it here. 1287 TagType(TypeClass TC, TagDecl *D, QualType can) 1288 : Type(TC, can, /*Dependent=*/false), decl(D, 0) {} 1289 1290public: 1291 TagDecl *getDecl() const { return decl.getPointer(); } 1292 1293 /// @brief Determines whether this type is in the process of being 1294 /// defined. 1295 bool isBeingDefined() const { return decl.getInt(); } 1296 void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 1297 1298 virtual void getAsStringInternal(std::string &InnerString) const; 1299 void getAsStringInternal(std::string &InnerString, 1300 bool SuppressTagKind) const; 1301 1302 static bool classof(const Type *T) { 1303 return T->getTypeClass() >= TagFirst && T->getTypeClass() <= TagLast; 1304 } 1305 static bool classof(const TagType *) { return true; } 1306 static bool classof(const RecordType *) { return true; } 1307 static bool classof(const EnumType *) { return true; } 1308}; 1309 1310/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1311/// to detect TagType objects of structs/unions/classes. 1312class RecordType : public TagType { 1313protected: 1314 explicit RecordType(RecordDecl *D) 1315 : TagType(Record, reinterpret_cast<TagDecl*>(D), QualType()) { } 1316 explicit RecordType(TypeClass TC, RecordDecl *D) 1317 : TagType(TC, reinterpret_cast<TagDecl*>(D), QualType()) { } 1318 friend class ASTContext; // ASTContext creates these. 1319public: 1320 1321 RecordDecl *getDecl() const { 1322 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1323 } 1324 1325 // FIXME: This predicate is a helper to QualType/Type. It needs to 1326 // recursively check all fields for const-ness. If any field is declared 1327 // const, it needs to return false. 1328 bool hasConstFields() const { return false; } 1329 1330 // FIXME: RecordType needs to check when it is created that all fields are in 1331 // the same address space, and return that. 1332 unsigned getAddressSpace() const { return 0; } 1333 1334 static bool classof(const TagType *T); 1335 static bool classof(const Type *T) { 1336 return isa<TagType>(T) && classof(cast<TagType>(T)); 1337 } 1338 static bool classof(const RecordType *) { return true; } 1339}; 1340 1341/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1342/// to detect TagType objects of enums. 1343class EnumType : public TagType { 1344 explicit EnumType(EnumDecl *D) 1345 : TagType(Enum, reinterpret_cast<TagDecl*>(D), QualType()) { } 1346 friend class ASTContext; // ASTContext creates these. 1347public: 1348 1349 EnumDecl *getDecl() const { 1350 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1351 } 1352 1353 static bool classof(const TagType *T); 1354 static bool classof(const Type *T) { 1355 return isa<TagType>(T) && classof(cast<TagType>(T)); 1356 } 1357 static bool classof(const EnumType *) { return true; } 1358}; 1359 1360class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1361 unsigned Depth : 16; 1362 unsigned Index : 16; 1363 IdentifierInfo *Name; 1364 1365 TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1366 QualType Canon) 1367 : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1368 Depth(D), Index(I), Name(N) { } 1369 1370 TemplateTypeParmType(unsigned D, unsigned I) 1371 : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1372 Depth(D), Index(I), Name(0) { } 1373 1374 friend class ASTContext; // ASTContext creates these 1375 1376public: 1377 unsigned getDepth() const { return Depth; } 1378 unsigned getIndex() const { return Index; } 1379 IdentifierInfo *getName() const { return Name; } 1380 1381 virtual void getAsStringInternal(std::string &InnerString) const; 1382 1383 void Profile(llvm::FoldingSetNodeID &ID) { 1384 Profile(ID, Depth, Index, Name); 1385 } 1386 1387 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1388 unsigned Index, IdentifierInfo *Name) { 1389 ID.AddInteger(Depth); 1390 ID.AddInteger(Index); 1391 ID.AddPointer(Name); 1392 } 1393 1394 static bool classof(const Type *T) { 1395 return T->getTypeClass() == TemplateTypeParm; 1396 } 1397 static bool classof(const TemplateTypeParmType *T) { return true; } 1398}; 1399 1400/// \brief Represents the type of a template specialization as written 1401/// in the source code. 1402/// 1403/// Template specialization types represent the syntactic form of a 1404/// template-id that refers to a type, e.g., @c vector<int>. Some 1405/// template specialization types are syntactic sugar, whose canonical 1406/// type will point to some other type node that represents the 1407/// instantiation or class template specialization. For example, a 1408/// class template specialization type of @c vector<int> will refer to 1409/// a tag type for the instantiation 1410/// @c std::vector<int, std::allocator<int>>. 1411/// 1412/// Other template specialization types, for which the template name 1413/// is dependent, may be canonical types. These types are always 1414/// dependent. 1415class TemplateSpecializationType 1416 : public Type, public llvm::FoldingSetNode { 1417 1418 /// \brief The name of the template being specialized. 1419 TemplateName Template; 1420 1421 /// \brief - The number of template arguments named in this class 1422 /// template specialization. 1423 unsigned NumArgs; 1424 1425 TemplateSpecializationType(TemplateName T, 1426 const TemplateArgument *Args, 1427 unsigned NumArgs, QualType Canon); 1428 1429 virtual void Destroy(ASTContext& C); 1430 1431 friend class ASTContext; // ASTContext creates these 1432 1433public: 1434 /// \brief Determine whether any of the given template arguments are 1435 /// dependent. 1436 static bool anyDependentTemplateArguments(const TemplateArgument *Args, 1437 unsigned NumArgs); 1438 1439 /// \brief Print a template argument list, including the '<' and '>' 1440 /// enclosing the template arguments. 1441 static std::string PrintTemplateArgumentList(const TemplateArgument *Args, 1442 unsigned NumArgs); 1443 1444 typedef const TemplateArgument * iterator; 1445 1446 iterator begin() const { return getArgs(); } 1447 iterator end() const; 1448 1449 /// \brief Retrieve the name of the template that we are specializing. 1450 TemplateName getTemplateName() const { return Template; } 1451 1452 /// \brief Retrieve the template arguments. 1453 const TemplateArgument *getArgs() const { 1454 return reinterpret_cast<const TemplateArgument *>(this + 1); 1455 } 1456 1457 /// \brief Retrieve the number of template arguments. 1458 unsigned getNumArgs() const { return NumArgs; } 1459 1460 /// \brief Retrieve a specific template argument as a type. 1461 /// \precondition @c isArgType(Arg) 1462 const TemplateArgument &getArg(unsigned Idx) const; 1463 1464 virtual void getAsStringInternal(std::string &InnerString) const; 1465 1466 void Profile(llvm::FoldingSetNodeID &ID) { 1467 Profile(ID, Template, getArgs(), NumArgs); 1468 } 1469 1470 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, 1471 const TemplateArgument *Args, unsigned NumArgs); 1472 1473 static bool classof(const Type *T) { 1474 return T->getTypeClass() == TemplateSpecialization; 1475 } 1476 static bool classof(const TemplateSpecializationType *T) { return true; } 1477}; 1478 1479/// \brief Represents a type that was referred to via a qualified 1480/// name, e.g., N::M::type. 1481/// 1482/// This type is used to keep track of a type name as written in the 1483/// source code, including any nested-name-specifiers. The type itself 1484/// is always "sugar", used to express what was written in the source 1485/// code but containing no additional semantic information. 1486class QualifiedNameType : public Type, public llvm::FoldingSetNode { 1487 /// \brief The nested name specifier containing the qualifier. 1488 NestedNameSpecifier *NNS; 1489 1490 /// \brief The type that this qualified name refers to. 1491 QualType NamedType; 1492 1493 QualifiedNameType(NestedNameSpecifier *NNS, QualType NamedType, 1494 QualType CanonType) 1495 : Type(QualifiedName, CanonType, NamedType->isDependentType()), 1496 NNS(NNS), NamedType(NamedType) { } 1497 1498 friend class ASTContext; // ASTContext creates these 1499 1500public: 1501 /// \brief Retrieve the qualification on this type. 1502 NestedNameSpecifier *getQualifier() const { return NNS; } 1503 1504 /// \brief Retrieve the type named by the qualified-id. 1505 QualType getNamedType() const { return NamedType; } 1506 1507 virtual void getAsStringInternal(std::string &InnerString) const; 1508 1509 void Profile(llvm::FoldingSetNodeID &ID) { 1510 Profile(ID, NNS, NamedType); 1511 } 1512 1513 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1514 QualType NamedType) { 1515 ID.AddPointer(NNS); 1516 NamedType.Profile(ID); 1517 } 1518 1519 static bool classof(const Type *T) { 1520 return T->getTypeClass() == QualifiedName; 1521 } 1522 static bool classof(const QualifiedNameType *T) { return true; } 1523}; 1524 1525/// \brief Represents a 'typename' specifier that names a type within 1526/// a dependent type, e.g., "typename T::type". 1527/// 1528/// TypenameType has a very similar structure to QualifiedNameType, 1529/// which also involves a nested-name-specifier following by a type, 1530/// and (FIXME!) both can even be prefixed by the 'typename' 1531/// keyword. However, the two types serve very different roles: 1532/// QualifiedNameType is a non-semantic type that serves only as sugar 1533/// to show how a particular type was written in the source 1534/// code. TypenameType, on the other hand, only occurs when the 1535/// nested-name-specifier is dependent, such that we cannot resolve 1536/// the actual type until after instantiation. 1537class TypenameType : public Type, public llvm::FoldingSetNode { 1538 /// \brief The nested name specifier containing the qualifier. 1539 NestedNameSpecifier *NNS; 1540 1541 typedef llvm::PointerUnion<const IdentifierInfo *, 1542 const TemplateSpecializationType *> NameType; 1543 1544 /// \brief The type that this typename specifier refers to. 1545 NameType Name; 1546 1547 TypenameType(NestedNameSpecifier *NNS, const IdentifierInfo *Name, 1548 QualType CanonType) 1549 : Type(Typename, CanonType, true), NNS(NNS), Name(Name) { 1550 assert(NNS->isDependent() && 1551 "TypenameType requires a dependent nested-name-specifier"); 1552 } 1553 1554 TypenameType(NestedNameSpecifier *NNS, const TemplateSpecializationType *Ty, 1555 QualType CanonType) 1556 : Type(Typename, CanonType, true), NNS(NNS), Name(Ty) { 1557 assert(NNS->isDependent() && 1558 "TypenameType requires a dependent nested-name-specifier"); 1559 } 1560 1561 friend class ASTContext; // ASTContext creates these 1562 1563public: 1564 /// \brief Retrieve the qualification on this type. 1565 NestedNameSpecifier *getQualifier() const { return NNS; } 1566 1567 /// \brief Retrieve the type named by the typename specifier as an 1568 /// identifier. 1569 /// 1570 /// This routine will return a non-NULL identifier pointer when the 1571 /// form of the original typename was terminated by an identifier, 1572 /// e.g., "typename T::type". 1573 const IdentifierInfo *getIdentifier() const { 1574 return Name.dyn_cast<const IdentifierInfo *>(); 1575 } 1576 1577 /// \brief Retrieve the type named by the typename specifier as a 1578 /// type specialization. 1579 const TemplateSpecializationType *getTemplateId() const { 1580 return Name.dyn_cast<const TemplateSpecializationType *>(); 1581 } 1582 1583 virtual void getAsStringInternal(std::string &InnerString) const; 1584 1585 void Profile(llvm::FoldingSetNodeID &ID) { 1586 Profile(ID, NNS, Name); 1587 } 1588 1589 static void Profile(llvm::FoldingSetNodeID &ID, NestedNameSpecifier *NNS, 1590 NameType Name) { 1591 ID.AddPointer(NNS); 1592 ID.AddPointer(Name.getOpaqueValue()); 1593 } 1594 1595 static bool classof(const Type *T) { 1596 return T->getTypeClass() == Typename; 1597 } 1598 static bool classof(const TypenameType *T) { return true; } 1599}; 1600 1601/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1602/// object oriented design. They basically correspond to C++ classes. There 1603/// are two kinds of interface types, normal interfaces like "NSString" and 1604/// qualified interfaces, which are qualified with a protocol list like 1605/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1606/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1607class ObjCInterfaceType : public Type { 1608 ObjCInterfaceDecl *Decl; 1609protected: 1610 ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1611 Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 1612 friend class ASTContext; // ASTContext creates these. 1613public: 1614 1615 ObjCInterfaceDecl *getDecl() const { return Decl; } 1616 1617 /// qual_iterator and friends: this provides access to the (potentially empty) 1618 /// list of protocols qualifying this interface. If this is an instance of 1619 /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1620 /// empty list if there are no qualifying protocols. 1621 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1622 inline qual_iterator qual_begin() const; 1623 inline qual_iterator qual_end() const; 1624 bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1625 1626 /// getNumProtocols - Return the number of qualifying protocols in this 1627 /// interface type, or 0 if there are none. 1628 inline unsigned getNumProtocols() const; 1629 1630 /// getProtocol - Return the specified qualifying protocol. 1631 inline ObjCProtocolDecl *getProtocol(unsigned i) const; 1632 1633 1634 virtual void getAsStringInternal(std::string &InnerString) const; 1635 static bool classof(const Type *T) { 1636 return T->getTypeClass() == ObjCInterface || 1637 T->getTypeClass() == ObjCQualifiedInterface; 1638 } 1639 static bool classof(const ObjCInterfaceType *) { return true; } 1640}; 1641 1642/// ObjCQualifiedInterfaceType - This class represents interface types 1643/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1644/// 1645/// Duplicate protocols are removed and protocol list is canonicalized to be in 1646/// alphabetical order. 1647class ObjCQualifiedInterfaceType : public ObjCInterfaceType, 1648 public llvm::FoldingSetNode { 1649 1650 // List of protocols for this protocol conforming object type 1651 // List is sorted on protocol name. No protocol is enterred more than once. 1652 llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1653 1654 ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1655 ObjCProtocolDecl **Protos, unsigned NumP) : 1656 ObjCInterfaceType(ObjCQualifiedInterface, D), 1657 Protocols(Protos, Protos+NumP) { } 1658 friend class ASTContext; // ASTContext creates these. 1659public: 1660 1661 ObjCProtocolDecl *getProtocol(unsigned i) const { 1662 return Protocols[i]; 1663 } 1664 unsigned getNumProtocols() const { 1665 return Protocols.size(); 1666 } 1667 1668 qual_iterator qual_begin() const { return Protocols.begin(); } 1669 qual_iterator qual_end() const { return Protocols.end(); } 1670 1671 virtual void getAsStringInternal(std::string &InnerString) const; 1672 1673 void Profile(llvm::FoldingSetNodeID &ID); 1674 static void Profile(llvm::FoldingSetNodeID &ID, 1675 const ObjCInterfaceDecl *Decl, 1676 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1677 1678 static bool classof(const Type *T) { 1679 return T->getTypeClass() == ObjCQualifiedInterface; 1680 } 1681 static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1682}; 1683 1684inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1685 if (const ObjCQualifiedInterfaceType *QIT = 1686 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1687 return QIT->qual_begin(); 1688 return 0; 1689} 1690inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1691 if (const ObjCQualifiedInterfaceType *QIT = 1692 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1693 return QIT->qual_end(); 1694 return 0; 1695} 1696 1697/// getNumProtocols - Return the number of qualifying protocols in this 1698/// interface type, or 0 if there are none. 1699inline unsigned ObjCInterfaceType::getNumProtocols() const { 1700 if (const ObjCQualifiedInterfaceType *QIT = 1701 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1702 return QIT->getNumProtocols(); 1703 return 0; 1704} 1705 1706/// getProtocol - Return the specified qualifying protocol. 1707inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1708 return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1709} 1710 1711 1712 1713/// ObjCQualifiedIdType - to represent id<protocol-list>. 1714/// 1715/// Duplicate protocols are removed and protocol list is canonicalized to be in 1716/// alphabetical order. 1717class ObjCQualifiedIdType : public Type, 1718 public llvm::FoldingSetNode { 1719 // List of protocols for this protocol conforming 'id' type 1720 // List is sorted on protocol name. No protocol is enterred more than once. 1721 llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1722 1723 ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1724 : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 1725 /*Dependent=*/false), 1726 Protocols(Protos, Protos+NumP) { } 1727 friend class ASTContext; // ASTContext creates these. 1728public: 1729 1730 ObjCProtocolDecl *getProtocols(unsigned i) const { 1731 return Protocols[i]; 1732 } 1733 unsigned getNumProtocols() const { 1734 return Protocols.size(); 1735 } 1736 ObjCProtocolDecl **getReferencedProtocols() { 1737 return &Protocols[0]; 1738 } 1739 1740 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1741 qual_iterator qual_begin() const { return Protocols.begin(); } 1742 qual_iterator qual_end() const { return Protocols.end(); } 1743 1744 virtual void getAsStringInternal(std::string &InnerString) const; 1745 1746 void Profile(llvm::FoldingSetNodeID &ID); 1747 static void Profile(llvm::FoldingSetNodeID &ID, 1748 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1749 1750 static bool classof(const Type *T) { 1751 return T->getTypeClass() == ObjCQualifiedId; 1752 } 1753 static bool classof(const ObjCQualifiedIdType *) { return true; } 1754 1755}; 1756 1757// Inline function definitions. 1758 1759/// getUnqualifiedType - Return the type without any qualifiers. 1760inline QualType QualType::getUnqualifiedType() const { 1761 Type *TP = getTypePtr(); 1762 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(TP)) 1763 TP = EXTQT->getBaseType(); 1764 return QualType(TP, 0); 1765} 1766 1767/// getAddressSpace - Return the address space of this type. 1768inline unsigned QualType::getAddressSpace() const { 1769 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1770 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1771 return AT->getElementType().getAddressSpace(); 1772 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1773 return RT->getAddressSpace(); 1774 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1775 return EXTQT->getAddressSpace(); 1776 return 0; 1777} 1778 1779/// getObjCGCAttr - Return the gc attribute of this type. 1780inline QualType::GCAttrTypes QualType::getObjCGCAttr() const { 1781 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1782 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1783 return AT->getElementType().getObjCGCAttr(); 1784 if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CT)) 1785 return EXTQT->getObjCGCAttr(); 1786 if (const PointerType *PT = CT->getAsPointerType()) 1787 return PT->getPointeeType().getObjCGCAttr(); 1788 return GCNone; 1789} 1790 1791/// isMoreQualifiedThan - Determine whether this type is more 1792/// qualified than the Other type. For example, "const volatile int" 1793/// is more qualified than "const int", "volatile int", and 1794/// "int". However, it is not more qualified than "const volatile 1795/// int". 1796inline bool QualType::isMoreQualifiedThan(QualType Other) const { 1797 unsigned MyQuals = this->getCVRQualifiers(); 1798 unsigned OtherQuals = Other.getCVRQualifiers(); 1799 if (getAddressSpace() != Other.getAddressSpace()) 1800 return false; 1801 return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1802} 1803 1804/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1805/// as qualified as the Other type. For example, "const volatile 1806/// int" is at least as qualified as "const int", "volatile int", 1807/// "int", and "const volatile int". 1808inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1809 unsigned MyQuals = this->getCVRQualifiers(); 1810 unsigned OtherQuals = Other.getCVRQualifiers(); 1811 if (getAddressSpace() != Other.getAddressSpace()) 1812 return false; 1813 return (MyQuals | OtherQuals) == MyQuals; 1814} 1815 1816/// getNonReferenceType - If Type is a reference type (e.g., const 1817/// int&), returns the type that the reference refers to ("const 1818/// int"). Otherwise, returns the type itself. This routine is used 1819/// throughout Sema to implement C++ 5p6: 1820/// 1821/// If an expression initially has the type "reference to T" (8.3.2, 1822/// 8.5.3), the type is adjusted to "T" prior to any further 1823/// analysis, the expression designates the object or function 1824/// denoted by the reference, and the expression is an lvalue. 1825inline QualType QualType::getNonReferenceType() const { 1826 if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1827 return RefType->getPointeeType(); 1828 else 1829 return *this; 1830} 1831 1832inline const TypedefType* Type::getAsTypedefType() const { 1833 return dyn_cast<TypedefType>(this); 1834} 1835inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1836 if (const PointerType *PT = getAsPointerType()) 1837 return PT->getPointeeType()->getAsObjCInterfaceType(); 1838 return 0; 1839} 1840 1841// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1842// space qualifiers if present. 1843inline bool Type::isFunctionType() const { 1844 return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1845} 1846inline bool Type::isPointerType() const { 1847 return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1848} 1849inline bool Type::isBlockPointerType() const { 1850 return isa<BlockPointerType>(CanonicalType.getUnqualifiedType()); 1851} 1852inline bool Type::isReferenceType() const { 1853 return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1854} 1855inline bool Type::isLValueReferenceType() const { 1856 return isa<LValueReferenceType>(CanonicalType.getUnqualifiedType()); 1857} 1858inline bool Type::isRValueReferenceType() const { 1859 return isa<RValueReferenceType>(CanonicalType.getUnqualifiedType()); 1860} 1861inline bool Type::isFunctionPointerType() const { 1862 if (const PointerType* T = getAsPointerType()) 1863 return T->getPointeeType()->isFunctionType(); 1864 else 1865 return false; 1866} 1867inline bool Type::isMemberPointerType() const { 1868 return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1869} 1870inline bool Type::isMemberFunctionPointerType() const { 1871 if (const MemberPointerType* T = getAsMemberPointerType()) 1872 return T->getPointeeType()->isFunctionType(); 1873 else 1874 return false; 1875} 1876inline bool Type::isArrayType() const { 1877 return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1878} 1879inline bool Type::isConstantArrayType() const { 1880 return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1881} 1882inline bool Type::isIncompleteArrayType() const { 1883 return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1884} 1885inline bool Type::isVariableArrayType() const { 1886 return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1887} 1888inline bool Type::isDependentSizedArrayType() const { 1889 return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1890} 1891inline bool Type::isRecordType() const { 1892 return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1893} 1894inline bool Type::isAnyComplexType() const { 1895 return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1896} 1897inline bool Type::isVectorType() const { 1898 return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1899} 1900inline bool Type::isExtVectorType() const { 1901 return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1902} 1903inline bool Type::isObjCInterfaceType() const { 1904 return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1905} 1906inline bool Type::isObjCQualifiedInterfaceType() const { 1907 return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1908} 1909inline bool Type::isObjCQualifiedIdType() const { 1910 return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1911} 1912inline bool Type::isTemplateTypeParmType() const { 1913 return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 1914} 1915 1916inline bool Type::isSpecificBuiltinType(unsigned K) const { 1917 if (const BuiltinType *BT = getAsBuiltinType()) 1918 if (BT->getKind() == (BuiltinType::Kind) K) 1919 return true; 1920 return false; 1921} 1922 1923/// \brief Determines whether this is a type for which one can define 1924/// an overloaded operator. 1925inline bool Type::isOverloadableType() const { 1926 return isDependentType() || isRecordType() || isEnumeralType(); 1927} 1928 1929inline bool Type::hasPointerRepresentation() const { 1930 return (isPointerType() || isReferenceType() || isBlockPointerType() || 1931 isObjCInterfaceType() || isObjCQualifiedIdType() || 1932 isObjCQualifiedInterfaceType() || isNullPtrType()); 1933} 1934 1935inline bool Type::hasObjCPointerRepresentation() const { 1936 return (isObjCInterfaceType() || isObjCQualifiedIdType() || 1937 isObjCQualifiedInterfaceType()); 1938} 1939 1940/// Insertion operator for diagnostics. This allows sending QualType's into a 1941/// diagnostic with <<. 1942inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1943 QualType T) { 1944 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 1945 Diagnostic::ak_qualtype); 1946 return DB; 1947} 1948 1949} // end namespace clang 1950 1951#endif 1952