@@ -341,6 +341,63 @@ class BuiltinTypeDescriptorIterator
341
341
}
342
342
};
343
343
344
+ // / A key-value pair in a TypeRef -> MetadataSource map.
345
+ struct GenericMetadataSource {
346
+ using Key = RelativeDirectPointer<const char >;
347
+ using Value = Key;
348
+
349
+ const Key MangledTypeName;
350
+ const Value EncodedMetadataSource;
351
+ };
352
+
353
+ // / Describes the layout of a heap closure.
354
+ // /
355
+ // / For simplicity's sake and other reasons, this shouldn't contain
356
+ // / architecture-specifically sized things like direct pointers, uintptr_t, etc.
357
+ struct CaptureDescriptor {
358
+ public:
359
+
360
+ // / The number of captures in the closure and the number of typerefs that
361
+ // / immediately follow this struct.
362
+ const uint32_t NumCaptures;
363
+
364
+ // / The number of sources of metadata available in the MetadataSourceMap
365
+ // / directly following the list of capture's typerefs.
366
+ const uint32_t NumMetadataSources;
367
+
368
+ // / The number of items in the NecessaryBindings structure at the head of
369
+ // / the closure.
370
+ const uint32_t NumBindings;
371
+
372
+ // / Get the key-value pair for the ith generic metadata source.
373
+ const GenericMetadataSource &getGenericMetadataSource (size_t i) const {
374
+ assert (i <= NumMetadataSources &&
375
+ " Generic metadata source index out of range" );
376
+ auto Begin = getGenericMetadataSourceBuffer ();
377
+ return Begin[i];
378
+ }
379
+
380
+ // / Get the typeref (encoded as a mangled type name) of the ith
381
+ // / closure capture.
382
+ const RelativeDirectPointer<const char > &
383
+ getCaptureMangledTypeName (size_t i) const {
384
+ assert (i <= NumCaptures && " Capture index out of range" );
385
+ auto Begin = getCaptureTypeRefBuffer ();
386
+ return Begin[i];
387
+ }
388
+
389
+ private:
390
+ const GenericMetadataSource *getGenericMetadataSourceBuffer () const {
391
+ auto BeginTR = reinterpret_cast <const char *>(getCaptureTypeRefBuffer ());
392
+ auto EndTR = BeginTR + NumCaptures * sizeof (GenericMetadataSource);
393
+ return reinterpret_cast <const GenericMetadataSource *>(EndTR );
394
+ }
395
+
396
+ const RelativeDirectPointer<const char > *getCaptureTypeRefBuffer () const {
397
+ return reinterpret_cast <const RelativeDirectPointer<const char > *>(this +1 );
398
+ }
399
+ };
400
+
344
401
} // end namespace reflection
345
402
} // end namespace swift
346
403
0 commit comments