clang 8.0.0

BaseSubobject.h
Go to the documentation of this file.
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;
40 BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
41 : Base(Base), BaseOffset(BaseOffset) {}
42
43 /// getBase - Returns the base class declaration.
44 const CXXRecordDecl *getBase() const { return Base; }
45
46 /// getBaseOffset - Returns the base class offset.
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
llvm
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
Base
llvm::DenseMapInfo
Definition: TypeOrdering.h:38
clang::BaseSubobject::getBaseOffset
CharUnits getBaseOffset() const
getBaseOffset - Returns the base class offset.
Definition: BaseSubobject.h:47
CharUnits.h
llvm::DenseMapInfo< clang::BaseSubobject >::isEqual
static bool isEqual(const clang::BaseSubobject &LHS, const clang::BaseSubobject &RHS)
Definition: BaseSubobject.h:78
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::BaseSubobject::BaseSubobject
BaseSubobject()=default
clang::BaseSubobject::operator==
friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS)
Definition: BaseSubobject.h:49
clang::CharUnits::fromQuantity
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
clang::BaseSubobject::getBase
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
Definition: BaseSubobject.h:44
clang::BaseSubobject
Definition: BaseSubobject.h:31
llvm::DenseMapInfo< clang::BaseSubobject >::getTombstoneKey
static clang::BaseSubobject getTombstoneKey()
Definition: BaseSubobject.h:65
clang::BaseSubobject::BaseSubobject
BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
Definition: BaseSubobject.h:40
llvm::isPodLike
Definition: DeclAccessPair.h:66
llvm::DenseMapInfo< clang::BaseSubobject >::getHashValue
static unsigned getHashValue(const clang::BaseSubobject &Base)
Definition: BaseSubobject.h:71
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
DeclCXX.h
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
llvm::DenseMapInfo< clang::BaseSubobject >::getEmptyKey
static clang::BaseSubobject getEmptyKey()
Definition: BaseSubobject.h:59
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300