@@ -709,8 +709,17 @@ CompilerType GetTypedefedTypeRecursive(CompilerType type) {
709709} // namespace
710710
711711llvm::Expected<uint32_t >
712- SwiftLanguageRuntime::GetNumChildren (CompilerType type,
713- ExecutionContextScope *exe_scope) {
712+ SwiftLanguageRuntime::GetNumFields (CompilerType type,
713+ ExecutionContext *exe_ctx) {
714+ if (exe_ctx)
715+ return GetNumChildren (type, exe_ctx->GetBestExecutionContextScope (), false ,
716+ false );
717+ return llvm::createStringError (" no execution context" );
718+ }
719+
720+ llvm::Expected<uint32_t > SwiftLanguageRuntime::GetNumChildren (
721+ CompilerType type, ExecutionContextScope *exe_scope,
722+ bool include_superclass, bool include_clang_types) {
714723 LLDB_SCOPED_TIMER ();
715724
716725 auto ts_sp = type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>();
@@ -726,7 +735,7 @@ SwiftLanguageRuntime::GetNumChildren(CompilerType type,
726735 return pack_type->count ;
727736
728737 // Deal with Clang types.
729- {
738+ if (include_clang_types) {
730739 CompilerType clang_type =
731740 LookupAnonymousClangType (type.GetMangledTypeName ().AsCString ());
732741 if (!clang_type)
@@ -806,7 +815,7 @@ SwiftLanguageRuntime::GetNumChildren(CompilerType type,
806815 if (GetWeakReferent (ts, type))
807816 return 1 ;
808817 break ;
809- default :
818+ case swift::reflection::ReferenceKind::Strong :
810819 break ;
811820 }
812821
@@ -838,7 +847,8 @@ SwiftLanguageRuntime::GetNumChildren(CompilerType type,
838847 type.GetMangledTypeName (), rti->getNumFields ());
839848
840849 // The superclass, if any, is an extra child.
841- if (reflection_ctx->LookupSuperclass (*tr, ts.GetDescriptorFinder ()))
850+ if (include_superclass &&
851+ reflection_ctx->LookupSuperclass (*tr, ts.GetDescriptorFinder ()))
842852 return rti->getNumFields () + 1 ;
843853 return rti->getNumFields ();
844854 }
@@ -867,91 +877,6 @@ SwiftLanguageRuntime::GetNumChildren(CompilerType type,
867877 type.GetMangledTypeName ().GetString ());
868878}
869879
870- std::optional<unsigned >
871- SwiftLanguageRuntime::GetNumFields (CompilerType type,
872- ExecutionContext *exe_ctx) {
873- auto ts_sp = type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>();
874- if (!ts_sp)
875- return {};
876- auto &ts = *ts_sp;
877-
878- using namespace swift ::reflection;
879- // Try the static type metadata.
880- const TypeRef *tr = nullptr ;
881- auto ti_or_err = GetSwiftRuntimeTypeInfo (
882- type, exe_ctx ? exe_ctx->GetBestExecutionContextScope () : nullptr , &tr);
883- if (!ti_or_err) {
884- LLDB_LOG_ERRORV (GetLog (LLDBLog::Types), ti_or_err.takeError (), " {0}" );
885- return {};
886- }
887- auto *ti = &*ti_or_err;
888-
889- // Structs and Tuples.
890- switch (ti->getKind ()) {
891- case TypeInfoKind::Record: {
892- // Structs and Tuples.
893- auto *rti = llvm::cast<RecordTypeInfo>(ti);
894- switch (rti->getRecordKind ()) {
895- case RecordKind::ExistentialMetatype:
896- case RecordKind::ThickFunction:
897- // There are two fields, `function` and `context`, but they're not exposed
898- // by lldb.
899- return 0 ;
900- case RecordKind::OpaqueExistential:
901- // `OpaqueExistential` is documented as:
902- // An existential is a three-word buffer followed by value metadata...
903- // The buffer is exposed as fields named `payload_data_{0,1,2}`, and
904- // the number of fields are increased to match.
905- return rti->getNumFields () + 3 ;
906- default :
907- return rti->getNumFields ();
908- }
909- }
910- case TypeInfoKind::Builtin: {
911- // Clang types without debug info may present themselves like this.
912- return {};
913- }
914- case TypeInfoKind::Enum: {
915- auto *eti = llvm::cast<EnumTypeInfo>(ti);
916- return eti->getNumPayloadCases ();
917- }
918- case TypeInfoKind::Reference: {
919- // Objects.
920- auto *rti = llvm::cast<ReferenceTypeInfo>(ti);
921- switch (rti->getReferenceKind ()) {
922- case ReferenceKind::Weak:
923- case ReferenceKind::Unowned:
924- case ReferenceKind::Unmanaged:
925- if (auto referent = GetWeakReferent (ts, type))
926- return referent.GetNumFields (exe_ctx);
927- return 0 ;
928- case ReferenceKind::Strong:
929- ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
930- if (!reflection_ctx)
931- return {};
932- if (!tr)
933- return {};
934-
935- LLDBTypeInfoProvider tip (*this , ts);
936- auto cti_or_err = reflection_ctx->GetClassInstanceTypeInfo (
937- *tr, &tip, ts.GetDescriptorFinder ());
938- if (!cti_or_err) {
939- LLDB_LOG_ERRORV (GetLog (LLDBLog::Types), cti_or_err.takeError (),
940- " GetNumFields failed: {0}" );
941- return {};
942- }
943- if (auto *rti = llvm::dyn_cast_or_null<RecordTypeInfo>(&*cti_or_err))
944- return rti->getNumFields ();
945-
946- return {};
947- }
948- }
949- default :
950- LogUnimplementedTypeKind (__FUNCTION__, type);
951- return {};
952- }
953- }
954-
955880static std::pair<SwiftLanguageRuntime::LookupResult, std::optional<size_t >>
956881findFieldWithName (const std::vector<swift::reflection::FieldInfo> &fields,
957882 const swift::reflection::TypeRef *tr, llvm::StringRef name,
0 commit comments