@@ -38,38 +38,45 @@ std::string lldb_private::formatters::swift::SwiftOptionalSummaryProvider::
38
38
return sstr.GetString ().str ();
39
39
}
40
40
41
- // if this ValueObject is an Optional<T> with the Some(T) case selected,
42
- // retrieve the value of the Some case..
43
- static ValueObjectSP
41
+ // / If this ValueObject is an Optional<T> with the Some(T) case selected,
42
+ // / retrieve the value of the Some case.
43
+ // /
44
+ // / Returns {} on error, nullptr on .none, and a ValueObject on .some.
45
+ // / None of the callees can pass on errors messages, so this function
46
+ // / doesn't return them either.
47
+ static std::optional<ValueObjectSP>
44
48
ExtractSomeIfAny (ValueObject *optional,
45
49
bool synthetic_value = false ) {
46
50
if (!optional)
47
- return nullptr ;
51
+ return {} ;
48
52
49
53
static ConstString g_Some (" some" );
50
54
static ConstString g_None (" none" );
51
55
52
56
ValueObjectSP non_synth_valobj = optional->GetNonSyntheticValue ();
53
57
if (!non_synth_valobj)
54
- return nullptr ;
58
+ return {} ;
55
59
56
60
ConstString value (non_synth_valobj->GetValueAsCString ());
57
61
58
- if (!value || value == g_None)
62
+ if (!value)
63
+ return {};
64
+
65
+ if (value == g_None)
59
66
return nullptr ;
60
67
61
68
ValueObjectSP value_sp (
62
69
non_synth_valobj->GetChildMemberWithName (g_Some, true ));
63
70
if (!value_sp)
64
- return nullptr ;
71
+ return {} ;
65
72
66
73
auto process_sp = optional->GetProcessSP ();
67
74
auto *swift_runtime = SwiftLanguageRuntime::Get (process_sp);
68
75
69
76
CompilerType type = non_synth_valobj->GetCompilerType ();
70
77
auto type_system = type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwift>();
71
78
if (!type_system)
72
- return nullptr ;
79
+ return {} ;
73
80
if (auto kind = type_system->GetNonTriviallyManagedReferenceKind (
74
81
type.GetOpaqueQualType ())) {
75
82
if (*kind == TypeSystemSwift::NonTriviallyManagedReferenceKind::eWeak) {
@@ -86,10 +93,10 @@ ExtractSomeIfAny(ValueObject *optional,
86
93
DataExtractor extractor (buffer_sp, process_sp->GetByteOrder (),
87
94
process_sp->GetAddressByteSize ());
88
95
ExecutionContext exe_ctx (process_sp);
89
- value_sp = ValueObjectSP ( ValueObject::CreateValueObjectFromData (
90
- value_sp->GetName ().AsCString (), extractor, exe_ctx, value_type)) ;
96
+ value_sp = ValueObject::CreateValueObjectFromData (
97
+ value_sp->GetName ().AsCString (), extractor, exe_ctx, value_type);
91
98
if (!value_sp)
92
- return nullptr ;
99
+ return {} ;
93
100
else
94
101
value_sp->SetSyntheticChildrenGenerated (true );
95
102
}
@@ -121,7 +128,11 @@ ExtractSomeIfAny(ValueObject *optional,
121
128
static bool
122
129
SwiftOptional_SummaryProvider_Impl (ValueObject &valobj, Stream &stream,
123
130
const TypeSummaryOptions &options) {
124
- ValueObjectSP some = ExtractSomeIfAny (&valobj, true );
131
+ std::optional<ValueObjectSP> maybe_some = ExtractSomeIfAny (&valobj, true );
132
+ if (!maybe_some)
133
+ return false ;
134
+
135
+ ValueObjectSP some = *maybe_some;
125
136
if (!some) {
126
137
stream.Printf (" nil" );
127
138
return true ;
@@ -172,8 +183,12 @@ bool lldb_private::formatters::swift::SwiftOptionalSummaryProvider::
172
183
if (!target_valobj)
173
184
return false ;
174
185
175
- ValueObjectSP some = ExtractSomeIfAny (target_valobj, true );
186
+ std::optional<ValueObjectSP> maybe_some =
187
+ ExtractSomeIfAny (target_valobj, true );
188
+ if (!maybe_some)
189
+ return false ;
176
190
191
+ ValueObjectSP some = *maybe_some;
177
192
if (!some)
178
193
return true ;
179
194
@@ -231,7 +246,12 @@ lldb::ChildCacheState lldb_private::formatters::swift::SwiftOptionalSyntheticFro
231
246
m_is_none = true ;
232
247
m_children = false ;
233
248
234
- m_some = ExtractSomeIfAny (&m_backend, true );
249
+ std::optional<ValueObjectSP> maybe_some =
250
+ ExtractSomeIfAny (&m_backend, true );
251
+ if (!maybe_some)
252
+ return ChildCacheState::eRefetch;
253
+
254
+ m_some = *maybe_some;
235
255
236
256
if (!m_some) {
237
257
m_is_none = true ;
0 commit comments