15#include "llvm/ADT/ScopeExit.h"
69enum class LibcxxVariantIndexValidity { Valid,
Invalid, NPos };
71uint64_t VariantNposValue(uint64_t index_byte_size) {
72 switch (index_byte_size) {
74 return static_cast<uint8_t
>(-1);
80 lldbassert(
false &&
"Unknown index type size");
84LibcxxVariantIndexValidity
85LibcxxVariantGetIndexValidity(ValueObjectSP &impl_sp) {
86 ValueObjectSP index_sp(
87 impl_sp->GetChildMemberWithName(
ConstString(
"__index"),
true));
90 return LibcxxVariantIndexValidity::Invalid;
101 std::optional<uint64_t> index_type_bytes = index_type.
GetByteSize(
nullptr);
102 if (!index_type_bytes)
103 return LibcxxVariantIndexValidity::Invalid;
105 uint64_t npos_value = VariantNposValue(*index_type_bytes);
106 uint64_t index_value = index_sp->GetValueAsUnsigned(0);
108 if (index_value == npos_value)
109 return LibcxxVariantIndexValidity::NPos;
111 return LibcxxVariantIndexValidity::Valid;
114std::optional<uint64_t> LibcxxVariantIndexValue(ValueObjectSP &impl_sp) {
115 ValueObjectSP index_sp(
116 impl_sp->GetChildMemberWithName(
ConstString(
"__index"),
true));
121 return {index_sp->GetValueAsUnsigned(0)};
124ValueObjectSP LibcxxVariantGetNthHead(ValueObjectSP &impl_sp, uint64_t index) {
125 ValueObjectSP data_sp(
126 impl_sp->GetChildMemberWithName(
ConstString(
"__data"),
true));
129 return ValueObjectSP{};
131 ValueObjectSP current_level = data_sp;
132 for (uint64_t n = index; n != 0; --n) {
133 ValueObjectSP tail_sp(
134 current_level->GetChildMemberWithName(
ConstString(
"__tail"),
true));
137 return ValueObjectSP{};
139 current_level = tail_sp;
142 return current_level->GetChildMemberWithName(
ConstString(
"__head"),
true);
147namespace formatters {
160 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
162 if (validity == LibcxxVariantIndexValidity::Invalid)
165 if (validity == LibcxxVariantIndexValidity::NPos) {
166 stream.
Printf(
" No Value");
170 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
172 if (!optional_index_value)
175 uint64_t index_value = *optional_index_value;
177 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
220bool VariantFrontEnd::Update() {
227 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
229 if (validity == LibcxxVariantIndexValidity::Invalid)
232 if (validity == LibcxxVariantIndexValidity::NPos)
240ValueObjectSP VariantFrontEnd::GetChildAtIndex(
size_t idx) {
249 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
251 if (!optional_index_value)
254 uint64_t index_value = *optional_index_value;
256 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
271 ValueObjectSP head_value(
272 nth_head->GetChildMemberWithName(
ConstString(
"__value"),
true));
282 lldb::ValueObjectSP valobj_sp) {
284 return new VariantFrontEnd(*valobj_sp);
Generic representation of a type in a programming language.
CompilerType GetTypeTemplateArgument(size_t idx, bool expand_pack=false) const
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
ConstString GetDisplayTypeName() const
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
virtual size_t CalculateNumChildren()=0
virtual bool MightHaveChildren()=0
virtual size_t GetIndexOfChildWithName(ConstString name)=0
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx)=0
virtual lldb::ValueObjectSP GetNonSyntheticValue()
A class that represents a running process on the host machine.