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);
76 return static_cast<uint16_t
>(-1);
78 return static_cast<uint32_t
>(-1);
80 lldbassert(
false &&
"Unknown index type size");
81 return static_cast<uint32_t
>(-1);
84LibcxxVariantIndexValidity
86 ValueObjectSP index_sp(impl_sp->GetChildMemberWithName(
"__index"));
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"));
119 return {index_sp->GetValueAsUnsigned(0)};
123 ValueObjectSP data_sp(impl_sp->GetChildMemberWithName(
"__data"));
129 for (uint64_t n = index; n != 0; --n) {
130 ValueObjectSP tail_sp(current_level->GetChildMemberWithName(
"__tail"));
135 current_level = tail_sp;
138 return current_level->GetChildMemberWithName(
"__head");
143namespace formatters {
156 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
158 if (validity == LibcxxVariantIndexValidity::Invalid)
161 if (validity == LibcxxVariantIndexValidity::NPos) {
162 stream.
Printf(
" No Value");
166 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
168 if (!optional_index_value)
171 uint64_t index_value = *optional_index_value;
173 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
223 LibcxxVariantIndexValidity validity = LibcxxVariantGetIndexValidity(impl_sp);
225 if (validity == LibcxxVariantIndexValidity::Invalid)
228 if (validity == LibcxxVariantIndexValidity::NPos)
236ValueObjectSP VariantFrontEnd::GetChildAtIndex(uint32_t idx) {
245 auto optional_index_value = LibcxxVariantIndexValue(impl_sp);
247 if (!optional_index_value)
250 uint64_t index_value = *optional_index_value;
252 ValueObjectSP nth_head = LibcxxVariantGetNthHead(impl_sp, index_value);
267 ValueObjectSP head_value(nth_head->GetChildMemberWithName(
"__value"));
279 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 lldb::ValueObjectSP GetChildAtIndex(uint32_t idx)=0
virtual lldb::ChildCacheState Update()=0
This function is assumed to always succeed and if it fails, the front-end should know to deal with it...
virtual bool MightHaveChildren()=0
virtual size_t GetIndexOfChildWithName(ConstString name)=0
virtual llvm::Expected< uint32_t > CalculateNumChildren()=0
virtual lldb::ValueObjectSP GetNonSyntheticValue()
A class that represents a running process on the host machine.
ChildCacheState
Specifies if children need to be re-computed after a call to SyntheticChildrenFrontEnd::Update.
@ eRefetch
Children need to be recomputed dynamically.
@ eReuse
Children did not change and don't need to be recomputed; re-use what we computed the last time we cal...
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP