1*f4a2713aSLionel Sambuc //===--- BaseSubobject.h - BaseSubobject class ----------------------------===// 2*f4a2713aSLionel Sambuc // 3*f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4*f4a2713aSLionel Sambuc // 5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7*f4a2713aSLionel Sambuc // 8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9*f4a2713aSLionel Sambuc // 10*f4a2713aSLionel Sambuc // This file provides a definition of the BaseSubobject class. 11*f4a2713aSLionel Sambuc // 12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13*f4a2713aSLionel Sambuc 14*f4a2713aSLionel Sambuc #ifndef LLVM_CLANG_AST_BASESUBOBJECT_H 15*f4a2713aSLionel Sambuc #define LLVM_CLANG_AST_BASESUBOBJECT_H 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc #include "clang/AST/CharUnits.h" 18*f4a2713aSLionel Sambuc #include "llvm/ADT/DenseMap.h" 19*f4a2713aSLionel Sambuc #include "llvm/Support/DataTypes.h" 20*f4a2713aSLionel Sambuc #include "llvm/Support/type_traits.h" 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc namespace clang { 23*f4a2713aSLionel Sambuc class CXXRecordDecl; 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc // BaseSubobject - Uniquely identifies a direct or indirect base class. 26*f4a2713aSLionel Sambuc // Stores both the base class decl and the offset from the most derived class to 27*f4a2713aSLionel Sambuc // the base class. Used for vtable and VTT generation. 28*f4a2713aSLionel Sambuc class BaseSubobject { 29*f4a2713aSLionel Sambuc /// Base - The base class declaration. 30*f4a2713aSLionel Sambuc const CXXRecordDecl *Base; 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc /// BaseOffset - The offset from the most derived class to the base class. 33*f4a2713aSLionel Sambuc CharUnits BaseOffset; 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc public: BaseSubobject()36*f4a2713aSLionel Sambuc BaseSubobject() { } BaseSubobject(const CXXRecordDecl * Base,CharUnits BaseOffset)37*f4a2713aSLionel Sambuc BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset) 38*f4a2713aSLionel Sambuc : Base(Base), BaseOffset(BaseOffset) { } 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc /// getBase - Returns the base class declaration. getBase()41*f4a2713aSLionel Sambuc const CXXRecordDecl *getBase() const { return Base; } 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc /// getBaseOffset - Returns the base class offset. getBaseOffset()44*f4a2713aSLionel Sambuc CharUnits getBaseOffset() const { return BaseOffset; } 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) { 47*f4a2713aSLionel Sambuc return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset; 48*f4a2713aSLionel Sambuc } 49*f4a2713aSLionel Sambuc }; 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc } // end namespace clang 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc namespace llvm { 54*f4a2713aSLionel Sambuc 55*f4a2713aSLionel Sambuc template<> struct DenseMapInfo<clang::BaseSubobject> { 56*f4a2713aSLionel Sambuc static clang::BaseSubobject getEmptyKey() { 57*f4a2713aSLionel Sambuc return clang::BaseSubobject( 58*f4a2713aSLionel Sambuc DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(), 59*f4a2713aSLionel Sambuc clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getEmptyKey())); 60*f4a2713aSLionel Sambuc } 61*f4a2713aSLionel Sambuc 62*f4a2713aSLionel Sambuc static clang::BaseSubobject getTombstoneKey() { 63*f4a2713aSLionel Sambuc return clang::BaseSubobject( 64*f4a2713aSLionel Sambuc DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(), 65*f4a2713aSLionel Sambuc clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getTombstoneKey())); 66*f4a2713aSLionel Sambuc } 67*f4a2713aSLionel Sambuc 68*f4a2713aSLionel Sambuc static unsigned getHashValue(const clang::BaseSubobject &Base) { 69*f4a2713aSLionel Sambuc typedef std::pair<const clang::CXXRecordDecl *, clang::CharUnits> PairTy; 70*f4a2713aSLionel Sambuc return DenseMapInfo<PairTy>::getHashValue(PairTy(Base.getBase(), 71*f4a2713aSLionel Sambuc Base.getBaseOffset())); 72*f4a2713aSLionel Sambuc } 73*f4a2713aSLionel Sambuc 74*f4a2713aSLionel Sambuc static bool isEqual(const clang::BaseSubobject &LHS, 75*f4a2713aSLionel Sambuc const clang::BaseSubobject &RHS) { 76*f4a2713aSLionel Sambuc return LHS == RHS; 77*f4a2713aSLionel Sambuc } 78*f4a2713aSLionel Sambuc }; 79*f4a2713aSLionel Sambuc 80*f4a2713aSLionel Sambuc // It's OK to treat BaseSubobject as a POD type. 81*f4a2713aSLionel Sambuc template <> struct isPodLike<clang::BaseSubobject> { 82*f4a2713aSLionel Sambuc static const bool value = true; 83*f4a2713aSLionel Sambuc }; 84*f4a2713aSLionel Sambuc 85*f4a2713aSLionel Sambuc } 86*f4a2713aSLionel Sambuc 87*f4a2713aSLionel Sambuc #endif 88