From 62d5a7e9bd207fc4aaa67877a9dea326bed63984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sat, 18 Apr 2020 15:06:52 +0200 Subject: [PATCH] feature: header text in generated files fixed double-far encoding/decoding bug --- Capnp.Net.Runtime/DeserializerState.cs | 2 +- Capnp.Net.Runtime/Rpc/rpc.cs | 1 + Capnp.Net.Runtime/SerializerState.cs | 2 +- .../CapnpC.CSharp.Generator.Tests.csproj | 4 + CapnpC.CSharp.Generator.Tests/Embedded | Bin 0 -> 3736 bytes .../NullableDisable.capnp.bin | Bin 1720 -> 1664 bytes .../NullableDisable2.capnp.bin | Bin 2112 -> 2008 bytes .../NullableEnable.capnp.bin | Bin 1720 -> 1656 bytes .../NullableEnable2.capnp.bin | Bin 2112 -> 2008 bytes .../Embedded Resources/rpc-csharp.capnp.bin | Bin 66744 -> 66784 bytes .../Embedded Resources/test.capnp.bin | Bin 141680 -> 141704 bytes .../UnitTest1.capnp | 0 .../No Resources/rpc-csharp.capnp | 4 +- .../No Resources/test.capnp | 2 +- .../testdata/annotated-json.binary | Bin 0 -> 544 bytes .../No Resources/testdata/annotated.json | 22 +++ .../No Resources/testdata/binary | Bin 0 -> 2816 bytes .../testdata/errors.capnp.nobuild | 161 +++++++++++++++ .../No Resources/testdata/errors.txt | 60 ++++++ .../No Resources/testdata/flat | Bin 0 -> 2808 bytes .../No Resources/testdata/lists.binary | Bin 0 -> 1096 bytes .../No Resources/testdata/packed | Bin 0 -> 831 bytes .../No Resources/testdata/packedflat | Bin 0 -> 828 bytes .../No Resources/testdata/pretty.json | 88 +++++++++ .../No Resources/testdata/pretty.txt | 187 ++++++++++++++++++ .../No Resources/testdata/segmented | Bin 0 -> 5520 bytes .../No Resources/testdata/segmented-packed | Bin 0 -> 1352 bytes .../No Resources/testdata/short.json | 1 + .../No Resources/testdata/short.txt | 1 + .../CodeGen/CodeGenerator.cs | 9 +- CapnpC.CSharp.Generator/Model/GenFile.cs | 1 + CapnpC.CSharp.Generator/Model/SchemaModel.cs | 16 ++ CapnpC.CSharp.Generator/Model/SourceInfo.cs | 12 ++ .../Model/SupportedAnnotations.cs | 15 ++ include/capnp/c++.capnp | 26 +++ scripts/regen-capnpbin.bat | 3 + 36 files changed, 612 insertions(+), 5 deletions(-) create mode 100644 CapnpC.CSharp.Generator.Tests/Embedded rename CapnpC.CSharp.Generator.Tests/{Embedded Resources => No Resources}/UnitTest1.capnp (100%) create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated-json.binary create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/binary create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/flat create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/lists.binary create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/packed create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/packedflat create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented-packed create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.json create mode 100644 CapnpC.CSharp.Generator.Tests/No Resources/testdata/short.txt create mode 100644 CapnpC.CSharp.Generator/Model/SourceInfo.cs create mode 100644 include/capnp/c++.capnp create mode 100644 scripts/regen-capnpbin.bat diff --git a/Capnp.Net.Runtime/DeserializerState.cs b/Capnp.Net.Runtime/DeserializerState.cs index 1aee28e..eaa24f9 100644 --- a/Capnp.Net.Runtime/DeserializerState.cs +++ b/Capnp.Net.Runtime/DeserializerState.cs @@ -350,7 +350,7 @@ namespace Capnp throw new DeserializationException("Error decoding double-far pointer: not followed by intra-segment pointer"); CurrentSegmentIndex = pointer1.TargetSegmentIndex; - Offset = 0; + Offset = pointer1.LandingPadOffset; pointer = pointer2; offset = -1; } diff --git a/Capnp.Net.Runtime/Rpc/rpc.cs b/Capnp.Net.Runtime/Rpc/rpc.cs index d2d8c5f..c48f8d0 100644 --- a/Capnp.Net.Runtime/Rpc/rpc.cs +++ b/Capnp.Net.Runtime/Rpc/rpc.cs @@ -1,3 +1,4 @@ +#pragma warning disable CS1591 using Capnp; using Capnp.Rpc; using System; diff --git a/Capnp.Net.Runtime/SerializerState.cs b/Capnp.Net.Runtime/SerializerState.cs index 293a424..cb219d1 100644 --- a/Capnp.Net.Runtime/SerializerState.cs +++ b/Capnp.Net.Runtime/SerializerState.cs @@ -375,7 +375,7 @@ namespace Capnp farPtr2.SetFarPointer(target.SegmentIndex, target.Offset, false); var farSpan = FarSpan(landingPadSlice.SegmentIndex); farSpan[landingPadSlice.Offset] = farPtr2; - targetPtr.Offset = target.Offset; + targetPtr.Offset = 0; farSpan[landingPadSlice.Offset + 1] = targetPtr; } } diff --git a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj index 77462b1..86f1a6b 100644 --- a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj +++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj @@ -30,6 +30,10 @@ + + + + diff --git a/CapnpC.CSharp.Generator.Tests/Embedded b/CapnpC.CSharp.Generator.Tests/Embedded new file mode 100644 index 0000000000000000000000000000000000000000..79d5e7d828d0888f0ecf55605a96c9fff77f35e4 GIT binary patch literal 3736 zcmbVPU5Hgx6yEdWPnpz6G3JYAhMGB!F%=D{ph64`{!9r94RO44iwn)YH}AC?YN)v; z_=Cc{NcB(=i6{z+5lKoW_>Zac5ItwUhy+SO5=7s(_xaA*XV1NpxL}{P*IIk6v-Y?4 zUgut8j2Uaf!&0kh1OKSin0u3rnTllX!-7f3U}R0__a6-ZeJWhP3~|Pw>;ZR~ zxfQD+x7f_H9*XmDRy|I70sb{;ndf})4d4^yyZrXatJ`Z+FA={M4B>)lhWZibYiRP| zFL{>jkeR=@Ojp}`+eW`x_7!np+*P~h{M9;^`%`xDLHHknur-b&{X39ff$&+NKmPv4 zUw`O5`upRsF|P8LpZEy;E%>YuVtM+Ye;-EjzSLxA_T@`*ix#;wx{J|ZzEX~Id2b!-6vp+;_2QVR(9%zN zJ_MP0{5*Q+-=PBocPT%M5x$Qy)N$V)zfabo(LO(i#qOuOJ1Q1S)u>u16)V;uc_cW* zxOd0Ea(~QMeT99H`RN`^$9yG*>d*Y=Vyr0**nC&L9aSp%ig|VGW@sI?p!1U$H+gT2 zv;1Ud9krf1^&#~Q=EL_lBEE^|?yY>ar}$FQoVh2 z#4nw5tqUQ!kho{tv$78@21m#d_Om=J%_JWP0xI>C9~xjNmQR-q4J>f^Kk zGX1*1=~s;FMLbF2{+!m>-w~SoJQvrQ{g$Nu>!kE4d#Z7>5Eq>rTDhzH!G--mR1X(t za~NqIaq;~^Tncf2QQkWD@)ws~vUuTn%^r*=xOnH&$A(e4BX>{u6lKp1?Yw zBkNy@@2B>m`>gfivP%}PmnZK$Gh%-FUN9^6yYiM&wNxD{+a>||e)9LveVG41RE-b@ zZ@d%R!j9lF=5mBV3t-+s{VQotIu*cuF3|S)w3FA9*_cq1Z*gogW zTFLWXPw(vGUNz35-VSQ7kTg33}7 IH@;W@0nr@WBLDyZ literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin index 14f05c8dbdd594ee40531bef29e1d33599139cd1..0195af509b3a7de4d6d97592213a9e39798e8759 100644 GIT binary patch delta 531 zcmdnN+rX>I00iej1Q@U|2mVy%b`Pfguo0jql`#jN-9wR{BAy1^LDL$%zGd z1x5KK`MN3jC3&eO$@xX8`pzIhXFccOjKrb>J@?eS)S|?a{35-O)Z&t2eZPE#pw#00 z(xT+lV*Sv(%o32Wp_v}oD4?qtCi5~KHsb*@7=duX+hZAG&AhKc;S~hL3z7I$K>i{m zz81seFlMF62bdQG)4+j~^I0S}_pq#BtOrGkA<%A6q|m@3L`VS5holQehSgAi0;6Mc HHk&8_Htm|L diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin index dcc032abdebdc1a9e8df46a9810d832c12bf82e8..5681502377722ce251cc43eb2261de3658b689e1 100644 GIT binary patch delta 493 zcmX>gaD!iq0SJD92ryt_5CqcVObiTbnHd=5fov8aW(4AoOcS-_7zHN_GRup81oC$Q z@lPNY2Vzd30&}2@^yCIMj)@BtBo%=IkAM=oK$;y$!+^%*hm7JAKWK1)M5sP5{Mp{7B!YnlM`9BH+QqfGqNP-r=(7P V$F`4W7tnBCAO^(^*q7oQngF1ZZH52< delta 602 zcmcb?e?UNs0SMR`K_m#UFbD!kaV7?az03>@@?a4L29Pu(^F%E<#;D1L%<`fifqW*Q zyev>c9LUxM(&j)J>B$Lf91|BPNV)87Uy{MN`oMR3XopFqx4_UbYe_ z7X@_XS~N8)fqeUkfx@0{R{BAy1^LDL$%zGd1x5KK`MN3jC3&eO$@xX8`pzIhXFccO zjKrb>J@?eS)S|?a{35-O)Z&t2eZPE#pw#00(xT+lV*SYhOyZL>n0~kk03FQ;gbUst z%MfekeJu&(2LbUyBz_f;zZi+X3CLdr<;w!uS`3q)F}8?RF!T3 diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin index 4a92c1a303018bc643e701d6f89d43f84b93dd1a..6c81ea600449a1cdd5ab044e6ae23132f685ce7d 100644 GIT binary patch delta 539 zcmdnN`-4Z50SL~42ryt_5Cqcu85tPQSl*?|}a9sn84lNT}xPyC=EdJ)LU0^+McTn@y( zKpVg&O!i>ZkPQX$b^%3Wfi$ua5kNlJh{+2WIT%GJuVj>$^aP4A0WnAqvf9AO4;jTp z{7Q3j5|eULUGqSsUUFhVUcuxLrX%$-K;s#KaOvA)8Dh=6uML6xDj;5f#18`U7b5XN z@{5u9n}GZ!P`)XU{R@bfLHV{oHc0&)bRo_DC)3jnB2pr0{}pWi#`AV delta 576 zcmeytvx8TY0SK;v2ryt_5Cqcu85tOUGBGg71KBJ<4CFFYPSliV44J%;NnZ3Qkb4Oz z{SiougQS7-@<18s$qB3+6Bj5*{RIj>0%A^}1Urz10T#xIx9mi}0=Zd0{1b@Hfmju; z-Gfm>QWwbE1r#+!(`zuflTn^AYVt}(c}Yc}oE9?!Lm-+O-^mXd#bey8^n+3h@{9G8 z6ASVRitQ17t7);exlvGQ^sBUxR`y2#6OV@vDIR wMM!)thRI>fN|O&TF9@cA`zGhHh;43USgaD!iq0SJD92ryt_5CqcVObiTbnHd=5fov8aW(4AoOcS-_7zHKisq}hQq3}{S#$S6MXgNCRiP$CN`Dhs5` zf%H@$Ee|!rgHc0rE|9+qD83X(BO9;)WWeMFKot{#GEzXi5KYA#pbB|LvB``~^0K`^ zIW8aunTBl2Od#KWVxaJ3Mh@}G>zRJm%K)un1j40nk7bB8^S(9&@~eP&0TMq5$X|%W z2gxr+;)8-@36yUNWP<{A8I*4eWP{W%LgIr$KBTfBH7v83Ju@jYC$pq-@;hcLz0};y z5|{kk#LPVBoW$bd)MCfH6wkbp)S|S+c_wKsRO#xt@c=clAj Ve#f?t2jm!DAO^(`*q7oQngE;}Z~p)Q delta 602 zcmcb?e?UNs0SMR`K_m#UFbD!kaV7?az03>@@?a4L29Pu(^F%E<#>mNr%<`fif&5=U zHL^enaUfe4NSgy?q$ek^aZFsGAn6Jecm$LP1k&t48U}nOKV%f2_(4O|7ATPg6m;&?50YxVQX=Lp^AnlVE09DiiWu$<(7fnS6P=!2W{A5NZdD%*! zToBL~YthuK1oG`C1`2z+S?LF*7UUP}Cnpx<6%^%{N|r3o%Ni9 zGZKpm^xRYPQi~Ex@{9CBQj1H9_5Jb{f>Mj~ON)|Ii}fc5Fo{pjVEW-E0CY4X5H5Io zEJLiB_q8OD9|Xh;k@!_W{$eElCLn(ilrIZpYcWiI#%wh?faL=f9q7QSy*Y<9j*+E2 avm|5kIktVFp!hQcS_g_h>ITFHb`1bO*_ToP diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/rpc-csharp.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/rpc-csharp.capnp.bin index 720907783602a0916c0a7c1ade509a2b8890a602..0a66adb1d3dc66dea27ce9a9e4d6ffa2003db42e 100644 GIT binary patch delta 149 zcmdnd$?~9+MUaI72tWi7m#{N1Y}hEc-j1^)_e(?p9@`<` diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.capnp.bin index 66c8d13757549b83eaaa4e2e4e1ff90e836ca0da..199c9d32bde29d294b778ab0a2803f43e5362bc7 100644 GIT binary patch delta 892 zcmZWnO=uHQ5Pq{snjecaO4w{8q=|(r1gy!;pZa1Dg`ReMvBY4TlpYMWre1`-wH}n* zHggE{l;$MyptgrXPU5i_ZN2rDLIrbbb1alNoAizKtbB{HcXs49SoXaX?AWCbFk$~qh3BcSkj{-VCLj(W+m458velB@!*zJ3 z&0P}%70K?Pg$KZ6HQMRewI#dV&N##MpApO{y4H&eO=xO#^(1a6JXV<%)w*QYp*1TU zPRSwrNN5U@T}=fu9v(aAqMOW(`e$>(q3O{z>xt-XNp>CD*!6I*FyU39OP&yk9{iC32F69xq9)+>P4~oE9tlJjP(12T-z@TU0<^M8VYWY zskk(z!@QHhCLxD8>{4zyh!cL@(_b07LK00sCtus|_!8oGzpmw93GcFG*ZVC(fWr?$ z6?zV0HK0QWztOo*$hG6wV)Dl7=vO4M6jX64sKbtv!7(9++U|Dn%Tt&@(@2GT&lz)m zJvYuVW2o3PbS=3cIu*&5?|}6?DxHy?|a|d9rn|&_*p-`7-5Xf z)00m!#;-AEFERGUUAzg7dpiRixAGB^?rBEbAU#CBV3jZpDTugkN^2;orFe+1;J&_o z#c!|`2aOIMgESg6(~IjU4%FT}zH@J2F(mY1%D04;XD2V<`;av375{WkaS+g2nFgFu zKz7x)Y$^^cHs-_9xRAbT6ldeJ#c4o0EOh6tFEteh0UaEKB{-OlaA%UE14( z68d;d_1ME^RM6pCl*1k&&3&roZv8iRYdW_}_9mW_{fJN+N49SpDGuIYY)|da<^*iu z{v3y0LJ8|QpxW^eug64aRP$_LpcRvp>&CoXLi`yMdf~aBT~Zumzd(pf_(8~F=pokQ z0($tJ_9H^6pS<)tliRZ&VPGY}aXBI2t5?AZp@hc4e&X9bNTOwCwBaMhyq_*u7nnCW zwoRcMkA1~f>?rQzz?5`*X^Ydv5~68|Xs<+W)ZXUsizU)yZ%2{YCq5Sxw-lES&aFF1 z-XTjhm%CN1)OYHIoyvCYb-hxp;e+zp)y>P=XUzcqp<6!emf?4MVfV5&?Zb!V)x$r3 Sp`KfsX(Xe!PA8KIC;kU7VY8tC diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest1.capnp similarity index 100% rename from CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest1.capnp rename to CapnpC.CSharp.Generator.Tests/No Resources/UnitTest1.capnp diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp index fa0f149..730a740 100644 --- a/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp +++ b/CapnpC.CSharp.Generator.Tests/No Resources/rpc-csharp.capnp @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Christian Köllner and contributors +# Copyright (c) 2020 Christian Köllner and contributors # This is a modified version of rpc.capnp, found in the original distribution # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors # Licensed under the MIT License: @@ -110,6 +110,8 @@ # network at level 4. And since Cap'n Proto IPC is extremely fast, it may never make sense to # bother implementing any other vat network protocol -- just use the correct container type and get # it for free. +# $$embed +# #pragma warning disable CS1591 using CSharp = import "/csharp.capnp"; $CSharp.namespace("Capnp.Rpc"); diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp index 0a4a507..d68c71c 100644 --- a/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp +++ b/CapnpC.CSharp.Generator.Tests/No Resources/test.capnp @@ -21,7 +21,7 @@ @0xd508eebdc2dc42b8; -using Cxx = import "c++.capnp"; +using Cxx = import "/capnp/c++.capnp"; # Use a namespace likely to cause trouble if the generated code doesn't use fully-qualified # names for stuff in the capnproto namespace. diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated-json.binary b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated-json.binary new file mode 100644 index 0000000000000000000000000000000000000000..6c54755184df36aa9d07ef4ee925a624db789ce5 GIT binary patch literal 544 zcmZuuK~BRk5Zt8YMkOv45+@68NWE}GLMq|`d;pLV*Kv$Y9J%hH;y;|Y@B^O4?7D_j zVwBlg+ncO+LPYccGUjwf@6Z`lbYBrIXN0Vxk6Ml;+#z0q|LFzlo)70mpX9BY4D=Rc zy#hC2jc*rxA>r?`UYAYiC&+gw=t7XRX|6lNk?o!63F3`pIp`2A&tRK4`hE6_Cz(%bIOQ8Z zf~O$QIkAxF`(=%70W3bk0xRyveW&2{IoKQT*@4`zmOA#8*W4$xuSTb1&v5jMF6IG8 Rzq9>e_s`wzH2;U<>krr}I0*m% literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json new file mode 100644 index 0000000..bb51400 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/annotated.json @@ -0,0 +1,22 @@ +{ "names-can_contain!anything Really": "foo", + "flatFoo": 123, + "flatBar": "abc", + "renamed-flatBaz": {"hello": true}, + "flatQux": "cba", + "pfx.foo": "this is a long string in order to force multi-line pretty printing", + "pfx.renamed-bar": 321, + "pfx.baz": {"hello": true}, + "pfx.xfp.qux": "fed", + "union-type": "renamed-bar", + "barMember": 789, + "multiMember": "ghi", + "dependency": {"renamed-foo": "corge"}, + "simpleGroup": {"renamed-grault": "garply"}, + "enums": ["qux", "renamed-bar", "foo", "renamed-baz"], + "innerJson": [123, "hello", {"object": true}], + "testBase64": "ZnJlZA==", + "testHex": "706c756768", + "bUnion": "renamed-bar", + "bValue": 678, + "externalUnion": {"type": "bar", "value": "cba"}, + "unionWithVoid": {"type": "voidValue"} } diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/binary b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/binary new file mode 100644 index 0000000000000000000000000000000000000000..ea39763774b2ed570407a3384a8865fbeaa79213 GIT binary patch literal 2816 zcmds&Ur1AN6vxkWS&HkAuIPW8=7SmHpCql9^$#>me6W{5?5dmphIhN$&20o*hW)W9 z1(Oo7dI`i#kfet)ETUCJ!Lqkly#!@FNCf?r+xOhv#rDvHK7{PRxu4(popUbt+ehzpE+zbwD zd;oSN5v{_*aeh>6qNpzG1xcmuYrwF4W#z9b*N4&@#Y9Iaq&J?aPY$Jt8Rm7*^>vQa zG2A91J+kFr_2uB5twod>%+<*6f$eOK{Jb2;&szwxpUHkE`%5(c9&iWj3a|vM1-U+_ z#x9WSdkx)y{ixInK6UAoJ<+Xsk?Y$PlTnT}f4{{d?N*oD+BpBG;kqJUeEzxrBSW$Z zcDvW~w>+L5mh^DI&kX59A1R>ttAu-Gd3Eh4wgQTx_`Popr^+2f`Eur5cmJHiu@LsL z_|vmU-3#gS*AOWR=TB{~Q%9BqqWPij&q;C%nn@G(v9MWsyT9V$2S=HQuitvi3_5R4j9o4opuy1t7<-%*0nF?ah^uhl!X%niZ4f?|@BY|1 zjLsv^nZqtOHG>|n&xbK1ceAXXwj9s%$2S-3_n4?*;H53<=6{-L1 kh0bLw-#9^p=Q5G%;kjJQ^~6slQH;&)9&2MNS(d8TKa`mRLjV8( literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild new file mode 100644 index 0000000..a909e97 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.capnp.nobuild @@ -0,0 +1,161 @@ +# Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors +# Licensed under the MIT License: +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# This file is intended to test that various error cases are detected as errors. The error +# output is matched against a golden file. The file name has the .nobuild extension to make +# sure that a build system which automatically builds .capnp files does not try to build this one. + +# + +@0xccd0890aa4926a9b; +# Can't really test the missing-ID error because the output is intentionally unpredictable. + +const notType :Int32 = 123; +annotation notFieldAnnotation(struct) :Int32; +annotation fieldAnnotation(field) :Int32; + +struct Foo { + dupName @0 :Int32; + dupName @1 :Int32; + dupNumber1 @2 :Int32; + dupNumber2 @2 :Int32; + + missingNumber @4 :Int32; + next @5 :Int32; + + emptyUnion :union {} + emptyGroup :group {} + + singletonUnion :union { + field @6 :Int32; + } + + union { + dupName @7 :Int32; + f8 @8 :Int32; + } + union { + f9 @9 :Int32; + f10 @10 :Int32; + } + + struct wrongTypeStyle {} + WrongFieldStyle @11 :Int32; + under_score @12 :Int32; + + containsStruct :group { + f13 @13 :Int32; + struct CantNestHere {} + } + + retroUnion @16! :union { + f14 @14 :Int32; + f15 @15 :Int32; + } + + missingColonAndEclamation @18 union { + f19 @19 :Int32; + f20 @20 :Int32; + } + + missingExclamation @21 :union { + f22 @22 :Int32; + f23 @23 :Int32; + } + + missingColon @24! union { + f19 @25 :Int32; + f20 @26 :Int32; + } + + unnamedInNamed :union { + f27 @27 :Int32; + f28 @28 :Int32; + union { + # content is ignored + } + } + + listWithoutParam @31 :List; + listWithTooManyParams @32 :List(Int32, Int64); + listAnyPointer @33 :List(AnyPointer); + notAType @34 :notType; + noParams @35 :Foo(Int32); + + defaultOutOfRange @36 :Int16 = 1234567; + defaultOutOfRange2 @37 :UInt16 = -1; + defaultWrongType @38 :Text = 123; + defaultWrongType2 @39 :Text = [123]; + defaultWrongType3 @40 :Text = (foo = 123, bar = 456); + defaultTooBigToBeNegative @41 :Int64 = -0x8000000000000001; + defaultNotConstant @42 :Int32 = .Foo; + defaultConstantNotQualified @43 :Int32 = notType; + + notAnnotation @44 :Int32 $Foo(123); + badAnnotation @45 :Int32 $notFieldAnnotation(123); + notVoidAnnotation @46 :Int32 $fieldAnnotation; + + undefinedImport @17 :import "noshuchfile.capnp".Bar; + undefinedAbsolute @47 : .NoSuch; + undefinedRelative @29 :NoSuch; + undefinedMember @30 :Foo.NoSuch; +} + +struct Bar { + x @3 :Text; + someGroup :group { + defaultMissingFieldName @2 :Bar = (x = "abcd", 456); + defaultNoSuchField @0 :Bar = (nosuchfield = 123); + defaultGroupMismatch @1 :Bar = (someGroup = 123); + } +} + + +using Bar; + +enum DupEnumerants { + dupName @0; + dupName @1; + dupNumber1 @2; + dupNumber2 @2; +} + +const recursive: UInt32 = .recursive; + +struct Generic(T, U) { +} + +struct UseGeneric { + tooFew @0 :Generic(Text); + tooMany @1 :Generic(Text, Data, List(Int32)); + doubleBind @2 :Generic(Text, Data)(Data, Text); + primitiveBinding @3 :Generic(Text, Int32); +} + +const embedBadType :UInt32 = embed "binary"; +const embedNoSuchFile :Data = embed "no-such-file"; + +using Baz = import "nosuchfile-unused.capnp".Baz; +# Check that an import in an unused `using` still reports error. + +interface TestInterface { + foo @0 (a :UInt32 = null); +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt new file mode 100644 index 0000000..ed238e4 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/errors.txt @@ -0,0 +1,60 @@ +file:74:30-32: error: As of Cap'n Proto v0.3, it is no longer necessary to assign numbers to unions. However, removing the number will break binary compatibility. If this is an old protocol and you need to retain compatibility, please add an exclamation point after the number to indicate that it is really needed, e.g. `foo @1! :union {`. If this is a new protocol or compatibility doesn't matter, just remove the @n entirely. Sorry for the inconvenience, and thanks for being an early adopter! :) +file:74:30-32: error: As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon for named unions, e.g. `foo :union {`. +file:79:23-25: error: As of Cap'n Proto v0.3, it is no longer necessary to assign numbers to unions. However, removing the number will break binary compatibility. If this is an old protocol and you need to retain compatibility, please add an exclamation point after the number to indicate that it is really needed, e.g. `foo @1! :union {`. If this is a new protocol or compatibility doesn't matter, just remove the @n entirely. Sorry for the inconvenience, and thanks for being an early adopter! :) +file:84:17-19: error: As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon for named unions, e.g. `foo :union {`. +file:132:7-10: error: 'using' declaration without '=' must specify a named declaration from a different scope. +file:37:3-10: error: 'dupName' is already defined in this scope. +file:36:3-10: error: 'dupName' previously defined here. +file:52:5-12: error: 'dupName' is already defined in this scope. +file:36:3-10: error: 'dupName' previously defined here. +file:55:3-8: error: An unnamed union is already defined in this scope. +file:51:3-8: error: Previously defined here. +file:60:10-24: error: Type names must begin with a capital letter. +file:61:3-18: error: Non-type names must begin with a lower-case letter. +file:62:3-14: error: Cap'n Proto declaration names should use camelCase and must not contain underscores. (Code generators may convert names to the appropriate style for the target language.) +file:66:5-27: error: This kind of declaration doesn't belong here. +file:44:3-23: error: Union must have at least two members. +file:45:3-23: error: Group must have at least one member. +file:47: error: Union must have at least two members. +file:92: error: Unions cannot contain unnamed unions. +file:39:15-16: error: Duplicate ordinal number. +file:38:15-16: error: Ordinal @2 originally used here. +file:41:18-19: error: Skipped ordinal @3. Ordinals must be sequential with no holes. +file:69:15-17: error: Union ordinal, if specified, must be greater than no more than one of its member ordinals (i.e. there can only be one field retroactively unionized). +file:116:31-50: error: Import failed: noshuchfile.capnp +file:118:26-32: error: Not defined: NoSuch +file:119:28-34: error: 'Foo' has no member named 'NoSuch' +file:97:25-29: error: 'List' requires exactly one parameter. +file:98:30-48: error: Too many generic parameters. +file:98:30-34: error: 'List' requires exactly one parameter. +file:99:23-39: error: 'List(AnyPointer)' is not supported. +file:100:17-24: error: 'notType' is not a type. +file:101:17-27: error: Declaration does not accept generic parameters. +file:103:34-41: error: Integer value out of range. +file:104:37-38: error: Integer value out of range. +file:105:32-35: error: Type mismatch; expected Text. +file:106:33-38: error: Type mismatch; expected Text. +file:107:33-55: error: Type mismatch; expected Text. +file:108:43-61: error: Integer is too big to be negative. +file:109:35-39: error: '.Foo' does not refer to a constant. +file:110:44-51: error: Constant names must be qualified to avoid confusion. Please replace 'notType' with '.notType', if that's what you intended. +file:117:28-34: error: Not defined: NoSuch +file:112:29-32: error: 'Foo' is not an annotation. +file:113:29-47: error: 'notFieldAnnotation' cannot be applied to this kind of declaration. +file:114:33-48: error: 'fieldAnnotation' requires a value. +file:126:35-46: error: Struct has no field named 'nosuchfield'. +file:127:49-52: error: Type mismatch; expected group. +file:125:52-55: error: Missing field name. +file:136:3-10: error: 'dupName' is already defined in this scope. +file:135:3-10: error: 'dupName' previously defined here. +file:138:15-16: error: Duplicate ordinal number. +file:137:15-16: error: Ordinal @2 originally used here. +file:141:7-16: error: Declaration recursively depends on itself. +file:147:14-27: error: Not enough generic parameters. +file:148:15-47: error: Too many generic parameters. +file:149:18-49: error: Double-application of generic parameters. +file:150:38-43: error: Sorry, only pointer types can be used as generic parameters. +file:153:30-44: error: Embeds can only be used when Text, Data, or a struct is expected. +file:154:37-51: error: Couldn't read file for embed: no-such-file +file:160:23-27: error: Only pointer parameters can declare their default as 'null'. +file:156:20-45: error: Import failed: nosuchfile-unused.capnp diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/flat b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/flat new file mode 100644 index 0000000000000000000000000000000000000000..427fc31bcd157175204f62674277b46d9e518b2b GIT binary patch literal 2808 zcmds&Ur1AN6vxkWS&HkAuIPW8=7SmHpCql9^$#>me6W{5?5dmphIhN$&20o*hW)W9 z1(Oo7dI`i#kfet)ETUCJ!Lqkly#!@FNCf?r+xOhv#rDvHK7{PRxu4(popUa~vz_z1 zL_{fMBwbhV<@nG(<+SOG_s&H{nW6S^V{6)rP}-JH=Z9-XsCr=k62#KocT=6`CY~O` zG7HLF53Pjqd%BW|3a~x_nl)x<%+zSqxEkbm_A}YfOxI}8xD`B${T%QTxEUPQ_yFuk zB3gyRaeh>6qNpzG1xcmuYrwF4W#z9b*N4&@#Y9Iaq&J?aPY$Jt8Rm7*^>vQaF}x-s zJ+kFr_2uY@)*{Lb=4#~Mf$eOKd|r;@^A>{aXR@Ek{u0f<2iyU>0xSV*L9WlKu?yt- zUPCuvKPvTtPhC1?PjqWuP>Gd2FOHkcxzDP-c-v?lY$xY19T$YO=y^k_6fAj*pAx zWwBq79Cj~yU$8gwB-^A&H}KuCkUrgnIr1SlQDhQ@BvL)Ki@Y9>$>o;h2DiP%evB zFTMqxgQLvD*Ka*$2Awx2#x55P(BS9+j6Lp(0A_Xy#8bF$VG_-%HV7ZfcYo|0M(2^| z%wd@LVqDdg7;&D8}Y?kF_zCEKAkrA9dCO;{X5v literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/lists.binary b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/lists.binary new file mode 100644 index 0000000000000000000000000000000000000000..30ae630c0f45e88df949a57ef5f260cee53109c3 GIT binary patch literal 1096 zcmZQzU|{F~VhG@3Pz5sBffz)q1Fvp$^mr`BLgc?jS>*U=(PNNkT!;-#3C@w2_$8J7-X0Tl;#1_ zAU7}pF*6W@01FU<%=qNL2gGFn=>z#&6o~nNSQ5&I*#o1|?E{$$a!*oX6_7-@3#8r% zhzm)n}QR(sQZP($37r1oL!4K!2~>`NeabuYeLyxZMwZX>wM zuosI`FewqMFM*f|lJudB711h0VcEAZzXWALBLeNkPG?ghz3_Vu|NnCyc>d>>Hp6dD}wXgz) z-(%Vx*)_j_vo83t{H|l|WKyob*h1lC7Oyk!nw0}%vtK0<>y7cq9ToSUb;g2&yUAupjodtnshGBfGY6eVvF zHU&e1*ct*(u00qs*|r+?t%f6qf=Z~S_yO8id~*ROI&Uc}22cHvB?8Zj$Hh*%;_AVL z#=gN6#V^ujJtGtJi97dS;6&iw^yCfuFqj*eI2My;V>m9Q;_MSwJSD|bIKC=nb|aXf#5H+C(?W!>Erl+De+|{Xy&rx3MDmp8&cg!Q1L6t+4+K*O3mFE=?UI U+Hq)$ literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packedflat b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/packedflat new file mode 100644 index 0000000000000000000000000000000000000000..7c304a9e5224fc543bdc3ae04427c82954fec965 GIT binary patch literal 828 zcmZ9JZAep57{|}q-Al8r>)n}QR(sQZP($37r1oL!4K!2~>`NeabuYdQ?{>GF+X(K> zuosI`FewqMFM*f|lJudB711h0VcEAZzXWALBLeNkPG?ghz3_Vu|NnCyc>d?sEA<%m zCg!I`k6`M8>09*SHH?=**Oa~^Yc82({Cs7saokWpd{pu0(NetU^7JdF*22{0HPk5e zsFx~5XDKs5M?eHUA&2-n0wQP#T0#N3L|M^w%7DfwgX1aHEkld~0ig17oT`Q8G5juR zcVyT60?xY7$MU<5wUbG?{$dM-lUbb3ylYktjLiY{q-?2QaQ(M|73Lx{EF@S6`Gf*w zg;r!E+D5dE=rW=Y!TqQjmZ2tSKtX75^g^=1TiI^1K?@sG1%(JuFtwEcG*l_|AlupH z357lGw8sM-<~^+6A2oFWW5$Mgv}REfzb56$PZAba>e$DwH@APTN*H6&8GWxkUlqV5 z0$S@ETEjp}+nG-U+cg$EpOlyE#5g?_-`A{2rCS?AVzTdxOlX$@us%R4NR>Yrs>aV| zQfCOi;qsnsGC~iz;#%xJXV$$tEHCWOfBoU*X>sGk11t3hMk8LZaY~H3h*8@abtN4X zgov?~<9!~dk7oscIOCJ9#pz@DfIn*NX8mrC_VONggND3>0_}w{kju=ZOH+)zMZ^>e z^FnJFIQ{LRu*tU7ux~XSITTbvHN_3kzT%q;IMI1aSuuF(hb$3%UOX;z(iK+^E;RNH zrYLTaF6$YYpikVn{{kn1_ogRr*oVQ~$iy*8oRx4~OvTwJu6Rm}r*M2#%Mx!gFIoTq literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json new file mode 100644 index 0000000..abf82d6 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.json @@ -0,0 +1,88 @@ +{ "voidField": null, + "boolField": true, + "int8Field": -123, + "int16Field": -12345, + "int32Field": -12345678, + "int64Field": "-123456789012345", + "uInt8Field": 234, + "uInt16Field": 45678, + "uInt32Field": 3456789012, + "uInt64Field": "12345678901234567890", + "float32Field": 1234.5, + "float64Field": -1.23e47, + "textField": "foo", + "dataField": [98, 97, 114], + "structField": { + "voidField": null, + "boolField": true, + "int8Field": -12, + "int16Field": 3456, + "int32Field": -78901234, + "int64Field": "56789012345678", + "uInt8Field": 90, + "uInt16Field": 1234, + "uInt32Field": 56789012, + "uInt64Field": "345678901234567890", + "float32Field": -1.2499999646475857e-10, + "float64Field": 345, + "textField": "baz", + "dataField": [113, 117, 120], + "structField": { + "voidField": null, + "boolField": false, + "int8Field": 0, + "int16Field": 0, + "int32Field": 0, + "int64Field": "0", + "uInt8Field": 0, + "uInt16Field": 0, + "uInt32Field": 0, + "uInt64Field": "0", + "float32Field": 0, + "float64Field": 0, + "textField": "nested", + "structField": {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "really nested", "enumField": "foo", "interfaceField": null}, + "enumField": "foo", + "interfaceField": null }, + "enumField": "baz", + "interfaceField": null, + "voidList": [null, null, null], + "boolList": [false, true, false, true, true], + "int8List": [12, -34, -128, 127], + "int16List": [1234, -5678, -32768, 32767], + "int32List": [12345678, -90123456, -2147483648, 2147483647], + "int64List": ["123456789012345", "-678901234567890", "-9223372036854775808", "9223372036854775807"], + "uInt8List": [12, 34, 0, 255], + "uInt16List": [1234, 5678, 0, 65535], + "uInt32List": [12345678, 90123456, 0, 4294967295], + "uInt64List": ["123456789012345", "678901234567890", "0", "18446744073709551615"], + "float32List": [0, 1234567, 9.9999999338158125e36, -9.9999999338158125e36, 9.99999991097579e-38, -9.99999991097579e-38], + "float64List": [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306], + "textList": ["quux", "corge", "grault"], + "dataList": [[103, 97, 114, 112, 108, 121], [119, 97, 108, 100, 111], [102, 114, 101, 100]], + "structList": [ + {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "x structlist 1", "enumField": "foo", "interfaceField": null}, + {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "x structlist 2", "enumField": "foo", "interfaceField": null}, + {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "x structlist 3", "enumField": "foo", "interfaceField": null} ], + "enumList": ["qux", "bar", "grault"] }, + "enumField": "corge", + "interfaceField": null, + "voidList": [null, null, null, null, null, null], + "boolList": [true, false, false, true], + "int8List": [111, -111], + "int16List": [11111, -11111], + "int32List": [111111111, -111111111], + "int64List": ["1111111111111111111", "-1111111111111111111"], + "uInt8List": [111, 222], + "uInt16List": [33333, 44444], + "uInt32List": [3333333333], + "uInt64List": ["11111111111111111111"], + "float32List": [5555.5, "Infinity", "-Infinity", "NaN"], + "float64List": [7777.75, "Infinity", "-Infinity", "NaN"], + "textList": ["plugh", "xyzzy", "thud"], + "dataList": [[111, 111, 112, 115], [101, 120, 104, 97, 117, 115, 116, 101, 100], [114, 102, 99, 51, 48, 57, 50]], + "structList": [ + {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "structlist 1", "enumField": "foo", "interfaceField": null}, + {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "structlist 2", "enumField": "foo", "interfaceField": null}, + {"voidField": null, "boolField": false, "int8Field": 0, "int16Field": 0, "int32Field": 0, "int64Field": "0", "uInt8Field": 0, "uInt16Field": 0, "uInt32Field": 0, "uInt64Field": "0", "float32Field": 0, "float64Field": 0, "textField": "structlist 3", "enumField": "foo", "interfaceField": null} ], + "enumList": ["foo", "garply"] } diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt new file mode 100644 index 0000000..079ff8d --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/pretty.txt @@ -0,0 +1,187 @@ +( voidField = void, + boolField = true, + int8Field = -123, + int16Field = -12345, + int32Field = -12345678, + int64Field = -123456789012345, + uInt8Field = 234, + uInt16Field = 45678, + uInt32Field = 3456789012, + uInt64Field = 12345678901234567890, + float32Field = 1234.5, + float64Field = -1.23e47, + textField = "foo", + dataField = "bar", + structField = ( + voidField = void, + boolField = true, + int8Field = -12, + int16Field = 3456, + int32Field = -78901234, + int64Field = 56789012345678, + uInt8Field = 90, + uInt16Field = 1234, + uInt32Field = 56789012, + uInt64Field = 345678901234567890, + float32Field = -1.25e-10, + float64Field = 345, + textField = "baz", + dataField = "qux", + structField = ( + voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "nested", + structField = ( + voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "really nested", + enumField = foo, + interfaceField = void ), + enumField = foo, + interfaceField = void ), + enumField = baz, + interfaceField = void, + voidList = [void, void, void], + boolList = [false, true, false, true, true], + int8List = [12, -34, -128, 127], + int16List = [1234, -5678, -32768, 32767], + int32List = [12345678, -90123456, -2147483648, 2147483647], + int64List = [123456789012345, -678901234567890, -9223372036854775808, 9223372036854775807], + uInt8List = [12, 34, 0, 255], + uInt16List = [1234, 5678, 0, 65535], + uInt32List = [12345678, 90123456, 0, 4294967295], + uInt64List = [123456789012345, 678901234567890, 0, 18446744073709551615], + float32List = [0, 1234567, 1e37, -1e37, 1e-37, -1e-37], + float64List = [0, 123456789012345, 1e306, -1e306, 1e-306, -1e-306], + textList = ["quux", "corge", "grault"], + dataList = ["garply", "waldo", "fred"], + structList = [ + ( voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "x structlist 1", + enumField = foo, + interfaceField = void ), + ( voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "x structlist 2", + enumField = foo, + interfaceField = void ), + ( voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "x structlist 3", + enumField = foo, + interfaceField = void ) ], + enumList = [qux, bar, grault] ), + enumField = corge, + interfaceField = void, + voidList = [void, void, void, void, void, void], + boolList = [true, false, false, true], + int8List = [111, -111], + int16List = [11111, -11111], + int32List = [111111111, -111111111], + int64List = [1111111111111111111, -1111111111111111111], + uInt8List = [111, 222], + uInt16List = [33333, 44444], + uInt32List = [3333333333], + uInt64List = [11111111111111111111], + float32List = [5555.5, inf, -inf, nan], + float64List = [7777.75, inf, -inf, nan], + textList = ["plugh", "xyzzy", "thud"], + dataList = ["oops", "exhausted", "rfc3092"], + structList = [ + ( voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "structlist 1", + enumField = foo, + interfaceField = void ), + ( voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "structlist 2", + enumField = foo, + interfaceField = void ), + ( voidField = void, + boolField = false, + int8Field = 0, + int16Field = 0, + int32Field = 0, + int64Field = 0, + uInt8Field = 0, + uInt16Field = 0, + uInt32Field = 0, + uInt64Field = 0, + float32Field = 0, + float64Field = 0, + textField = "structlist 3", + enumField = foo, + interfaceField = void ) ], + enumList = [foo, garply] ) diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented new file mode 100644 index 0000000000000000000000000000000000000000..c2840b426768c0d27fffbed324b0c4893c64c48b GIT binary patch literal 5520 zcmeI0X>3$g6vtl|E7TUS)CEPE7E!TSu@z}u;sj6uu~aQCxRlp2Gc6rE>$B6^q>~!d zRHKj(qJ*G+F)@fFMB)dRG{#spMw5|`ruxN1(GQI=aV5|5d+)sFF^Q=&CfXEFa^C;m z|2_AfbMD-&9X1T3MD!xXQXkI5(T;t-GM;}NukP8E|IPL?wX0C1?v0g?j6GBPR|V_I{_^XE+Ie#@Q_TMMd>_<{&51c37A@I5@%gbs>+PokKMub2yltN}`j6G_ zs{AZhx$OIAU+Xw*v>(`Tme?6@e?30>%<+%uM@%3*c)Q|8#m$Oa6x$Tr74KH;P`p?1 ze#PyI4=FyP7*_0898`Q<(35a1<`n&NRWD4JnVjaCdwxHD|B|1w)e9DF`MoXmZOg08 zhOynqmDfJqRhFxa)zmHdw7fGu|0rWQvd0RN?>tekQn5yHvEq4(7bq@KyjbxP#bt_h zipv#OC|;qsQt?{FR>cj9w+VXEWezz-Vm@1xJjp*{W#sGb%lU#{{tj8dhrFwO_SDby z)&J{ae<+m>?R4|3l3>X5h9ZI@uSG@l`?tCzLuNEO81T|{&fA6JoP1g7{Qe6>kqV>M zsh{IkojPk5!Tv%~_5wn`T2Xk`UDafEM8M(C7lda$<;rv48CiP-d-}t(e%s7MPP{2^G|EboBKDt|L)YV=pQGS&MOri z#qM&oyAC6j;N-v)bv0kETe)ZXC*OSZ*odON_viMthcaP9F-!j|Me(ynl=Zesu~Big zV8U`YF7^$g*k2{u9ZN<+g78<1!Z(RVlBN|+yZklEv;MK8A9l_mVkYBJ zIaslm<8XT10W-RjlNFwLy*R>2cALwuRlZ*9#N+v6FR~5`72> zI$yrjInT*|Kq_TYVh_UKsyy#Z>hK8XuK&L0Uf~UhV7Ez>@#;ild*vene}^c1jcBCd z#S;P!f2SZk@7;;MmnvHK?f4b@t;%!CPb5BQIBfMTY<=#=6CGpwrf9!Q+j$?yCgmdn ze~+l=XU*urBObp^dHig9<&6(L{yycoQzjCxA3yp+(*eeLKzZkVdhm!$2XB|GydTD$ zcg2I+&i#&zo9_jkf-xm_$duS3zc}^}ONqEvh%%R^Vz(mqZ#-&6dIa&mLlk@Nz0Bay zkX)k<-{s@eJ=XMnNdbHAW%_q&-MgQArHqSGE9@BE4zEX4B zcL~zISu`2$ZeHEmxz}i-jBro? E3Es02*Z=?k literal 0 HcmV?d00001 diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented-packed b/CapnpC.CSharp.Generator.Tests/No Resources/testdata/segmented-packed new file mode 100644 index 0000000000000000000000000000000000000000..c4a968e2654e699e0dce86ece395e1b3fe783139 GIT binary patch literal 1352 zcmZvcdu&rx9LLZ3wfl{YjqclZxD8zQ0Cf!K9!xgWbm1i+ZbOF;e2i}Ex<_5NuGh75 zNt+qeOe2sGqJ*ISV`30Vh{Qj9q%p>+A&^x5G?RZ!6isZ53HX@T-@R>cL~hRg-E)4A z?>YB#&b^q`sMH{7mC$50Ygh>)yJbUSW$3iiZuA`>203z7Qg~Cp89#_vzO%{c&Yjw3I$o~+E&kDA)4Zz2&v`}*FQyB< zKfm@~@9CJ@Ppu8;632I;4W|v_z`d~_%ZMk-~-^N!Owz+ zz~kUJ_ywi%hr(fd$+h|Y{)k0GSDO0wWbvw!y?-fR*VK>g@3t--NIN~R^gGOSVc1<$ zalxs)eG>&|>B7oa1FQ)ydHcfxE|aL?f`EG@07Xw z{WG9^=-T{ABL*svxs|*|u~J~D65n`WDjFCB6+v&Y0wv0AMgsm&C|*6Tyt$wYTGqX) zhdrQ`Vs#;OxfYxr=z3StVln|*Epz;ucBX$ynldVfuDjOd|D^NVxBtAJG)>DV$7G!^ z{(bRFyC%#=qjYKh_>!rTR?xl@3bYn_{mP_q-0+ad#s&! zK$U|#EwfFzRfQR=o{C0{fvEC@My8_G&7k|CXZ{~(0r_qjXa#MR0BB3Io~AN~mXB}; z^cwjZb9>sP3qZS}YaHRDpogH{u3*EPmq8ChmzoP>Z*j-5gMSFzZfK9WF!@EpX=BW# zJ6^x%?1v|nmn```KCOVH!cMN;^J1RD=oRB(0dY*p@G(>4nY>Ow=B4f xf5bv>SSDuk&(aT#C|8#LB=o4zzsW5^(ObBM{Is}1VT-&oA2cIS Generate() diff --git a/CapnpC.CSharp.Generator/Model/GenFile.cs b/CapnpC.CSharp.Generator/Model/GenFile.cs index ac0c35d..468315e 100644 --- a/CapnpC.CSharp.Generator/Model/GenFile.cs +++ b/CapnpC.CSharp.Generator/Model/GenFile.cs @@ -14,6 +14,7 @@ namespace CapnpC.CSharp.Generator.Model public bool? NullableEnable { get; set; } public bool EmitNullableDirective { get; set; } public bool EmitDomainClassesAndInterfaces { get; set; } + public string HeaderText { get; set; } public SupportedAnnotations.TypeVisibility TypeVisibility { get; set; } public IEnumerable NestedTypes { get => this.GetNestedTypes(); } diff --git a/CapnpC.CSharp.Generator/Model/SchemaModel.cs b/CapnpC.CSharp.Generator/Model/SchemaModel.cs index 8213ffd..2b75e7c 100644 --- a/CapnpC.CSharp.Generator/Model/SchemaModel.cs +++ b/CapnpC.CSharp.Generator/Model/SchemaModel.cs @@ -13,6 +13,7 @@ namespace CapnpC.CSharp.Generator.Model readonly DefinitionManager _typeDefMgr = new DefinitionManager(); readonly Dictionary _id2node = new Dictionary(); + readonly Dictionary _id2sourceInfo = new Dictionary(); public SchemaModel(Schema.CodeGeneratorRequest.Reader request) { @@ -51,6 +52,17 @@ namespace CapnpC.CSharp.Generator.Model _id2node[node.Id] = node; } + foreach (var reader in _request.SourceInfo) + { + var sourceInfo = new SourceInfo() + { + DocComment = reader.DocComment, + MemberDocComments = reader.Members.Select(m => m.DocComment).ToList() + }; + + _id2sourceInfo.Add(reader.Id, sourceInfo); + } + var requestedFiles = _request.RequestedFiles.ToDictionary(req => req.Id); BuildPass1(requestedFiles); BuildPass2(requestedFiles); @@ -96,6 +108,10 @@ namespace CapnpC.CSharp.Generator.Model file.EmitNullableDirective = GetEmitNullableDirective(node) ?? false; file.EmitDomainClassesAndInterfaces = GetEmitDomainClassesAndInterfaces(node) ?? true; file.TypeVisibility = GetTypeVisibility(node) ?? TypeVisibility.Public; + if (_id2sourceInfo.TryGetValue(node.Id, out var sourceInfo)) + { + file.HeaderText = GetHeaderText(sourceInfo); + } return ProcessNodePass1(id, name, state) as GenFile; } diff --git a/CapnpC.CSharp.Generator/Model/SourceInfo.cs b/CapnpC.CSharp.Generator/Model/SourceInfo.cs new file mode 100644 index 0000000..28ac508 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/SourceInfo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CapnpC.CSharp.Generator.Model +{ + class SourceInfo + { + public string DocComment { get; set; } + public IReadOnlyList MemberDocComments { get; set; } + } +} diff --git a/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs b/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs index cd78387..5985170 100644 --- a/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs +++ b/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace CapnpC.CSharp.Generator.Model @@ -130,5 +131,19 @@ namespace CapnpC.CSharp.Generator.Model } return null; } + + public static string GetHeaderText(SourceInfo sourceInfo) + { + if (sourceInfo.DocComment == null) + return null; + + var lines = sourceInfo.DocComment + .Split('\n') + .Select(line => line.Trim()) + .SkipWhile(line => !line.Equals("$$embed", StringComparison.OrdinalIgnoreCase)) + .Skip(1); + + return string.Join(Environment.NewLine, lines); + } } } diff --git a/include/capnp/c++.capnp b/include/capnp/c++.capnp new file mode 100644 index 0000000..2bda547 --- /dev/null +++ b/include/capnp/c++.capnp @@ -0,0 +1,26 @@ +# Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors +# Licensed under the MIT License: +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +@0xbdf87d7bb8304e81; +$namespace("capnp::annotations"); + +annotation namespace(file): Text; +annotation name(field, enumerant, struct, enum, interface, method, param, group, union): Text; diff --git a/scripts/regen-capnpbin.bat b/scripts/regen-capnpbin.bat new file mode 100644 index 0000000..aa4d9bb --- /dev/null +++ b/scripts/regen-capnpbin.bat @@ -0,0 +1,3 @@ +@echo off +cd "%~dp0\..\CapnpC.CSharp.Generator.Tests\No Resources" +for /f %%f in ('dir /b "*.capnp"') do capnp compile -o- %%f -I"..\..\include" > "..\Embedded Resources\%%f.bin" \ No newline at end of file