File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 24
24
25
25
#include < vector>
26
26
#include < unordered_map>
27
+ #include < utility>
27
28
28
29
namespace swift {
29
30
namespace remote {
@@ -419,6 +420,24 @@ class MetadataReader {
419
420
return swift::remote::decodeMangledType (Builder, Node);
420
421
}
421
422
423
+ // / Given a remote pointer to metadata, attempt to discover its MetadataKind.
424
+ std::pair<bool ,MetadataKind>
425
+ readKindFromMetadata (StoredPointer MetadataAddress) {
426
+ auto Cached = MetadataCache.find (MetadataAddress);
427
+ if (Cached != MetadataCache.end ()) {
428
+ if (auto Meta = Cached->second ) {
429
+ return {true ,Cached->second ->getKind ()};
430
+ } else {
431
+ return {false ,MetadataKind::Opaque};
432
+ }
433
+ }
434
+
435
+ auto Meta = readMetadata (MetadataAddress);
436
+ if (!Meta) return {false ,MetadataKind::Opaque};
437
+
438
+ return {true ,Meta->getKind ()};
439
+ }
440
+
422
441
// / Given a remote pointer to metadata, attempt to turn it into a type.
423
442
BuiltType readTypeFromMetadata (StoredPointer MetadataAddress) {
424
443
auto Cached = TypeCache.find (MetadataAddress);
Original file line number Diff line number Diff line change 22
22
#include " swift/Remote/Failure.h"
23
23
#include " swift/Remote/MemoryReader.h"
24
24
#include " swift/Basic/LLVM.h"
25
+ #include " swift/ABI/MetadataValues.h"
25
26
#include " llvm/ADT/Optional.h"
26
27
#include " llvm/ADT/StringRef.h"
27
28
@@ -169,6 +170,11 @@ class RemoteASTContext {
169
170
// / resolve it to a specific type in the local AST.
170
171
Result<Type> getTypeForRemoteTypeMetadata (remote::RemoteAddress address);
171
172
173
+ // / Given an address which is supposedly of type metadata, try to
174
+ // / resolve it to a specific MetadataKind value for its backing type.
175
+ Result<MetadataKind>
176
+ getKindForRemoteTypeMetadata (remote::RemoteAddress address);
177
+
172
178
// / Given an address which is supposedly of a nominal type descriptor,
173
179
// / try to resolve it to a specific nominal type declaration in the
174
180
// / local AST.
Original file line number Diff line number Diff line change @@ -537,6 +537,17 @@ class RemoteASTContextImpl {
537
537
return Result<Type>::emplaceFailure (Failure::Unknown);
538
538
}
539
539
540
+ Result<MetadataKind> getKindForRemoteTypeMetadata (RemoteAddress address) {
541
+ std::pair<bool ,MetadataKind> result;
542
+ if (Is32) {
543
+ result = Reader32->readKindFromMetadata (address.getAddressData ());
544
+ } else {
545
+ result = Reader64->readKindFromMetadata (address.getAddressData ());
546
+ }
547
+ if (result.first ) return Result<MetadataKind>(result.second );
548
+ return Result<MetadataKind>::emplaceFailure (Failure::Unknown);
549
+ }
550
+
540
551
Result<NominalTypeDecl *>
541
552
getDeclForRemoteNominalTypeDescriptor (RemoteAddress address) {
542
553
NominalTypeDecl *result;
You can’t perform that action at this time.
0 commit comments