9#ifndef LLVM_CLANG_AST_INTERP_MEMBER_POINTER_H
10#define LLVM_CLANG_AST_INTERP_MEMBER_POINTER_H
13#include "llvm/ADT/PointerIntPair.h"
23class MemberPointer final {
29 llvm::PointerIntPair<const ValueDecl *, 1, bool> DeclAndIsDerivedMember;
34 int32_t PtrOffset = 0;
35 uint8_t PathLength = 0;
39 bool IsDerived =
false)
40 : Base(Base), DeclAndIsDerivedMember(Dcl, IsDerived), Path(Path),
41 PtrOffset(PtrOffset), PathLength(PathLength) {}
46 : Base(Base), DeclAndIsDerivedMember(Dcl) {}
59 "getIntegerRepresentation() shouldn't be reachable for MemberPointers");
64 bool hasDecl()
const {
return DeclAndIsDerivedMember.getPointer(); }
68 return DeclAndIsDerivedMember.getPointer();
71 bool hasPath()
const {
return PathLength != 0; }
76 assert(Index < PathLength);
82 bool hasBase()
const {
return !Base.isZero(); }
93 assert(Path != NewPath);
106 return static_cast<uint64_t
>(PtrOffset) <= Base.getByteOffset();
111 return Base.
atField(-PtrOffset);
116 return isa_and_nonnull<CXXMethodDecl>(DeclAndIsDerivedMember.getPointer());
120 return dyn_cast_if_present<CXXMethodDecl>(
121 DeclAndIsDerivedMember.getPointer());
125 return dyn_cast_if_present<FieldDecl>(DeclAndIsDerivedMember.getPointer());
133 return MD->getParent();
139 bool NewIsDerived =
false)
const {
141 return MemberPointer(Base, DeclAndIsDerivedMember.getPointer(), Offset,
142 PathLength, Path, NewIsDerived);
143 return MemberPointer(this->Base, DeclAndIsDerivedMember.getPointer(),
144 Offset + PtrOffset, PathLength, Path, NewIsDerived);
148 assert(this->Base.
isZero());
149 return MemberPointer(Instance, DeclAndIsDerivedMember.getPointer(),
155 void print(llvm::raw_ostream &OS)
const {
156 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.
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.