feature: header text in generated files

fixed double-far encoding/decoding bug
This commit is contained in:
Christian Köllner 2020-04-18 15:06:52 +02:00
parent 75823c43b9
commit 62d5a7e9bd
36 changed files with 612 additions and 5 deletions

View File

@ -350,7 +350,7 @@ namespace Capnp
throw new DeserializationException("Error decoding double-far pointer: not followed by intra-segment pointer"); throw new DeserializationException("Error decoding double-far pointer: not followed by intra-segment pointer");
CurrentSegmentIndex = pointer1.TargetSegmentIndex; CurrentSegmentIndex = pointer1.TargetSegmentIndex;
Offset = 0; Offset = pointer1.LandingPadOffset;
pointer = pointer2; pointer = pointer2;
offset = -1; offset = -1;
} }

View File

@ -1,3 +1,4 @@
#pragma warning disable CS1591
using Capnp; using Capnp;
using Capnp.Rpc; using Capnp.Rpc;
using System; using System;

View File

@ -375,7 +375,7 @@ namespace Capnp
farPtr2.SetFarPointer(target.SegmentIndex, target.Offset, false); farPtr2.SetFarPointer(target.SegmentIndex, target.Offset, false);
var farSpan = FarSpan(landingPadSlice.SegmentIndex); var farSpan = FarSpan(landingPadSlice.SegmentIndex);
farSpan[landingPadSlice.Offset] = farPtr2; farSpan[landingPadSlice.Offset] = farPtr2;
targetPtr.Offset = target.Offset; targetPtr.Offset = 0;
farSpan[landingPadSlice.Offset + 1] = targetPtr; farSpan[landingPadSlice.Offset + 1] = targetPtr;
} }
} }

View File

@ -30,6 +30,10 @@
<EmbeddedResource Include="Embedded Resources\*" /> <EmbeddedResource Include="Embedded Resources\*" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="No Resources\UnitTest1.capnp" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CapnpC.CSharp.Generator\CapnpC.CSharp.Generator.csproj" /> <ProjectReference Include="..\CapnpC.CSharp.Generator\CapnpC.CSharp.Generator.csproj" />
</ItemGroup> </ItemGroup>

Binary file not shown.

View File

@ -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 # This is a modified version of rpc.capnp, found in the original distribution
# Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors # Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
# Licensed under the MIT License: # 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 # 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 # bother implementing any other vat network protocol -- just use the correct container type and get
# it for free. # it for free.
# $$embed
# #pragma warning disable CS1591
using CSharp = import "/csharp.capnp"; using CSharp = import "/csharp.capnp";
$CSharp.namespace("Capnp.Rpc"); $CSharp.namespace("Capnp.Rpc");

View File

@ -21,7 +21,7 @@
@0xd508eebdc2dc42b8; @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 # Use a namespace likely to cause trouble if the generated code doesn't use fully-qualified
# names for stuff in the capnproto namespace. # names for stuff in the capnproto namespace.

View File

@ -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"} }

Binary file not shown.

View File

@ -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);
}

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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"] }

View File

@ -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] )

Binary file not shown.

View File

@ -0,0 +1 @@
{"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"]}

View File

@ -0,0 +1 @@
(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])

View File

@ -260,7 +260,14 @@
cu = cu.AddMembers(ns); cu = cu.AddMembers(ns);
return cu.NormalizeWhitespace(" ", Environment.NewLine).ToFullString(); string content = cu.NormalizeWhitespace(" ", Environment.NewLine).ToFullString();
if (!string.IsNullOrWhiteSpace(file.HeaderText))
{
content = file.HeaderText + content;
}
return content;
} }
public IReadOnlyList<FileGenerationResult> Generate() public IReadOnlyList<FileGenerationResult> Generate()

View File

@ -14,6 +14,7 @@ namespace CapnpC.CSharp.Generator.Model
public bool? NullableEnable { get; set; } public bool? NullableEnable { get; set; }
public bool EmitNullableDirective { get; set; } public bool EmitNullableDirective { get; set; }
public bool EmitDomainClassesAndInterfaces { get; set; } public bool EmitDomainClassesAndInterfaces { get; set; }
public string HeaderText { get; set; }
public SupportedAnnotations.TypeVisibility TypeVisibility { get; set; } public SupportedAnnotations.TypeVisibility TypeVisibility { get; set; }
public IEnumerable<TypeDefinition> NestedTypes { get => this.GetNestedTypes(); } public IEnumerable<TypeDefinition> NestedTypes { get => this.GetNestedTypes(); }

View File

@ -13,6 +13,7 @@ namespace CapnpC.CSharp.Generator.Model
readonly DefinitionManager _typeDefMgr = new DefinitionManager(); readonly DefinitionManager _typeDefMgr = new DefinitionManager();
readonly Dictionary<ulong, Schema.Node.Reader> _id2node = new Dictionary<ulong, Schema.Node.Reader>(); readonly Dictionary<ulong, Schema.Node.Reader> _id2node = new Dictionary<ulong, Schema.Node.Reader>();
readonly Dictionary<ulong, SourceInfo> _id2sourceInfo = new Dictionary<ulong, SourceInfo>();
public SchemaModel(Schema.CodeGeneratorRequest.Reader request) public SchemaModel(Schema.CodeGeneratorRequest.Reader request)
{ {
@ -51,6 +52,17 @@ namespace CapnpC.CSharp.Generator.Model
_id2node[node.Id] = node; _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); var requestedFiles = _request.RequestedFiles.ToDictionary(req => req.Id);
BuildPass1(requestedFiles); BuildPass1(requestedFiles);
BuildPass2(requestedFiles); BuildPass2(requestedFiles);
@ -96,6 +108,10 @@ namespace CapnpC.CSharp.Generator.Model
file.EmitNullableDirective = GetEmitNullableDirective(node) ?? false; file.EmitNullableDirective = GetEmitNullableDirective(node) ?? false;
file.EmitDomainClassesAndInterfaces = GetEmitDomainClassesAndInterfaces(node) ?? true; file.EmitDomainClassesAndInterfaces = GetEmitDomainClassesAndInterfaces(node) ?? true;
file.TypeVisibility = GetTypeVisibility(node) ?? TypeVisibility.Public; 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; return ProcessNodePass1(id, name, state) as GenFile;
} }

View File

@ -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<string> MemberDocComments { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
namespace CapnpC.CSharp.Generator.Model namespace CapnpC.CSharp.Generator.Model
@ -130,5 +131,19 @@ namespace CapnpC.CSharp.Generator.Model
} }
return null; 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);
}
} }
} }

26
include/capnp/c++.capnp Normal file
View File

@ -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;

View File

@ -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"