clang  10.0.0svn
BaseSubobject.h
Go to the documentation of this file.
1 //===- BaseSubobject.h - BaseSubobject class --------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides a definition of the BaseSubobject class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_AST_BASESUBOBJECT_H
14 #define LLVM_CLANG_AST_BASESUBOBJECT_H
15 
16 #include "clang/AST/CharUnits.h"
17 #include "clang/AST/DeclCXX.h"
18 #include "llvm/ADT/DenseMapInfo.h"
19 #include "llvm/Support/type_traits.h"
20 #include <cstdint>
21 #include <utility>
22 
23 namespace clang {
24 
25 class CXXRecordDecl;
26 
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;
33 
34  /// BaseOffset - The offset from the most derived class to the base class.
35  CharUnits BaseOffset;
36 
37 public:
38  BaseSubobject() = default;
39  BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
40  : Base(Base), BaseOffset(BaseOffset) {}
41 
42  /// getBase - Returns the base class declaration.
43  const CXXRecordDecl *getBase() const { return Base; }
44 
45  /// getBaseOffset - Returns the base class offset.
46  CharUnits getBaseOffset() const { return BaseOffset; }
47 
48  friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) {
49  return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset;
50  }
51 };
52 
53 } // namespace clang
54 
55 namespace llvm {
56 
57 template<> struct DenseMapInfo<clang::BaseSubobject> {
59  return clang::BaseSubobject(
62  }
63 
65  return clang::BaseSubobject(
68  }
69 
70  static unsigned getHashValue(const clang::BaseSubobject &Base) {
71  using PairTy = std::pair<const clang::CXXRecordDecl *, clang::CharUnits>;
72 
73  return DenseMapInfo<PairTy>::getHashValue(PairTy(Base.getBase(),
74  Base.getBaseOffset()));
75  }
76 
77  static bool isEqual(const clang::BaseSubobject &LHS,
78  const clang::BaseSubobject &RHS) {
79  return LHS == RHS;
80  }
81 };
82 
83 } // namespace llvm
84 
85 #endif // LLVM_CLANG_AST_BASESUBOBJECT_H
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
Definition: BaseSubobject.h:46
static bool isEqual(const clang::BaseSubobject &LHS, const clang::BaseSubobject &RHS)
Definition: BaseSubobject.h:77
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS)
Definition: BaseSubobject.h:48
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
Definition: BaseSubobject.h:43
static clang::BaseSubobject getTombstoneKey()
Definition: BaseSubobject.h:64
BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
Definition: BaseSubobject.h:39
static unsigned getHashValue(const clang::BaseSubobject &Base)
Definition: BaseSubobject.h:70
Dataflow Directional Tag Classes.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
static clang::BaseSubobject getEmptyKey()
Definition: BaseSubobject.h:58
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255