@@ -669,18 +669,16 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
669
669
return {};
670
670
671
671
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
672
- auto &builder = reflection_ctx->GetBuilder ();
673
- auto tc = swift::reflection::TypeConverter (builder);
674
672
LLDBTypeInfoProvider tip (*this , *ts);
675
- auto *cti = tc. getClassInstanceTypeInfo (tr, 0 , &tip);
673
+ auto *cti = reflection_ctx-> GetClassInstanceTypeInfo (tr, &tip);
676
674
if (auto *rti =
677
675
llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(cti)) {
678
676
LLDB_LOGF (GetLog (LLDBLog::Types),
679
677
" %s: class RecordTypeInfo(num_fields=%i)" ,
680
678
type.GetMangledTypeName ().GetCString (), rti->getNumFields ());
681
679
682
680
// The superclass, if any, is an extra child.
683
- if (builder. lookupSuperclass (tr))
681
+ if (reflection_ctx-> LookupSuperclass (tr))
684
682
return rti->getNumFields () + 1 ;
685
683
return rti->getNumFields ();
686
684
}
@@ -743,9 +741,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
743
741
return referent.GetNumFields (exe_ctx);
744
742
return 0 ;
745
743
case ReferenceKind::Strong:
746
- TypeConverter tc ( GetReflectionContext ()-> GetBuilder () );
744
+ ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
747
745
LLDBTypeInfoProvider tip (*this , *ts);
748
- auto *cti = tc. getClassInstanceTypeInfo (tr, 0 , &tip);
746
+ auto *cti = reflection_ctx-> GetClassInstanceTypeInfo (tr, &tip);
749
747
if (auto *rti = llvm::dyn_cast_or_null<RecordTypeInfo>(cti)) {
750
748
return rti->getNumFields ();
751
749
}
@@ -876,18 +874,16 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
876
874
child_indexes);
877
875
case ReferenceKind::Strong: {
878
876
ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
879
- auto &builder = reflection_ctx->GetBuilder ();
880
- TypeConverter tc (builder);
881
877
LLDBTypeInfoProvider tip (*this , *ts);
882
878
// `current_tr` iterates the class hierarchy, from the current class, each
883
879
// superclass, and ends on null.
884
880
auto *current_tr = tr;
885
881
while (current_tr) {
886
882
auto *record_ti = llvm::dyn_cast_or_null<RecordTypeInfo>(
887
- tc. getClassInstanceTypeInfo (current_tr, 0 , &tip));
883
+ reflection_ctx-> GetClassInstanceTypeInfo (current_tr, &tip));
888
884
if (!record_ti)
889
885
break ;
890
- auto *super_tr = builder. lookupSuperclass (current_tr);
886
+ auto *super_tr = reflection_ctx-> LookupSuperclass (current_tr);
891
887
uint32_t offset = super_tr ? 1 : 0 ;
892
888
auto found_size = findFieldWithName (record_ti->getFields (), name, false ,
893
889
child_indexes, offset);
@@ -1393,18 +1389,13 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack(
1393
1389
});
1394
1390
1395
1391
// Build a TypeRef from the demangle tree.
1396
- auto typeref_or_err =
1397
- decodeMangledType (reflection_ctx->GetBuilder (), pack_element);
1398
- if (typeref_or_err.isError ()) {
1399
- LLDB_LOGF (log, " Couldn't get TypeRef for %s" ,
1400
- pack_type.GetMangledTypeName ().GetCString ());
1392
+ auto type_ref = reflection_ctx->GetTypeRefOrNull (dem, pack_element);
1393
+ if (!type_ref)
1401
1394
return {};
1402
- }
1403
- auto typeref = typeref_or_err.getType ();
1404
1395
1405
1396
// Apply the substitutions.
1406
1397
auto bound_typeref =
1407
- typeref-> subst ( reflection_ctx->GetBuilder () , substitutions);
1398
+ reflection_ctx->ApplySubstitutions (type_ref , substitutions);
1408
1399
swift::Demangle::NodePointer node = bound_typeref->getDemangling (dem);
1409
1400
CompilerType type = ts->RemangleAsType (dem, node);
1410
1401
@@ -1818,11 +1809,10 @@ CompilerType SwiftLanguageRuntimeImpl::BindGenericTypeParameters(
1818
1809
Demangler dem;
1819
1810
NodePointer unbound_node =
1820
1811
dem.demangleSymbol (unbound_type.GetMangledTypeName ().GetStringRef ());
1821
- auto type_ref_or_err =
1822
- decodeMangledType (reflection_ctx->GetBuilder (), unbound_node);
1823
- if (type_ref_or_err.isError ()) {
1812
+ auto type_ref = reflection_ctx->GetTypeRefOrNull (dem, unbound_node);
1813
+ if (!type_ref) {
1824
1814
LLDB_LOG (GetLog (LLDBLog::Expressions | LLDBLog::Types),
1825
- " Couldn't get TypeRef of unbound type. " );
1815
+ " Couldn't get TypeRef of unbound type" );
1826
1816
return {};
1827
1817
}
1828
1818
@@ -1842,28 +1832,24 @@ CompilerType SwiftLanguageRuntimeImpl::BindGenericTypeParameters(
1842
1832
return ;
1843
1833
}
1844
1834
1845
- NodePointer child_node =
1846
- dem.demangleSymbol (type.GetMangledTypeName ().GetStringRef ());
1847
- auto type_ref_or_err =
1848
- decodeMangledType (reflection_ctx->GetBuilder (), child_node);
1849
- if (type_ref_or_err.isError ()) {
1835
+ auto type_ref = reflection_ctx->GetTypeRefOrNull (
1836
+ type.GetMangledTypeName ().GetStringRef ());
1837
+ if (!type_ref) {
1850
1838
LLDB_LOG (GetLog (LLDBLog::Expressions | LLDBLog::Types),
1851
1839
" Couldn't get TypeRef when binding generic type parameters." );
1852
1840
failure = true ;
1853
1841
return ;
1854
1842
}
1855
1843
1856
- substitutions.insert ({{depth, index}, type_ref_or_err. getType () });
1844
+ substitutions.insert ({{depth, index}, type_ref });
1857
1845
});
1858
1846
1859
1847
if (failure)
1860
1848
return {};
1861
1849
1862
- const swift::reflection::TypeRef *type_ref = type_ref_or_err.getType ();
1863
-
1864
1850
// Apply the substitutions.
1865
1851
const swift::reflection::TypeRef *bound_type_ref =
1866
- type_ref-> subst ( reflection_ctx->GetBuilder () , substitutions);
1852
+ reflection_ctx->ApplySubstitutions (type_ref , substitutions);
1867
1853
NodePointer node = bound_type_ref->getDemangling (dem);
1868
1854
return ts->GetTypeSystemSwiftTypeRef ().RemangleAsType (dem, node);
1869
1855
}
@@ -1918,18 +1904,14 @@ SwiftLanguageRuntimeImpl::BindGenericTypeParameters(StackFrame &stack_frame,
1918
1904
return get_canonical ();
1919
1905
1920
1906
// Build a TypeRef from the demangle tree.
1921
- auto type_ref_or_err =
1922
- decodeMangledType (reflection_ctx->GetBuilder (), canonical);
1923
- if (type_ref_or_err.isError ()) {
1924
- LLDB_LOG (GetLog (LLDBLog::Expressions | LLDBLog::Types),
1925
- " Couldn't get TypeRef" );
1907
+ const swift::reflection::TypeRef *type_ref =
1908
+ reflection_ctx->GetTypeRefOrNull (dem, canonical);
1909
+ if (!type_ref)
1926
1910
return get_canonical ();
1927
- }
1928
- const swift::reflection::TypeRef *type_ref = type_ref_or_err.getType ();
1929
1911
1930
1912
// Apply the substitutions.
1931
1913
const swift::reflection::TypeRef *bound_type_ref =
1932
- type_ref-> subst ( reflection_ctx->GetBuilder () , substitutions);
1914
+ reflection_ctx->ApplySubstitutions (type_ref , substitutions);
1933
1915
NodePointer node = bound_type_ref->getDemangling (dem);
1934
1916
1935
1917
// Import the type into the scratch context. Subsequent conversions
@@ -2647,32 +2629,16 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
2647
2629
if (!reflection_ctx)
2648
2630
return nullptr ;
2649
2631
2650
- auto type_ref_or_err =
2651
- swift::Demangle::decodeMangledType (reflection_ctx->GetBuilder (), node);
2652
- if (type_ref_or_err.isError ()) {
2653
- LLDB_LOGF (log,
2654
- " [SwiftLanguageRuntimeImpl::GetTypeRef] Could not find typeref "
2655
- " for type: %s. Decode mangled type failed. Error: %s\n ." ,
2656
- type.GetMangledTypeName ().GetCString (),
2657
- type_ref_or_err.getError ()->copyErrorString ());
2632
+ auto type_ref = reflection_ctx->GetTypeRefOrNull (dem, node);
2633
+ if (!type_ref)
2658
2634
return nullptr ;
2659
- }
2660
- const swift::reflection::TypeRef *type_ref = type_ref_or_err.getType ();
2661
- if (type_ref) {
2662
- if (log && log->GetVerbose ()) {
2663
- std::stringstream ss;
2664
- type_ref->dump (ss);
2665
- LLDB_LOGF (log,
2666
- " [SwiftLanguageRuntimeImpl::GetTypeRef] Found typeref for "
2667
- " type: %s:\n %s" ,
2668
- type.GetMangledTypeName ().GetCString (), ss.str ().c_str ());
2669
- }
2670
- } else {
2671
- LLDB_LOGF (
2672
- log,
2673
- " [SwiftLanguageRuntimeImpl::GetTypeRef] could not find typeref for "
2674
- " type: %s:\n " ,
2675
- type.GetMangledTypeName ().GetCString ());
2635
+ if (log && log->GetVerbose ()) {
2636
+ std::stringstream ss;
2637
+ type_ref->dump (ss);
2638
+ LLDB_LOGF (log,
2639
+ " [SwiftLanguageRuntimeImpl::GetTypeRef] Found typeref for "
2640
+ " type: %s:\n %s" ,
2641
+ type.GetMangledTypeName ().GetCString (), ss.str ().c_str ());
2676
2642
}
2677
2643
return type_ref;
2678
2644
}
0 commit comments