@@ -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,37 @@ 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 tc = swift::reflection::TypeConverter (reflection_ctx->getBuilder ());
1088
+ LLDBTypeInfoProvider tip (*this , *ts);
1089
+ auto *cti = tc.getClassInstanceTypeInfo (tr, 0 , &tip);
1090
+ if (auto *rti =
1091
+ llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(cti)) {
1092
+ return rti->getNumFields ();
1093
+ }
1094
+
1095
+ return {};
1096
+ }
1033
1097
// FIXME: Implement more cases.
1034
1098
return {};
1035
1099
}
@@ -1064,38 +1128,6 @@ static llvm::StringRef GetBaseName(swift::Demangle::NodePointer node) {
1064
1128
}
1065
1129
}
1066
1130
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
1131
static CompilerType
1100
1132
GetTypeFromTypeRef (TypeSystemSwiftTypeRef &ts,
1101
1133
const swift::reflection::TypeRef *type_ref) {
@@ -2510,9 +2542,9 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
2510
2542
return type_ref;
2511
2543
}
2512
2544
2513
- const swift::reflection::TypeInfo *
2514
- SwiftLanguageRuntimeImpl::GetTypeInfo ( CompilerType type,
2515
- ExecutionContextScope *exe_scope ) {
2545
+ const swift::reflection::TypeInfo *SwiftLanguageRuntimeImpl::GetTypeInfo (
2546
+ CompilerType type, ExecutionContextScope *exe_scope ,
2547
+ swift::reflection::TypeRef const **out_tr ) {
2516
2548
auto *ts = llvm::dyn_cast_or_null<TypeSystemSwift>(type.GetTypeSystem ());
2517
2549
if (!ts)
2518
2550
return nullptr ;
@@ -2543,6 +2575,9 @@ SwiftLanguageRuntimeImpl::GetTypeInfo(CompilerType type,
2543
2575
if (!type_ref)
2544
2576
return nullptr ;
2545
2577
2578
+ if (out_tr)
2579
+ *out_tr = type_ref;
2580
+
2546
2581
auto *reflection_ctx = GetReflectionContext ();
2547
2582
if (!reflection_ctx)
2548
2583
return nullptr ;
0 commit comments