Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 917e914

Browse files
author
Stephen Hawley
committed
Added associated type descriptors
1 parent df9ffdb commit 917e914

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

SwiftReflector/Demangling/Swift5NodeToTLDefinition.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ public TLDefinition Convert (Node node)
819819
return ConvertProtocolRequirementsBaseDescriptor (node);
820820
case NodeKind.BaseConformanceDescriptor:
821821
return ConvertBaseConformanceDescriptor (node);
822+
case NodeKind.AssociatedTypeDescriptor:
823+
return ConvertAssocatedTypeDescriptor (node);
822824
default:
823825
return null;
824826
}
@@ -1147,6 +1149,15 @@ TLBaseConformanceDescriptor ConvertBaseConformanceDescriptor (Node node)
11471149
return new TLBaseConformanceDescriptor (mangledName, protocol.ClassName.Module, protocol, requirement, offset);
11481150
}
11491151

1152+
TLAssociatedTypeDescriptor ConvertAssocatedTypeDescriptor (Node node)
1153+
{
1154+
var name = new SwiftName (node.Children [0].Text, false);
1155+
var protocol = ConvertToSwiftType (node.Children [0].Children [0], false, null) as SwiftClassType;
1156+
if (protocol == null)
1157+
return null;
1158+
return new TLAssociatedTypeDescriptor (mangledName, protocol.ClassName.Module, protocol, name, offset);
1159+
}
1160+
11501161

11511162
// ConvertToFunctions are usually called from rules.
11521163

SwiftReflector/Demangling/TLDefinition.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,15 @@ public TLBaseConformanceDescriptor (string mangledName, SwiftName module, SwiftC
232232
}
233233
public SwiftClassType ProtocolRequirement { get; private set; }
234234
}
235+
236+
public class TLAssociatedTypeDescriptor : TLClassElem {
237+
public TLAssociatedTypeDescriptor (string mangledName, SwiftName module, SwiftClassType protocol, SwiftName associatedTypeName, ulong offset)
238+
: base (CoreCompoundType.AssociatedTypeDescriptor, mangledName, module, protocol, offset)
239+
{
240+
AssociatedTypeName = associatedTypeName;
241+
}
242+
243+
public SwiftName AssociatedTypeName { get; private set; }
244+
}
235245
}
236246

SwiftReflector/Enums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum CoreCompoundType {
3131
MetadataDescriptor,
3232
ProtocolRequirementsBaseDescriptor,
3333
BaseConformanceDescriptor,
34+
AssociatedTypeDescriptor,
3435
}
3536

3637
public enum CoreBuiltInType {

tests/tom-swifty-test/SwiftReflector/Swift4DemanglerTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,5 +1646,38 @@ public void TestBaseConformanceDescriptor ()
16461646
Assert.IsNotNull (cl, "not a class");
16471647
Assert.AreEqual ("Swift.Equatable", cl.ClassName.ToFullyQualifiedName (), "wrong name");
16481648
}
1649+
1650+
[Test]
1651+
public void TestAssociatedTypeDescriptor0 ()
1652+
{
1653+
var tld = Decomposer.Decompose ("_$s12RowValueType6Eureka04RuleC0PTl", false);
1654+
Assert.IsNotNull (tld, "failed decomposition");
1655+
var atdesc = tld as TLAssociatedTypeDescriptor;
1656+
Assert.IsNotNull (atdesc, "not an associated type desc");
1657+
Assert.AreEqual ("RowValueType", atdesc.AssociatedTypeName.Name, "wrong associated type name");
1658+
Assert.AreEqual ("Eureka.RuleType", atdesc.Class.ClassName.ToFullyQualifiedName (), "protocol name mismatch");
1659+
}
1660+
1661+
[Test]
1662+
public void TestAssociatedTypeDescriptor1 ()
1663+
{
1664+
var tld = Decomposer.Decompose ("_$s23PresentedControllerType6Eureka012PresenterRowC0PTl", false);
1665+
Assert.IsNotNull (tld, "failed decomposition");
1666+
var atdesc = tld as TLAssociatedTypeDescriptor;
1667+
Assert.IsNotNull (atdesc, "not an associated type desc");
1668+
Assert.AreEqual ("PresentedControllerType", atdesc.AssociatedTypeName.Name, "wrong associated type name");
1669+
Assert.AreEqual ("Eureka.PresenterRowType", atdesc.Class.ClassName.ToFullyQualifiedName (), "protocol name mismatch");
1670+
}
1671+
1672+
[Test]
1673+
public void TestAssociatedTypeDescriptor2 ()
1674+
{
1675+
var tld = Decomposer.Decompose ("_$s9InlineRow6Eureka0aB4TypePTl", false);
1676+
Assert.IsNotNull (tld, "failed decomposition");
1677+
var atdesc = tld as TLAssociatedTypeDescriptor;
1678+
Assert.IsNotNull (atdesc, "not an associated type desc");
1679+
Assert.AreEqual ("InlineRow", atdesc.AssociatedTypeName.Name, "wrong associated type name");
1680+
Assert.AreEqual ("Eureka.InlineRowType", atdesc.Class.ClassName.ToFullyQualifiedName (), "protocol name mismatch");
1681+
}
16491682
}
16501683
}

0 commit comments

Comments
 (0)