Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:29

0001 //===- BaseSubobject.h - BaseSubobject class --------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file provides a definition of the BaseSubobject class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_BASESUBOBJECT_H
0014 #define LLVM_CLANG_AST_BASESUBOBJECT_H
0015 
0016 #include "clang/AST/CharUnits.h"
0017 #include "clang/AST/DeclCXX.h"
0018 #include "llvm/ADT/DenseMapInfo.h"
0019 #include "llvm/Support/type_traits.h"
0020 #include <cstdint>
0021 #include <utility>
0022 
0023 namespace clang {
0024 
0025 class CXXRecordDecl;
0026 
0027 // BaseSubobject - Uniquely identifies a direct or indirect base class.
0028 // Stores both the base class decl and the offset from the most derived class to
0029 // the base class. Used for vtable and VTT generation.
0030 class BaseSubobject {
0031   /// Base - The base class declaration.
0032   const CXXRecordDecl *Base;
0033 
0034   /// BaseOffset - The offset from the most derived class to the base class.
0035   CharUnits BaseOffset;
0036 
0037 public:
0038   BaseSubobject() = default;
0039   BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
0040       : Base(Base), BaseOffset(BaseOffset) {}
0041 
0042   /// getBase - Returns the base class declaration.
0043   const CXXRecordDecl *getBase() const { return Base; }
0044 
0045   /// getBaseOffset - Returns the base class offset.
0046   CharUnits getBaseOffset() const { return BaseOffset; }
0047 
0048   friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) {
0049     return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset;
0050  }
0051 };
0052 
0053 } // namespace clang
0054 
0055 namespace llvm {
0056 
0057 template<> struct DenseMapInfo<clang::BaseSubobject> {
0058   static clang::BaseSubobject getEmptyKey() {
0059     return clang::BaseSubobject(
0060       DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(),
0061       clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getEmptyKey()));
0062   }
0063 
0064   static clang::BaseSubobject getTombstoneKey() {
0065     return clang::BaseSubobject(
0066       DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(),
0067       clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getTombstoneKey()));
0068   }
0069 
0070   static unsigned getHashValue(const clang::BaseSubobject &Base) {
0071     using PairTy = std::pair<const clang::CXXRecordDecl *, clang::CharUnits>;
0072 
0073     return DenseMapInfo<PairTy>::getHashValue(PairTy(Base.getBase(),
0074                                                      Base.getBaseOffset()));
0075   }
0076 
0077   static bool isEqual(const clang::BaseSubobject &LHS,
0078                       const clang::BaseSubobject &RHS) {
0079     return LHS == RHS;
0080   }
0081 };
0082 
0083 } // namespace llvm
0084 
0085 #endif // LLVM_CLANG_AST_BASESUBOBJECT_H