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(impl_sp->GetChildMemberWithName(
"__index",
true));
89 return LibcxxVariantIndexValidity::Invalid;
100 std::optional<uint64_t> index_type_bytes = index_type.
GetByteSize(
nullptr);
101 if (!index_type_bytes)
102 return LibcxxVariantIndexValidity::Invalid;
104 uint64_t npos_value = VariantNposValue(*index_type_bytes);
105 uint64_t index_value = index_sp->GetValueAsUnsigned(0);
107 if (index_value == npos_value)
108 return LibcxxVariantIndexValidity::NPos;
110 return LibcxxVariantIndexValidity::Valid;
113std::optional<uint64_t> LibcxxVariantIndexValue(ValueObjectSP &impl_sp) {
114 ValueObjectSP index_sp(impl_sp->GetChildMemberWithName(
"__index",
true));
119 return {index_sp->GetValueAsUnsigned(0)};
122ValueObjectSP LibcxxVariantGetNthHead(ValueObjectSP &impl_sp, uint64_t index) {
123 ValueObjectSP data_sp(impl_sp->GetChildMemberWithName(
"__data",
true));
126 return ValueObjectSP{};
128 ValueObjectSP current_level = data_sp;
129 for (uint64_t n = index; n != 0; --n) {
130 ValueObjectSP tail_sp(
131 current_level->GetChildMemberWithName(
"__tail",
true));
134 return ValueObjectSP{};
136 current_level = tail_sp;
139 return current_level->GetChildMemberWithName(
"__head",
true);
144namespace formatters {
157 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
159 if (validity == LibcxxVariantIndexValidity::Invalid)
162 if (validity == LibcxxVariantIndexValidity::NPos) {
163 stream.
Printf(
" No Value");
167 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
169 if (!optional_index_value)
172 uint64_t index_value = *optional_index_value;
174 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
217bool VariantFrontEnd::Update() {
224 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
226 if (validity == LibcxxVariantIndexValidity::Invalid)
229 if (validity == LibcxxVariantIndexValidity::NPos)
237ValueObjectSP VariantFrontEnd::GetChildAtIndex(
size_t idx) {
246 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
248 if (!optional_index_value)
251 uint64_t index_value = *optional_index_value;
253 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
268 ValueObjectSP head_value(nth_head->GetChildMemberWithName(
"__value",
true));
278 lldb::ValueObjectSP valobj_sp) {
280 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.