@@ -360,6 +360,8 @@ class TypeRefBuilder {
360
360
using BuiltRequirement = TypeRefRequirement;
361
361
using BuiltLayoutConstraint = TypeRefLayoutConstraint;
362
362
using BuiltGenericTypeParam = const GenericTypeParameterTypeRef *;
363
+ using BuiltGenericSignature = const GenericSignatureRef *;
364
+ using BuiltSubstitutionMap = llvm::DenseMap<DepthAndIndex, const TypeRef *>;
363
365
364
366
TypeRefBuilder (const TypeRefBuilder &other) = delete ;
365
367
TypeRefBuilder &operator =(const TypeRefBuilder &other) = delete ;
@@ -378,6 +380,8 @@ class TypeRefBuilder {
378
380
// / Cache for field info lookups.
379
381
std::unordered_map<std::string, RemoteRef<FieldDescriptor>> FieldTypeInfoCache;
380
382
383
+ std::vector<std::unique_ptr<const GenericSignatureRef>> SignatureRefPool;
384
+
381
385
TypeConverter TC;
382
386
MetadataSourceBuilder MSB;
383
387
@@ -394,6 +398,13 @@ class TypeRefBuilder {
394
398
return TR;
395
399
}
396
400
401
+ template <typename ... Args>
402
+ const GenericSignatureRef *makeGenericSignatureRef (Args... args) {
403
+ const auto TR = new GenericSignatureRef (::std::forward<Args>(args)...);
404
+ SignatureRefPool.push_back (std::unique_ptr<const GenericSignatureRef>(TR));
405
+ return TR;
406
+ }
407
+
397
408
Demangle::NodeFactory &getNodeFactory () { return Dem; }
398
409
399
410
void clearNodeFactory () { Dem.clear (); }
@@ -599,6 +610,14 @@ class TypeRefBuilder {
599
610
*this , {}, result, funcFlags, diffKind, nullptr );
600
611
}
601
612
613
+ BuiltType createProtocolTypeFromDecl (BuiltProtocolDecl protocol) {
614
+ if (protocol->second ) {
615
+ return llvm::cast<TypeRef>(createObjCProtocolType (protocol->first ));
616
+ } else {
617
+ return llvm::cast<TypeRef>(createNominalType (protocol->first ));
618
+ }
619
+ }
620
+
602
621
const ProtocolCompositionTypeRef *
603
622
createProtocolCompositionType (llvm::ArrayRef<BuiltProtocolDecl> protocols,
604
623
BuiltType superclass, bool isClassBound,
@@ -608,10 +627,10 @@ class TypeRefBuilder {
608
627
if (!protocol)
609
628
continue ;
610
629
611
- if ( protocol-> second )
612
- protocolRefs. push_back ( createObjCProtocolType (protocol-> first ));
613
- else
614
- protocolRefs.push_back (createNominalType (protocol-> first ) );
630
+ auto protocolType = createProtocolTypeFromDecl (* protocol);
631
+ if (!protocolType)
632
+ continue ;
633
+ protocolRefs.push_back (protocolType );
615
634
}
616
635
617
636
return ProtocolCompositionTypeRef::create (*this , protocolRefs, superclass,
@@ -720,8 +739,7 @@ class TypeRefBuilder {
720
739
return createObjCClassType (name);
721
740
}
722
741
723
- const ObjCProtocolTypeRef *
724
- createObjCProtocolType (const std::string &name) {
742
+ const ObjCProtocolTypeRef *createObjCProtocolType (const std::string &name) {
725
743
return ObjCProtocolTypeRef::create (*this , name);
726
744
}
727
745
@@ -739,6 +757,41 @@ class TypeRefBuilder {
739
757
return OpaqueTypeRef::get ();
740
758
}
741
759
760
+ BuiltGenericSignature
761
+ createGenericSignature (llvm::ArrayRef<BuiltType> builtParams,
762
+ llvm::ArrayRef<BuiltRequirement> requirements) {
763
+ std::vector<BuiltGenericTypeParam> params;
764
+ for (auto &builtParam : builtParams) {
765
+ auto *genericRef =
766
+ llvm::dyn_cast<GenericTypeParameterTypeRef>(builtParam);
767
+ if (!genericRef)
768
+ return nullptr ;
769
+ params.push_back (genericRef);
770
+ }
771
+ return GenericSignatureRef::create (*this , params, requirements);
772
+ }
773
+
774
+ BuiltSubstitutionMap
775
+ createSubstitutionMap (BuiltGenericSignature sig,
776
+ llvm::ArrayRef<BuiltType> replacements) {
777
+ assert (sig->getParams ().size () == replacements.size () &&
778
+ " Not enough replacement parameters!" );
779
+ if (sig->getParams ().size () != replacements.size ())
780
+ return BuiltSubstitutionMap{};
781
+
782
+ BuiltSubstitutionMap map{};
783
+ for (unsigned paramIdx : indices (sig->getParams ())) {
784
+ const auto *param = sig->getParams ()[paramIdx];
785
+ auto replacement = replacements[paramIdx];
786
+ map[{param->getDepth (), param->getIndex ()}] = replacement;
787
+ }
788
+ return map;
789
+ }
790
+
791
+ BuiltType subst (BuiltType subject, const BuiltSubstitutionMap &Subs) {
792
+ return subject->subst (*this , Subs);
793
+ }
794
+
742
795
// /
743
796
// / Parsing reflection metadata
744
797
// /
0 commit comments