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