BaseSubobject.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- BaseSubobject.h - BaseSubobject class --------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file provides a definition of the BaseSubobject class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_BASESUBOBJECT_H
  18. #define LLVM_CLANG_AST_BASESUBOBJECT_H
  19. #include "clang/AST/CharUnits.h"
  20. #include "clang/AST/DeclCXX.h"
  21. #include "llvm/ADT/DenseMapInfo.h"
  22. #include "llvm/Support/type_traits.h"
  23. #include <cstdint>
  24. #include <utility>
  25. namespace clang {
  26. class CXXRecordDecl;
  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.
  30. class BaseSubobject {
  31. /// Base - The base class declaration.
  32. const CXXRecordDecl *Base;
  33. /// BaseOffset - The offset from the most derived class to the base class.
  34. CharUnits BaseOffset;
  35. public:
  36. BaseSubobject() = default;
  37. BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
  38. : Base(Base), BaseOffset(BaseOffset) {}
  39. /// getBase - Returns the base class declaration.
  40. const CXXRecordDecl *getBase() const { return Base; }
  41. /// getBaseOffset - Returns the base class offset.
  42. CharUnits getBaseOffset() const { return BaseOffset; }
  43. friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) {
  44. return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset;
  45. }
  46. };
  47. } // namespace clang
  48. namespace llvm {
  49. template<> struct DenseMapInfo<clang::BaseSubobject> {
  50. static clang::BaseSubobject getEmptyKey() {
  51. return clang::BaseSubobject(
  52. DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(),
  53. clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getEmptyKey()));
  54. }
  55. static clang::BaseSubobject getTombstoneKey() {
  56. return clang::BaseSubobject(
  57. DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(),
  58. clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getTombstoneKey()));
  59. }
  60. static unsigned getHashValue(const clang::BaseSubobject &Base) {
  61. using PairTy = std::pair<const clang::CXXRecordDecl *, clang::CharUnits>;
  62. return DenseMapInfo<PairTy>::getHashValue(PairTy(Base.getBase(),
  63. Base.getBaseOffset()));
  64. }
  65. static bool isEqual(const clang::BaseSubobject &LHS,
  66. const clang::BaseSubobject &RHS) {
  67. return LHS == RHS;
  68. }
  69. };
  70. } // namespace llvm
  71. #endif // LLVM_CLANG_AST_BASESUBOBJECT_H
  72. #ifdef __GNUC__
  73. #pragma GCC diagnostic pop
  74. #endif