@@ -997,6 +997,38 @@ llvm::Optional<uint64_t> SwiftLanguageRuntimeImpl::GetMemberVariableOffset(
997
997
return offset;
998
998
}
999
999
1000
+ static CompilerType GetWeakReferent (TypeSystemSwiftTypeRef &ts,
1001
+ CompilerType type) {
1002
+ using namespace swift ::Demangle;
1003
+ Demangler dem;
1004
+ auto mangled = type.GetMangledTypeName ().GetStringRef ();
1005
+ NodePointer n = dem.demangleSymbol (mangled);
1006
+ if (!n || n->getKind () != Node::Kind::Global || !n->hasChildren ())
1007
+ return {};
1008
+ n = n->getFirstChild ();
1009
+ if (!n || n->getKind () != Node::Kind::TypeMangling || !n->hasChildren ())
1010
+ return {};
1011
+ n = n->getFirstChild ();
1012
+ if (!n || n->getKind () != Node::Kind::Type || !n->hasChildren ())
1013
+ return {};
1014
+ n = n->getFirstChild ();
1015
+ if (!n ||
1016
+ (n->getKind () != Node::Kind::Weak &&
1017
+ n->getKind () != Node::Kind::Unowned &&
1018
+ n->getKind () != Node::Kind::Unmanaged) ||
1019
+ !n->hasChildren ())
1020
+ return {};
1021
+ n = n->getFirstChild ();
1022
+ if (!n || n->getKind () != Node::Kind::Type || !n->hasChildren ())
1023
+ return {};
1024
+ // FIXME: We only need to canonicalize this node, not the entire type.
1025
+ n = ts.CanonicalizeSugar (dem, n->getFirstChild ());
1026
+ if (!n || n->getKind () != Node::Kind::SugaredOptional || !n->hasChildren ())
1027
+ return {};
1028
+ n = n->getFirstChild ();
1029
+ return ts.RemangleAsType (dem, n);
1030
+ }
1031
+
1000
1032
llvm::Optional<unsigned >
1001
1033
SwiftLanguageRuntimeImpl::GetNumChildren (CompilerType type,
1002
1034
ValueObject *valobj) {
@@ -1008,7 +1040,8 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
1008
1040
// Try the static type metadata.
1009
1041
auto frame =
1010
1042
valobj ? valobj->GetExecutionContextRef ().GetFrameSP ().get () : nullptr ;
1011
- auto *ti = GetTypeInfo (type, frame);
1043
+ const swift::reflection::TypeRef *tr = nullptr ;
1044
+ auto *ti = GetTypeInfo (type, frame, &tr);
1012
1045
// Structs and Tuples.
1013
1046
if (auto *rti =
1014
1047
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(ti)) {
@@ -1030,6 +1063,41 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
1030
1063
if (auto *eti = llvm::dyn_cast_or_null<swift::reflection::EnumTypeInfo>(ti)) {
1031
1064
return eti->getNumPayloadCases ();
1032
1065
}
1066
+ // Objects.
1067
+ if (auto *rti =
1068
+ llvm::dyn_cast_or_null<swift::reflection::ReferenceTypeInfo>(ti)) {
1069
+
1070
+ switch (rti->getReferenceKind ()) {
1071
+ case swift::reflection::ReferenceKind::Weak:
1072
+ case swift::reflection::ReferenceKind::Unowned:
1073
+ case swift::reflection::ReferenceKind::Unmanaged:
1074
+ // Weak references are implicitly Optionals, so report the one
1075
+ // child of Optional here.
1076
+ if (GetWeakReferent (*ts, type))
1077
+ return 1 ;
1078
+ break ;
1079
+ default :
1080
+ break ;
1081
+ }
1082
+
1083
+ if (!tr)
1084
+ return {};
1085
+
1086
+ auto *reflection_ctx = GetReflectionContext ();
1087
+ auto &builder = reflection_ctx->getBuilder ();
1088
+ auto tc = swift::reflection::TypeConverter (builder);
1089
+ LLDBTypeInfoProvider tip (*this , *ts);
1090
+ auto *cti = tc.getClassInstanceTypeInfo (tr, 0 , &tip);
1091
+ if (auto *rti =
1092
+ llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(cti)) {
1093
+ // The superclass, if any, is an extra child.
1094
+ if (builder.lookupSuperclass (tr))
1095
+ return rti->getNumFields () + 1 ;
1096
+ return rti->getNumFields ();
1097
+ }
1098
+
1099
+ return {};
1100
+ }
1033
1101
// FIXME: Implement more cases.
1034
1102
return {};
1035
1103
}
@@ -1064,38 +1132,6 @@ static llvm::StringRef GetBaseName(swift::Demangle::NodePointer node) {
1064
1132
}
1065
1133
}
1066
1134
1067
- static CompilerType GetWeakReferent (TypeSystemSwiftTypeRef &ts,
1068
- CompilerType type) {
1069
- using namespace swift ::Demangle;
1070
- Demangler dem;
1071
- auto mangled = type.GetMangledTypeName ().GetStringRef ();
1072
- NodePointer n = dem.demangleSymbol (mangled);
1073
- if (!n || n->getKind () != Node::Kind::Global || !n->hasChildren ())
1074
- return {};
1075
- n = n->getFirstChild ();
1076
- if (!n || n->getKind () != Node::Kind::TypeMangling || !n->hasChildren ())
1077
- return {};
1078
- n = n->getFirstChild ();
1079
- if (!n || n->getKind () != Node::Kind::Type || !n->hasChildren ())
1080
- return {};
1081
- n = n->getFirstChild ();
1082
- if (!n ||
1083
- (n->getKind () != Node::Kind::Weak &&
1084
- n->getKind () != Node::Kind::Unowned &&
1085
- n->getKind () != Node::Kind::Unmanaged) ||
1086
- !n->hasChildren ())
1087
- return {};
1088
- n = n->getFirstChild ();
1089
- if (!n || n->getKind () != Node::Kind::Type || !n->hasChildren ())
1090
- return {};
1091
- // FIXME: We only need to canonicalize this node, not the entire type.
1092
- n = ts.CanonicalizeSugar (dem, n->getFirstChild ());
1093
- if (!n || n->getKind () != Node::Kind::SugaredOptional || !n->hasChildren ())
1094
- return {};
1095
- n = n->getFirstChild ();
1096
- return ts.RemangleAsType (dem, n);
1097
- }
1098
-
1099
1135
static CompilerType
1100
1136
GetTypeFromTypeRef (TypeSystemSwiftTypeRef &ts,
1101
1137
const swift::reflection::TypeRef *type_ref) {
@@ -2510,9 +2546,9 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
2510
2546
return type_ref;
2511
2547
}
2512
2548
2513
- const swift::reflection::TypeInfo *
2514
- SwiftLanguageRuntimeImpl::GetTypeInfo ( CompilerType type,
2515
- ExecutionContextScope *exe_scope ) {
2549
+ const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo (
2550
+ CompilerType type, ExecutionContextScope *exe_scope ,
2551
+ swift::reflection::TypeRef const **out_tr ) {
2516
2552
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type.GetTypeSystem ());
2517
2553
if (!ts)
2518
2554
return nullptr ;
@@ -2543,6 +2579,9 @@ SwiftLanguageRuntimeImpl::GetTypeInfo(CompilerType type,
2543
2579
if (!type_ref)
2544
2580
return nullptr ;
2545
2581
2582
+ if (out_tr)
2583
+ *out_tr = type_ref;
2584
+
2546
2585
auto *reflection_ctx = GetReflectionContext ();
2547
2586
if (!reflection_ctx)
2548
2587
return nullptr ;
0 commit comments