@@ -215,181 +215,26 @@ class TypeRefBuilder {
215
215
216
216
const AssociatedTypeDescriptor *
217
217
lookupAssociatedTypes (const std::string &MangledTypeName,
218
- const DependentMemberTypeRef *DependentMember) {
219
- // Cache missed - we need to look through all of the assocty sections
220
- // for all images that we've been notified about.
221
- for (auto &Info : ReflectionInfos) {
222
- for (const auto &AssocTyDescriptor : Info.assocty ) {
223
- std::string ConformingTypeName (AssocTyDescriptor.ConformingTypeName );
224
- if (ConformingTypeName.compare (MangledTypeName) != 0 )
225
- continue ;
226
- std::string ProtocolMangledName (AssocTyDescriptor.ProtocolTypeName );
227
- auto DemangledProto = Demangle::demangleTypeAsNode (ProtocolMangledName);
228
- auto TR = swift::remote::decodeMangledType (*this , DemangledProto);
229
-
230
- auto &Conformance = *DependentMember->getProtocol ();
231
- if (auto Protocol = dyn_cast<ProtocolTypeRef>(TR)) {
232
- if (*Protocol != Conformance)
233
- continue ;
234
- return &AssocTyDescriptor;
235
- }
236
- }
237
- }
238
- return nullptr ;
239
- }
218
+ const DependentMemberTypeRef *DependentMember);
240
219
241
- public:
220
+ public:
242
221
const TypeRef *
243
222
getDependentMemberTypeRef (const std::string &MangledTypeName,
244
- const DependentMemberTypeRef *DependentMember) {
245
-
246
- if (auto AssocTys = lookupAssociatedTypes (MangledTypeName, DependentMember)) {
247
- for (auto &AssocTy : *AssocTys) {
248
- if (DependentMember->getMember ().compare (AssocTy.getName ()) != 0 )
249
- continue ;
250
-
251
- auto SubstitutedTypeName = AssocTy.getMangledSubstitutedTypeName ();
252
- auto Demangled = Demangle::demangleTypeAsNode (SubstitutedTypeName);
253
- return swift::remote::decodeMangledType (*this , Demangled);
254
- }
255
- }
256
- return nullptr ;
257
- }
223
+ const DependentMemberTypeRef *DependentMember);
258
224
259
225
std::vector<std::pair<std::string, const TypeRef *>>
260
- getFieldTypeRefs (const TypeRef *TR) {
261
- std::string MangledName;
262
- if (auto N = dyn_cast<NominalTypeRef>(TR))
263
- MangledName = N->getMangledName ();
264
- else if (auto BG = dyn_cast<BoundGenericTypeRef>(TR))
265
- MangledName = BG->getMangledName ();
266
- else
267
- return {};
268
-
269
- auto Subs = TR->getSubstMap ();
270
-
271
- std::vector<std::pair<std::string, const TypeRef *>> Fields;
272
- for (auto Info : ReflectionInfos) {
273
- for (auto &FieldDescriptor : Info.fieldmd ) {
274
- auto CandidateMangledName = FieldDescriptor.MangledTypeName .get ();
275
- if (!CandidateMangledName)
276
- continue ;
277
- if (MangledName.compare (CandidateMangledName) != 0 )
278
- continue ;
279
- for (auto &Field : FieldDescriptor) {
280
- auto FieldName = Field.getFieldName ();
281
-
282
- // Empty cases of enums do not have a type
283
- if (!Field.hasMangledTypeName ()) {
284
- Fields.push_back ({FieldName, nullptr });
285
- continue ;
286
- }
287
-
288
- auto Demangled
289
- = Demangle::demangleTypeAsNode (Field.getMangledTypeName ());
290
- auto Unsubstituted = swift::remote::decodeMangledType (*this , Demangled);
291
- if (!Unsubstituted)
292
- return {};
293
-
294
- auto Substituted = Unsubstituted->subst (*this , Subs);
295
- if (FieldName.empty ())
296
- FieldName = " <Redacted Field Name>" ;
297
- Fields.push_back ({FieldName, Substituted});
298
- }
299
- }
300
- }
301
- return Fields;
302
- }
226
+ getFieldTypeRefs (const TypeRef *TR);
303
227
304
228
// /
305
229
// / Dumping typerefs, field declarations, associated types
306
230
// /
307
231
308
232
void dumpTypeRef (const std::string &MangledName,
309
- std::ostream &OS, bool printTypeName = false ) {
310
- auto TypeName = Demangle::demangleTypeAsString (MangledName);
311
- OS << TypeName << ' \n ' ;
312
-
313
- auto DemangleTree = Demangle::demangleTypeAsNode (MangledName);
314
- auto TR = swift::remote::decodeMangledType (*this , DemangleTree);
315
- if (!TR) {
316
- OS << " !!! Invalid typeref: " << MangledName << ' \n ' ;
317
- return ;
318
- }
319
- TR->dump (OS);
320
- OS << ' \n ' ;
321
- }
322
-
323
- void dumpFieldSection (std::ostream &OS) {
324
- for (const auto §ions : ReflectionInfos) {
325
- for (const auto &descriptor : sections.fieldmd ) {
326
- auto TypeName
327
- = Demangle::demangleTypeAsString (descriptor.getMangledTypeName ());
328
- OS << TypeName << ' \n ' ;
329
- for (size_t i = 0 ; i < TypeName.size (); ++i)
330
- OS << ' -' ;
331
- OS << ' \n ' ;
332
- for (auto &field : descriptor) {
333
- OS << field.getFieldName ();
334
- if (field.hasMangledTypeName ()) {
335
- OS << " : " ;
336
- dumpTypeRef (field.getMangledTypeName (), OS);
337
- } else {
338
- OS << " \n\n " ;
339
- }
340
- }
341
- }
342
- }
343
- }
344
-
345
- void dumpAssociatedTypeSection (std::ostream &OS) {
346
- for (const auto §ions : ReflectionInfos) {
347
- for (const auto &descriptor : sections.assocty ) {
348
- auto conformingTypeName = Demangle::demangleTypeAsString (
349
- descriptor.getMangledConformingTypeName ());
350
- auto protocolName = Demangle::demangleTypeAsString (
351
- descriptor.getMangledProtocolTypeName ());
352
-
353
- OS << " - " << conformingTypeName << " : " << protocolName;
354
- OS << ' \n ' ;
355
-
356
- for (const auto &associatedType : descriptor) {
357
- OS << " typealias " << associatedType.getName () << " = " ;
358
- dumpTypeRef (associatedType.getMangledSubstitutedTypeName (), OS);
359
- }
360
- }
361
- }
362
- }
363
-
364
- void dumpBuiltinTypeSection (std::ostream &OS) {
365
- for (const auto §ions : ReflectionInfos) {
366
- for (const auto &descriptor : sections.builtin ) {
367
- auto typeName = Demangle::demangleTypeAsString (
368
- descriptor.getMangledTypeName ());
369
-
370
- OS << " \n - " << typeName << " :\n " ;
371
- OS << " Size: " << descriptor.Size << " \n " ;
372
- OS << " Alignment: " << descriptor.Alignment << " \n " ;
373
- OS << " Stride: " << descriptor.Stride << " \n " ;
374
- OS << " NumExtraInhabitants: " << descriptor.NumExtraInhabitants << " \n " ;
375
- }
376
- }
377
- }
378
-
379
- void dumpAllSections (std::ostream &OS) {
380
- OS << " FIELDS:\n " ;
381
- OS << " =======\n " ;
382
- dumpFieldSection (OS);
383
- OS << ' \n ' ;
384
- OS << " ASSOCIATED TYPES:\n " ;
385
- OS << " =================\n " ;
386
- dumpAssociatedTypeSection (OS);
387
- OS << ' \n ' ;
388
- OS << " BUILTIN TYPES:\n " ;
389
- OS << " ==============\n " ;
390
- dumpBuiltinTypeSection (OS);
391
- OS << ' \n ' ;
392
- }
233
+ std::ostream &OS, bool printTypeName = false );
234
+ void dumpFieldSection (std::ostream &OS);
235
+ void dumpAssociatedTypeSection (std::ostream &OS);
236
+ void dumpBuiltinTypeSection (std::ostream &OS);
237
+ void dumpAllSections (std::ostream &OS);
393
238
};
394
239
395
240
0 commit comments