@@ -32,30 +32,34 @@ struct DescriptorFinderForwarder : public swift::reflection::DescriptorFinder {
32
32
33
33
std::unique_ptr<swift::reflection::BuiltinTypeDescriptorBase>
34
34
getBuiltinTypeDescriptor (const swift::reflection::TypeRef *TR) override {
35
- if (m_descriptor_finder && shouldConsultDescriptorFinder ())
36
- return m_descriptor_finder ->getBuiltinTypeDescriptor (TR);
35
+ if (!m_descriptor_finders. empty () && shouldConsultDescriptorFinder ())
36
+ return m_descriptor_finders. back () ->getBuiltinTypeDescriptor (TR);
37
37
return nullptr ;
38
38
}
39
39
40
40
std::unique_ptr<swift::reflection::FieldDescriptorBase>
41
41
getFieldDescriptor (const swift::reflection::TypeRef *TR) override {
42
- if (m_descriptor_finder && shouldConsultDescriptorFinder ())
43
- return m_descriptor_finder ->getFieldDescriptor (TR);
42
+ if (!m_descriptor_finders. empty () && shouldConsultDescriptorFinder ())
43
+ return m_descriptor_finders. back () ->getFieldDescriptor (TR);
44
44
return nullptr ;
45
45
}
46
46
47
47
std::unique_ptr<swift::reflection::MultiPayloadEnumDescriptorBase>
48
48
getMultiPayloadEnumDescriptor (const swift::reflection::TypeRef *TR) override {
49
- if (m_descriptor_finder && shouldConsultDescriptorFinder ())
50
- return m_descriptor_finder ->getMultiPayloadEnumDescriptor (TR);
49
+ if (!m_descriptor_finders. empty () && shouldConsultDescriptorFinder ())
50
+ return m_descriptor_finders. back () ->getMultiPayloadEnumDescriptor (TR);
51
51
return nullptr ;
52
52
}
53
- void SetExternalDescriptorFinder (
54
- swift::reflection::DescriptorFinder *desciptor_finder) {
55
- m_descriptor_finder = desciptor_finder;
53
+
54
+ void PushExternalDescriptorFinder (
55
+ swift::reflection::DescriptorFinder *descriptor_finder) {
56
+ m_descriptor_finders.push_back (descriptor_finder);
56
57
}
57
58
58
- void ClearExternalDescriptorFinder () { m_descriptor_finder = nullptr ; }
59
+ void PopExternalDescriptorFinder () {
60
+ assert (!m_descriptor_finders.empty () && " m_descriptor_finders is empty!" );
61
+ m_descriptor_finders.pop_back ();
62
+ }
59
63
60
64
void SetImageAdded (bool image_added) {
61
65
m_image_added |= image_added;
@@ -76,7 +80,8 @@ struct DescriptorFinderForwarder : public swift::reflection::DescriptorFinder {
76
80
}
77
81
}
78
82
79
- swift::reflection::DescriptorFinder *m_descriptor_finder = nullptr ;
83
+ llvm::SmallVector<swift::reflection::DescriptorFinder *, 1 >
84
+ m_descriptor_finders;
80
85
bool m_image_added = false ;
81
86
};
82
87
@@ -138,17 +143,17 @@ class TargetReflectionContext : public ReflectionContextInterface {
138
143
}
139
144
140
145
// / Sets the descriptor finder, and on scope exit clears it out.
141
- auto SetDescriptorFinderAndClearOnExit (
146
+ auto PushDescriptorFinderAndPopOnExit (
142
147
swift::reflection::DescriptorFinder *descriptor_finder) {
143
- m_forwader.SetExternalDescriptorFinder (descriptor_finder);
148
+ m_forwader.PushExternalDescriptorFinder (descriptor_finder);
144
149
return llvm::make_scope_exit (
145
- [&]() { m_forwader.ClearExternalDescriptorFinder (); });
150
+ [&]() { m_forwader.PopExternalDescriptorFinder (); });
146
151
}
147
152
148
153
const swift::reflection::TypeRef *GetTypeRefOrNull (
149
154
swift::Demangle::Demangler &dem, swift::Demangle::NodePointer node,
150
155
swift::reflection::DescriptorFinder *descriptor_finder) override {
151
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
156
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
152
157
auto type_ref_or_err =
153
158
swift::Demangle::decodeMangledType (m_reflection_ctx.getBuilder (), node);
154
159
if (type_ref_or_err.isError ()) {
@@ -164,7 +169,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
164
169
const swift::reflection::TypeRef *type_ref,
165
170
swift::remote::TypeInfoProvider *provider,
166
171
swift::reflection::DescriptorFinder *descriptor_finder) override {
167
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
172
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
168
173
if (!type_ref)
169
174
return nullptr ;
170
175
@@ -188,7 +193,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
188
193
GetTypeInfo (const swift::reflection::TypeRef *type_ref,
189
194
swift::remote::TypeInfoProvider *provider,
190
195
swift::reflection::DescriptorFinder *descriptor_finder) override {
191
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
196
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
192
197
if (!type_ref)
193
198
return nullptr ;
194
199
@@ -226,7 +231,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
226
231
const swift::reflection::TypeInfo *GetTypeInfoFromInstance (
227
232
lldb::addr_t instance, swift::remote::TypeInfoProvider *provider,
228
233
swift::reflection::DescriptorFinder *descriptor_finder) override {
229
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
234
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
230
235
return m_reflection_ctx.getInstanceTypeInfo (instance, provider);
231
236
}
232
237
@@ -237,7 +242,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
237
242
const swift::reflection::TypeRef *LookupSuperclass (
238
243
const swift::reflection::TypeRef *tr,
239
244
swift::reflection::DescriptorFinder *descriptor_finder) override {
240
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
245
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
241
246
return m_reflection_ctx.getBuilder ().lookupSuperclass (tr);
242
247
}
243
248
@@ -263,7 +268,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
263
268
swift::reflection::DescriptorFinder *descriptor_finder,
264
269
lldb::addr_t pointer,
265
270
std::function<bool (SuperClassType)> fn) override {
266
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
271
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
267
272
// Guard against faulty self-referential metadata.
268
273
unsigned limit = 256 ;
269
274
auto md_ptr = m_reflection_ctx.readMetadataFromInstance (pointer);
@@ -298,7 +303,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
298
303
const swift::reflection::TypeRef *enum_type_ref,
299
304
swift::remote::TypeInfoProvider *provider,
300
305
swift::reflection::DescriptorFinder *descriptor_finder) override {
301
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
306
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
302
307
int32_t case_idx;
303
308
if (m_reflection_ctx.projectEnumValue (enum_addr, enum_type_ref, &case_idx,
304
309
provider))
@@ -312,7 +317,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
312
317
swift::reflection::RemoteAddress existential_address,
313
318
const swift::reflection::TypeRef &existential_tr,
314
319
swift::reflection::DescriptorFinder *descriptor_finder) override {
315
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
320
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
316
321
return m_reflection_ctx.projectExistentialAndUnwrapClass (
317
322
existential_address, existential_tr);
318
323
}
@@ -321,7 +326,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
321
326
ReadTypeFromMetadata (lldb::addr_t metadata_address,
322
327
swift::reflection::DescriptorFinder *descriptor_finder,
323
328
bool skip_artificial_subclasses) override {
324
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
329
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
325
330
return m_reflection_ctx.readTypeFromMetadata (metadata_address,
326
331
skip_artificial_subclasses);
327
332
}
@@ -330,7 +335,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
330
335
ReadTypeFromInstance (lldb::addr_t instance_address,
331
336
swift::reflection::DescriptorFinder *descriptor_finder,
332
337
bool skip_artificial_subclasses) override {
333
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
338
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
334
339
auto metadata_address =
335
340
m_reflection_ctx.readMetadataFromInstance (instance_address);
336
341
if (!metadata_address) {
@@ -354,7 +359,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
354
359
const swift::reflection::TypeRef *type_ref,
355
360
swift::reflection::GenericArgumentMap substitutions,
356
361
swift::reflection::DescriptorFinder *descriptor_finder) override {
357
- auto on_exit = SetDescriptorFinderAndClearOnExit (descriptor_finder);
362
+ auto on_exit = PushDescriptorFinderAndPopOnExit (descriptor_finder);
358
363
return type_ref->subst (m_reflection_ctx.getBuilder (), substitutions);
359
364
}
360
365
0 commit comments