[Lldb-commits] [lldb] [lldb] Upgrade `GetIndexOfChildWithName` to use `llvm::Expected` (PR #136693)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 22 08:09:38 PDT 2025
================
@@ -319,40 +319,41 @@ ValueObjectSynthetic::GetChildMemberWithName(llvm::StringRef name,
bool can_create) {
UpdateValueIfNeeded();
- uint32_t index = GetIndexOfChildWithName(name);
+ auto index_or_err = GetIndexOfChildWithName(name);
- if (index == UINT32_MAX)
+ if (!index_or_err)
return lldb::ValueObjectSP();
- return GetChildAtIndex(index, can_create);
+ return GetChildAtIndex(*index_or_err, can_create);
}
-size_t ValueObjectSynthetic::GetIndexOfChildWithName(llvm::StringRef name_ref) {
+llvm::Expected<size_t>
+ValueObjectSynthetic::GetIndexOfChildWithName(llvm::StringRef name_ref) {
UpdateValueIfNeeded();
ConstString name(name_ref);
- uint32_t found_index = UINT32_MAX;
- bool did_find;
+ std::optional<uint32_t> found_index = std::nullopt;
{
std::lock_guard<std::mutex> guard(m_child_mutex);
auto name_to_index = m_name_toindex.find(name.GetCString());
- did_find = name_to_index != m_name_toindex.end();
- if (did_find)
+ if (name_to_index != m_name_toindex.end())
found_index = name_to_index->second;
}
- if (!did_find && m_synth_filter_up != nullptr) {
- uint32_t index = m_synth_filter_up->GetIndexOfChildWithName(name);
- if (index == UINT32_MAX)
- return index;
+ if (!found_index.has_value() && m_synth_filter_up != nullptr) {
+ auto index_or_err = m_synth_filter_up->GetIndexOfChildWithName(name);
+ if (!index_or_err)
+ return llvm::createStringError("Cannot find index of child '%s'",
+ name.AsCString());
----------------
Michael137 wrote:
```suggestion
return index_or_err.takeError();
```
https://github.com/llvm/llvm-project/pull/136693
More information about the lldb-commits
mailing list