[lldb] Upgrade GetIndexOfChildWithName to use llvm::Expected (#136693)
This patch replaces the use of `UINT32_MAX` as the error return value of `GetIndexOfChildWithName` with `llvm::Expected`. # Tasks to do in another PR 1. Replace `CalculateNumChildrenIgnoringErrors` with `CalculateNumChildren`. See [this comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056319358). 2. Update `lldb_private::formatters::ExtractIndexFromString` to use `llvm::Expected`. See [this comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2054217536). 3. Create a new class which carries both user and internal errors. See [this comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056439608).
This commit is contained in:
@@ -2037,19 +2037,19 @@ lldb::ValueObjectSP ScriptInterpreterPythonImpl::GetChildAtIndex(
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
int ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
|
||||
llvm::Expected<int> ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
|
||||
const StructuredData::ObjectSP &implementor_sp, const char *child_name) {
|
||||
if (!implementor_sp)
|
||||
return UINT32_MAX;
|
||||
return llvm::createStringError("Type has no child named '%s'", child_name);
|
||||
|
||||
StructuredData::Generic *generic = implementor_sp->GetAsGeneric();
|
||||
if (!generic)
|
||||
return UINT32_MAX;
|
||||
return llvm::createStringError("Type has no child named '%s'", child_name);
|
||||
auto *implementor = static_cast<PyObject *>(generic->GetValue());
|
||||
if (!implementor)
|
||||
return UINT32_MAX;
|
||||
return llvm::createStringError("Type has no child named '%s'", child_name);
|
||||
|
||||
int ret_val = UINT32_MAX;
|
||||
int ret_val = INT32_MAX;
|
||||
|
||||
{
|
||||
Locker py_lock(this,
|
||||
@@ -2058,6 +2058,8 @@ int ScriptInterpreterPythonImpl::GetIndexOfChildWithName(
|
||||
child_name);
|
||||
}
|
||||
|
||||
if (ret_val == INT32_MAX)
|
||||
return llvm::createStringError("Type has no child named '%s'", child_name);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user