From 7d7a2eda742187d39739545dc3145044567ea25b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Tue, 22 Oct 2019 19:50:46 +0200 Subject: [PATCH] Issue #21 --- Capnp.Net.Runtime.Tests/test.cs | 117 ++++++++---------- .../CapnpC.CSharp.Generator.Tests.csproj | 2 + .../CodeGenerator.feature | 1 + .../CodeGenerator.feature.cs | 12 ++ .../Embedded Resources/Issue21.capnp.bin | Bin 0 -> 1928 bytes .../Embedded Resources/test.cs | 115 ++++++++--------- .../CodeGen/CodeGenerator.cs | 52 +++++++- .../CodeGen/InterfaceSnippetGen.cs | 10 +- MsBuildGenerationTest/Issue21.capnp | 13 ++ 9 files changed, 181 insertions(+), 141 deletions(-) create mode 100644 CapnpC.CSharp.Generator.Tests/Embedded Resources/Issue21.capnp.bin create mode 100644 MsBuildGenerationTest/Issue21.capnp diff --git a/Capnp.Net.Runtime.Tests/test.cs b/Capnp.Net.Runtime.Tests/test.cs index 0d01cbe..925ff9d 100644 --- a/Capnp.Net.Runtime.Tests/test.cs +++ b/Capnp.Net.Runtime.Tests/test.cs @@ -11684,21 +11684,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); - public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) - { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); - } - - static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); - public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) - { - return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); - } - } - public static class TestPipeline { [TypeId(0xb0b29e51db0e26b1UL)] @@ -12469,15 +12454,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); - public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); - } - } - public static class TestTailCallee { [TypeId(0xa9ed2e5a9fd53d19UL)] @@ -12692,10 +12668,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - } - public static class TestTailCaller { [TypeId(0xb07a279515dc8ac5UL)] @@ -13156,33 +13128,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); - } - - static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); - } - - static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); - } - - static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); - } - } - public static class TestMoreStuff { [TypeId(0x931ba418da60f6e4UL)] @@ -14834,15 +14779,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); - } - } - public static class TestMembrane { [TypeId(0x9352e4e41f173917UL), Proxy(typeof(ThingProxy)), Skeleton(typeof(ThingSkeleton))] @@ -17313,4 +17249,55 @@ namespace Capnproto_test.Capnp.Test } } } -} \ No newline at end of file + + public static partial class PipeliningSupportExtensions + { + static readonly MemberAccessPath Path_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) + { + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); + } + + static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) + { + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); + } + + static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); + public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); + } + + static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); + } + + static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); + } + + static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); + } + + static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); + } + + static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); + } + } +} diff --git a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj index cf329b9..2911d45 100644 --- a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj +++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj @@ -28,6 +28,7 @@ + @@ -45,6 +46,7 @@ + diff --git a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature index 8952e00..a32890f 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature @@ -55,3 +55,4 @@ Scenario Outline: Valid generator output Examples: | bin | | Issue19.capnp.bin | + | Issue21.capnp.bin | \ No newline at end of file diff --git a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs index 0fdc738..f81372f 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs @@ -267,6 +267,18 @@ this.ScenarioInitialize(scenarioInfo); { #line 50 this.ValidGeneratorOutput("Issue19.capnp.bin", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Issue21.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Issue21.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "Issue21.capnp.bin")] + public virtual void ValidGeneratorOutput_Issue21_Capnp_Bin() + { +#line 50 +this.ValidGeneratorOutput("Issue21.capnp.bin", ((string[])(null))); #line hidden } } diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/Issue21.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/Issue21.capnp.bin new file mode 100644 index 0000000000000000000000000000000000000000..43ce0da193313eb043962cf2fb2cbb936e6e24d5 GIT binary patch literal 1928 zcmd5-&r4KM6h3c8Qx_J6*rJ7kfh0IE11%IJW&)A2pMXig;S$5L$nB2{sp>7 zS_EQHk%B_tqGb`ZkZc#Yw4GA_fZ+Gdy~lUo<34}vJaF&1=iGD8Iqy5?-X|jRAHz_K zT*l%@N@OW5(t~viMu0H{c@A8ptvUB%Zj}r2;CKJ`f18ii+MC+ssR$>t*uDdPHQDTF zXJ=<(_uyA*`yw=quW>ZK8s5a_GK3NEepMdBr{63Et6$f@b;BlTdRAleT`FbaZ-9Yg zGz8tPn2zGitG$tq!UyZuHHi9si1Rs*U-yK&9=rGU%hu=geixJ|fhaDn4cB@2+yE!e zZp2Z@x1q1Z^cxGEyVr_?pH9MI66bt4Jcizf!`9!IeVNhmKgKUJGZaL!5_ygDJ{;x~ z{H}COtxUfAxp)!|?{S_utb)5Ze1uFKwqyEYt=1^#vY98P>hmi0O}__6IKy0W7!!?p znf)8FA6Bgh`=9-!_3D6p1w-?0wQ?SuR4~lvFO$zy%JpY2p60LLEzOoHHJUQ7baS=` zBfTrq3H7jUfis^pY=~D1yh=}5-r3_RY2WkRPM-J6wZ?RviF)m9NaAC@BaEW=QST4m zAH~L(DNnMl79nfGDjEEJ@e3Bu!a2t?%rnIEG<9d6DaGqvvKz#er2T26aMt}$V^&@~ zt&y*u`mX3ZaJG7C<->Zie*<)|-XqN~i^U}s96o6E@$bB0_2GZSIfP}>yGs0-fzoMY V=BshouY5Q79 task) - { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); - } - - static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); - public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) - { - return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); - } - } - public static class TestPipeline { [TypeId(0xb0b29e51db0e26b1UL)] @@ -11685,15 +11670,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); - public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); - } - } - public static class TestTailCallee { [TypeId(0xa9ed2e5a9fd53d19UL)] @@ -11908,10 +11884,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - } - public static class TestTailCaller { [TypeId(0xb07a279515dc8ac5UL)] @@ -12372,33 +12344,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); - } - - static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); - } - - static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); - } - - static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); - } - } - public static class TestMoreStuff { [TypeId(0x931ba418da60f6e4UL)] @@ -14050,15 +13995,6 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions - { - static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); - } - } - public static class TestMembrane { [TypeId(0x9352e4e41f173917UL), Proxy(typeof(ThingProxy)), Skeleton(typeof(ThingSkeleton))] @@ -16529,4 +16465,55 @@ namespace Capnproto_test.Capnp.Test } } } + + public static partial class PipeliningSupportExtensions + { + static readonly MemberAccessPath Path_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) + { + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); + } + + static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) + { + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); + } + + static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); + public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); + } + + static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); + } + + static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); + } + + static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); + } + + static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); + } + + static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); + public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) + { + return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); + } + } } \ No newline at end of file diff --git a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs index 9721552..32d6f75 100644 --- a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs +++ b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs @@ -101,11 +101,6 @@ yield return _interfaceGen.MakeProxy(def); yield return _interfaceGen.MakeSkeleton(def); - if (_interfaceGen.RequiresPipeliningSupport(def)) - { - yield return _interfaceGen.MakePipeliningSupport(def); - } - if (def.NestedTypes.Any()) { var ns = ClassDeclaration( @@ -147,6 +142,46 @@ } } + ClassDeclarationSyntax TransformPipeliningSupport(IHasNestedDefinitions def) + { + var classDecl = default(ClassDeclarationSyntax); + + var q = new Queue(); + + foreach (var inner in def.NestedDefinitions.OfType()) + { + q.Enqueue(inner); + } + + while (q.Count > 0) + { + var cur = q.Dequeue(); + + if (cur.Tag == TypeTag.Interface && _interfaceGen.RequiresPipeliningSupport(cur)) + { + var members = _interfaceGen.MakePipeliningSupport(cur).ToArray(); + + if (members.Length > 0) + { + if (classDecl == null) + { + classDecl = ClassDeclaration(_names.PipeliningExtensionsClassName.Identifier) + .AddModifiers(Public, Static, Partial); + } + + classDecl = classDecl.AddMembers(members); + } + } + + foreach (var inner in cur.NestedDefinitions.OfType()) + { + q.Enqueue(inner); + } + } + + return classDecl; + } + internal string Transform(GenFile file) { NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace; @@ -158,6 +193,13 @@ ns = ns.AddMembers(Transform(def).ToArray()); } + var psc = TransformPipeliningSupport(file); + + if (psc != null) + { + ns = ns.AddMembers(psc); + } + var cu = CompilationUnit().AddUsings( UsingDirective(ParseName("Capnp")), UsingDirective(ParseName("Capnp.Rpc")), diff --git a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs index 2a2f9dd..0f86f80 100644 --- a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs @@ -760,11 +760,8 @@ namespace CapnpC.CSharp.Generator.CodeGen readonly HashSet<(string, string)> _existingExtensionMethods = new HashSet<(string, string)>(); - public MemberDeclarationSyntax MakePipeliningSupport(TypeDefinition type) + public IEnumerable MakePipeliningSupport(TypeDefinition type) { - var classDecl = ClassDeclaration(_names.PipeliningExtensionsClassName.Identifier) - .AddModifiers(Public, Static, Partial); - foreach (var method in type.Methods) { foreach (var path in ExpandPipeliningPaths(method)) @@ -836,11 +833,10 @@ namespace CapnpC.CSharp.Generator.CodeGen Argument( accessPath.IdentifierName))))))); - classDecl = classDecl.AddMembers(pathDecl, methodDecl); + yield return pathDecl; + yield return methodDecl; } } - - return classDecl; } } } diff --git a/MsBuildGenerationTest/Issue21.capnp b/MsBuildGenerationTest/Issue21.capnp new file mode 100644 index 0000000..2d07bda --- /dev/null +++ b/MsBuildGenerationTest/Issue21.capnp @@ -0,0 +1,13 @@ +@0xae5ab8efc527d253; + +struct Outer { + + interface A { + methodA @0 (param1 :Int64) -> (); + } + + interface B { + methodB @0 (param1 :Int64) -> (a :A); + } + +}