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