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 2424
2525#include < vector>
2626#include < unordered_map>
27+ #include < utility>
2728
2829namespace swift {
2930namespace remote {
@@ -419,6 +420,24 @@ class MetadataReader {
419420 return swift::remote::decodeMangledType (Builder, Node);
420421 }
421422
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+
422441 // / Given a remote pointer to metadata, attempt to turn it into a type.
423442 BuiltType readTypeFromMetadata (StoredPointer MetadataAddress) {
424443 auto Cached = TypeCache.find (MetadataAddress);
Original file line number Diff line number Diff line change 2222#include " swift/Remote/Failure.h"
2323#include " swift/Remote/MemoryReader.h"
2424#include " swift/Basic/LLVM.h"
25+ #include " swift/ABI/MetadataValues.h"
2526#include " llvm/ADT/Optional.h"
2627#include " llvm/ADT/StringRef.h"
2728
@@ -169,6 +170,11 @@ class RemoteASTContext {
169170 // / resolve it to a specific type in the local AST.
170171 Result<Type> getTypeForRemoteTypeMetadata (remote::RemoteAddress address);
171172
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+
172178 // / Given an address which is supposedly of a nominal type descriptor,
173179 // / try to resolve it to a specific nominal type declaration in the
174180 // / local AST.
Original file line number Diff line number Diff line change @@ -537,6 +537,17 @@ class RemoteASTContextImpl {
537537 return Result<Type>::emplaceFailure (Failure::Unknown);
538538 }
539539
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+
540551 Result<NominalTypeDecl *>
541552 getDeclForRemoteNominalTypeDescriptor (RemoteAddress address) {
542553 NominalTypeDecl *result;
You can’t perform that action at this time.
0 commit comments