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