[Lldb-commits] [lldb] [lldb] Improve maintainability and readability for ValueObject methods (PR #75865)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Mon Dec 18 16:18:26 PST 2023
================
@@ -1623,62 +1623,68 @@ bool ValueObject::IsUninitializedReference() {
ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index,
bool can_create) {
- ValueObjectSP synthetic_child_sp;
- if (IsPointerType() || IsArrayType()) {
- std::string index_str = llvm::formatv("[{0}]", index);
- ConstString index_const_str(index_str);
- // Check if we have already created a synthetic array member in this valid
- // object. If we have we will re-use it.
- synthetic_child_sp = GetSyntheticChild(index_const_str);
- if (!synthetic_child_sp) {
- ValueObject *synthetic_child;
- // We haven't made a synthetic array member for INDEX yet, so lets make
- // one and cache it for any future reference.
- synthetic_child = CreateChildAtIndex(0, true, index);
-
- // Cache the value if we got one back...
- if (synthetic_child) {
- AddSyntheticChild(index_const_str, synthetic_child);
- synthetic_child_sp = synthetic_child->GetSP();
- synthetic_child_sp->SetName(ConstString(index_str));
- synthetic_child_sp->m_flags.m_is_array_item_for_pointer = true;
- }
- }
+ if (!IsPointerType() && !IsArrayType()) {
+ return ValueObjectSP();
+ }
+
+ std::string index_str = llvm::formatv("[{0}]", index);
+ ConstString index_const_str(index_str);
+ // Check if we have already created a synthetic array member in this valid
+ // object. If we have we will re-use it.
+ if (auto existing_synthetic_child = GetSyntheticChild(index_const_str)) {
+ return existing_synthetic_child;
+ }
+
+ // We haven't made a synthetic array member for INDEX yet, so lets make
+ // one and cache it for any future reference.
+ ValueObject *synthetic_child = CreateChildAtIndex(0, true, index);
+
+ if (!synthetic_child) {
+ return ValueObjectSP();
}
+
+ // Cache the value if we got one back...
+ AddSyntheticChild(index_const_str, synthetic_child);
+ auto synthetic_child_sp = synthetic_child->GetSP();
+ synthetic_child_sp->SetName(ConstString(index_str));
+ synthetic_child_sp->m_flags.m_is_array_item_for_pointer = true;
return synthetic_child_sp;
}
ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to,
bool can_create) {
- ValueObjectSP synthetic_child_sp;
- if (IsScalarType()) {
- std::string index_str = llvm::formatv("[{0}-{1}]", from, to);
- ConstString index_const_str(index_str);
- // Check if we have already created a synthetic array member in this valid
- // object. If we have we will re-use it.
- synthetic_child_sp = GetSyntheticChild(index_const_str);
- if (!synthetic_child_sp) {
- uint32_t bit_field_size = to - from + 1;
- uint32_t bit_field_offset = from;
- if (GetDataExtractor().GetByteOrder() == eByteOrderBig)
- bit_field_offset =
- GetByteSize().value_or(0) * 8 - bit_field_size - bit_field_offset;
- // We haven't made a synthetic array member for INDEX yet, so lets make
- // one and cache it for any future reference.
- ValueObjectChild *synthetic_child = new ValueObjectChild(
- *this, GetCompilerType(), index_const_str, GetByteSize().value_or(0),
- 0, bit_field_size, bit_field_offset, false, false,
- eAddressTypeInvalid, 0);
-
- // Cache the value if we got one back...
- if (synthetic_child) {
- AddSyntheticChild(index_const_str, synthetic_child);
- synthetic_child_sp = synthetic_child->GetSP();
- synthetic_child_sp->SetName(ConstString(index_str));
- synthetic_child_sp->m_flags.m_is_bitfield_for_scalar = true;
- }
- }
+ if (!IsScalarType()) {
+ ValueObjectSP();
}
+ std::string index_str = llvm::formatv("[{0}-{1}]", from, to);
+ ConstString index_const_str(index_str);
+
+ // Check if we have already created a synthetic array member in this valid
+ // object. If we have we will re-use it.
+ if (auto existing_synthetic_child = GetSyntheticChild(index_const_str)) {
+ return existing_synthetic_child;
+ }
----------------
clayborg wrote:
remove braces
https://github.com/llvm/llvm-project/pull/75865
More information about the lldb-commits
mailing list