@@ -738,9 +738,8 @@ SwiftLanguage::GetHardcodedSummaries() {
738
738
return g_formatters;
739
739
}
740
740
741
- static CompilerType
742
- ExtractSwiftTypeFromCxxInteropType (CompilerType type, TypeSystemSwift &ts,
743
- SwiftLanguageRuntime &runtime) {
741
+ static llvm::StringRef
742
+ ExtractSwiftTypeNameFromCxxInteropType (CompilerType type) {
744
743
// Try to recognize a Swift type wrapped in a C++ interop wrapper class.
745
744
// These types have a typedef from a char to the swift mangled name, and a
746
745
// static constexpr char field whose type is the typedef, and whose name
@@ -770,8 +769,6 @@ ExtractSwiftTypeFromCxxInteropType(CompilerType type, TypeSystemSwift &ts,
770
769
}
771
770
772
771
const clang::RecordDecl *record_decl = record_type->getDecl ();
773
- CompilerType swift_type;
774
-
775
772
for (auto *child_decl : record_decl->decls ()) {
776
773
auto *var_decl = llvm::dyn_cast<clang::VarDecl>(child_decl);
777
774
if (!var_decl)
@@ -790,39 +787,46 @@ ExtractSwiftTypeFromCxxInteropType(CompilerType type, TypeSystemSwift &ts,
790
787
if (!decl)
791
788
break ;
792
789
793
- auto swift_name = decl->getName ();
794
- if (!swift::Demangle::isMangledName (swift_name))
795
- break ;
796
-
797
- swift_type = ts.GetTypeFromMangledTypename (ConstString (swift_name));
798
- break ;
799
- }
800
-
801
- if (swift_type) {
802
- auto bound_type = runtime.BindGenericTypeParameters (
803
- swift_type, [&](unsigned depth, unsigned index ) -> CompilerType {
804
- assert (depth == 0 && " Unexpected depth! C++ interop does not support "
805
- " nested generic parameters" );
806
- if (depth > 0 )
807
- return {};
808
-
809
- auto templated_type = type.GetTypeTemplateArgument (index );
810
- auto substituted_type =
811
- ExtractSwiftTypeFromCxxInteropType (templated_type, ts, runtime);
812
-
813
- // The generic type might also not be a user defined type which
814
- // ExtractSwiftTypeFromCxxInteropType can find, but which is still
815
- // convertible to Swift (for example, int -> Int32). Attempt to
816
- // convert it to a Swift type.
817
- if (!substituted_type)
818
- substituted_type = ts.ConvertClangTypeToSwiftType (templated_type);
819
- return substituted_type;
820
- });
821
- return bound_type;
790
+ return decl->getName ();
822
791
}
823
792
return {};
824
793
}
825
794
795
+ static CompilerType ExtractSwiftTypeFromCxxInteropTypeName (
796
+ CompilerType type, llvm::StringRef swift_name, TypeSystemSwift &ts,
797
+ SwiftLanguageRuntime &swift_runtime) {
798
+ if (!swift::Demangle::isMangledName (swift_name))
799
+ return {};
800
+
801
+ CompilerType swift_type =
802
+ ts.GetTypeFromMangledTypename (ConstString (swift_name));
803
+ if (!swift_type)
804
+ return {};
805
+
806
+ auto bound_type = swift_runtime.BindGenericTypeParameters (
807
+ swift_type, [&](unsigned depth, unsigned index ) -> CompilerType {
808
+ assert (depth == 0 && " Unexpected depth! C++ interop does not support "
809
+ " nested generic parameters" );
810
+ if (depth > 0 )
811
+ return {};
812
+
813
+ CompilerType templated_type = type.GetTypeTemplateArgument (index );
814
+ CompilerType substituted_type = ExtractSwiftTypeFromCxxInteropTypeName (
815
+ templated_type,
816
+ ExtractSwiftTypeNameFromCxxInteropType (templated_type), ts,
817
+ swift_runtime);
818
+
819
+ // The generic type might also not be a user defined type which
820
+ // ExtractSwiftTypeFromCxxInteropType can find, but which is still
821
+ // convertible to Swift (for example, int -> Int32). Attempt to
822
+ // convert it to a Swift type.
823
+ if (!substituted_type)
824
+ substituted_type = ts.ConvertClangTypeToSwiftType (templated_type);
825
+ return substituted_type;
826
+ });
827
+ return bound_type;
828
+ }
829
+
826
830
// / Synthetic child that wraps a value object.
827
831
class ValueObjectWrapperSyntheticChildren : public SyntheticChildren {
828
832
class ValueObjectWrapperFrontEndProvider : public SyntheticChildrenFrontEnd {
@@ -1005,30 +1009,39 @@ SwiftLanguage::GetHardcodedSynthetics() {
1005
1009
FormatManager &format_manager)
1006
1010
-> lldb::SyntheticChildrenSP {
1007
1011
Log *log (GetLog (LLDBLog::DataFormatters));
1012
+ auto type = valobj.GetCompilerType ();
1008
1013
1014
+ // First, check whether this is a C++ wrapped Swift type.
1015
+ llvm::StringRef swift_type_name =
1016
+ ExtractSwiftTypeNameFromCxxInteropType (type);
1017
+ if (swift_type_name.empty ()) {
1018
+ LLDB_LOGV (log , " [Matching CxxBridgedSyntheticChildProvider] - "
1019
+ " Did not find Swift type." );
1020
+ return nullptr ;
1021
+ }
1022
+
1023
+ // Extract the Swift type.
1009
1024
ProcessSP process_sp (valobj.GetProcessSP ());
1010
1025
auto *swift_runtime = SwiftLanguageRuntime::Get (process_sp);
1011
- if (!swift_runtime) {
1026
+ if (!swift_runtime)
1012
1027
LLDB_LOGV (log , " [Matching CxxBridgedSyntheticChildProvider] - "
1013
1028
" Could not get the swift runtime." );
1014
- return nullptr ;
1015
- }
1016
1029
1017
- auto scratch_ctx = valobj.GetSwiftScratchContext ();
1018
- if (!scratch_ctx) {
1030
+ llvm::Optional<SwiftScratchContextReader> scratch_ctx_reader =
1031
+ valobj.GetSwiftScratchContext ();
1032
+ if (!scratch_ctx_reader || !scratch_ctx_reader->get ()) {
1019
1033
LLDB_LOGV (log , " [Matching CxxBridgedSyntheticChildProvider] - "
1020
- " Could not get the swift scratch context." );
1034
+ " Could not get the Swift scratch context." );
1021
1035
return nullptr ;
1022
1036
}
1023
- auto &type_system_swift = **scratch_ctx;
1024
-
1025
- auto type = valobj.GetCompilerType ();
1026
-
1027
- auto swift_type = ExtractSwiftTypeFromCxxInteropType (
1028
- type, type_system_swift, *swift_runtime);
1037
+ auto &ts = *scratch_ctx_reader->get ();
1038
+ CompilerType swift_type = ExtractSwiftTypeFromCxxInteropTypeName (
1039
+ type, swift_type_name, ts, *swift_runtime);
1029
1040
if (!swift_type) {
1030
- LLDB_LOGV (log , " [Matching CxxBridgedSyntheticChildProvider] - "
1031
- " Did not find Swift type." );
1041
+ LLDB_LOGV (log ,
1042
+ " [Matching CxxBridgedSyntheticChildProvider] - "
1043
+ " Did not find Swift type for type name \" {0}\" ." ,
1044
+ swift_type_name);
1032
1045
return nullptr ;
1033
1046
}
1034
1047
0 commit comments