1 //===- BaseSubobject.h - BaseSubobject class --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides a definition of the BaseSubobject class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_BASESUBOBJECT_H
15 #define LLVM_CLANG_AST_BASESUBOBJECT_H
17 #include "clang/AST/CharUnits.h"
18 #include "llvm/ADT/DenseMapInfo.h"
19 #include "llvm/Support/type_traits.h"
27 // BaseSubobject - Uniquely identifies a direct or indirect base class.
28 // Stores both the base class decl and the offset from the most derived class to
29 // the base class. Used for vtable and VTT generation.
31 /// Base - The base class declaration.
32 const CXXRecordDecl *Base;
34 /// BaseOffset - The offset from the most derived class to the base class.
38 BaseSubobject() = default;
39 BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
40 : Base(Base), BaseOffset(BaseOffset) {}
42 /// getBase - Returns the base class declaration.
43 const CXXRecordDecl *getBase() const { return Base; }
45 /// getBaseOffset - Returns the base class offset.
46 CharUnits getBaseOffset() const { return BaseOffset; }
48 friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) {
49 return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset;
57 template<> struct DenseMapInfo<clang::BaseSubobject> {
58 static clang::BaseSubobject getEmptyKey() {
59 return clang::BaseSubobject(
60 DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(),
61 clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getEmptyKey()));
64 static clang::BaseSubobject getTombstoneKey() {
65 return clang::BaseSubobject(
66 DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(),
67 clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getTombstoneKey()));
70 static unsigned getHashValue(const clang::BaseSubobject &Base) {
71 using PairTy = std::pair<const clang::CXXRecordDecl *, clang::CharUnits>;
73 return DenseMapInfo<PairTy>::getHashValue(PairTy(Base.getBase(),
74 Base.getBaseOffset()));
77 static bool isEqual(const clang::BaseSubobject &LHS,
78 const clang::BaseSubobject &RHS) {
83 // It's OK to treat BaseSubobject as a POD type.
84 template <> struct isPodLike<clang::BaseSubobject> {
85 static const bool value = true;
90 #endif // LLVM_CLANG_AST_BASESUBOBJECT_H