9#ifndef LLVM_CLANG_AST_INTERP_MEMBER_POINTER_H
10#define LLVM_CLANG_AST_INTERP_MEMBER_POINTER_H
13#include "llvm/ADT/PointerIntPair.h"
24class MemberPointer final {
30 llvm::PointerIntPair<const ValueDecl *, 1, bool> DeclAndIsDerivedMember;
35 int32_t PtrOffset = 0;
36 uint8_t PathLength = 0;
40 bool IsDerived =
false)
41 : Base(Base), DeclAndIsDerivedMember(Dcl, IsDerived), Path(Path),
42 PtrOffset(PtrOffset), PathLength(PathLength) {}
47 : Base(Base), DeclAndIsDerivedMember(Dcl) {}
60 "getIntegerRepresentation() shouldn't be reachable for MemberPointers");
65 bool hasDecl()
const {
return DeclAndIsDerivedMember.getPointer(); }
69 return DeclAndIsDerivedMember.getPointer();
72 bool hasPath()
const {
return PathLength != 0; }
77 assert(Index < PathLength);
83 bool hasBase()
const {
return !Base.isZero(); }
94 assert(Path != NewPath);
108 return static_cast<uint64_t
>(PtrOffset) <= Base.getByteOffset();
113 return Base.
atField(-PtrOffset);
118 return isa_and_nonnull<CXXMethodDecl>(DeclAndIsDerivedMember.getPointer());
122 return dyn_cast_if_present<CXXMethodDecl>(
123 DeclAndIsDerivedMember.getPointer());
127 return dyn_cast_if_present<FieldDecl>(DeclAndIsDerivedMember.getPointer());
135 return MD->getParent();
141 bool NewIsDerived =
false)
const {
143 return MemberPointer(Base, DeclAndIsDerivedMember.getPointer(), Offset,
144 PathLength, Path, NewIsDerived);
145 return MemberPointer(this->Base, DeclAndIsDerivedMember.getPointer(),
146 Offset + PtrOffset, PathLength, Path, NewIsDerived);
150 assert(this->Base.
isZero());
151 return MemberPointer(Instance, DeclAndIsDerivedMember.getPointer(),
157 void print(llvm::raw_ostream &OS)
const {
158 OS <<
"MemberPtr(" << Base <<
" " << (
const void *)
getDecl() <<
" + "
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Represents a member of a struct/union/class.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Holds all information required to evaluate constexpr code in a module.
const ValueDecl * getDecl() const
Return the base declaration. Might be null.
bool hasDecl() const
Does this member pointer have a base declaration?
APValue toAPValue(const ASTContext &) const
uint64_t getIntegerRepresentation() const
MemberPointer takeInstance(Pointer Instance) const
const CXXRecordDecl * getRecordDecl() const
Returns the record decl this member pointer points into.
const CXXRecordDecl * getPathEntry(unsigned Index) const
Return the cast path entry at the given position.
bool hasPath() const
Does this member pointer have a path (i.e. path length is > 0)?
std::string toDiagnosticString(const ASTContext &Ctx) const
MemberPointer(uint32_t Address, const Descriptor *D)
bool isDerivedMember() const
bool isMemberFunctionPointer() const
Is the base declaration a member function?
MemberPointer(const ValueDecl *D)
const FieldDecl * getField() const
Return the base declaration as a FieldDecl. Might return null.
MemberPointer atInstanceBase(unsigned Offset, uint8_t PathLength=0, const CXXRecordDecl **Path=nullptr, bool NewIsDerived=false) const
void print(llvm::raw_ostream &OS) const
void takePath(const CXXRecordDecl **NewPath)
Sets the path of this member pointer.
unsigned getPathLength() const
Return the length of the cast path.
ComparisonCategoryResult compare(const MemberPointer &RHS) const
const CXXRecordDecl ** path() const
Return the cast path. Might return null.
FunctionPointer toFunctionPointer(const Context &Ctx) const
const CXXMethodDecl * getMemberFunction() const
Return the base declaration as a CXXMethodDecl. Might return null.
std::optional< Pointer > toPointer(const Context &Ctx) const
bool isBaseCastPossible() const
MemberPointer(Pointer Base, const ValueDecl *Dcl)
A pointer to a memory block, live or dead.
Pointer atFieldSub(unsigned Off) const
Subtract the given offset from the current Base and Offset of the pointer.
Pointer atField(unsigned Off) const
Creates a pointer to a field.
bool isZero() const
Checks if the pointer is null.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Boolean &B)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
ComparisonCategoryResult
An enumeration representing the possible results of a three-way comparison.
U cast(CodeGen::Address addr)
Describes a memory block created by an allocation site.