diff --git a/Capnp.Net.Runtime/AnyPointer.cs b/Capnp.Net.Runtime/AnyPointer.cs index 02a5efc..95ee638 100644 --- a/Capnp.Net.Runtime/AnyPointer.cs +++ b/Capnp.Net.Runtime/AnyPointer.cs @@ -28,4 +28,4 @@ Reserializing.DeepCopy(State, state); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj b/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj index 6b5d624..3e741a9 100644 --- a/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj +++ b/Capnp.Net.Runtime/Capnp.Net.Runtime.csproj @@ -1,9 +1,11 @@  - netstandard2.0;netcoreapp2.1 + netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp3.0 Capnp - 7.2 + 8.0 + Enable + CS8600;CS8602;CS8603 Capnp.Net.Runtime Capnp.Net.Runtime true diff --git a/Capnp.Net.Runtime/CapnpSerializable.cs b/Capnp.Net.Runtime/CapnpSerializable.cs index 054d5b5..81b86b6 100644 --- a/Capnp.Net.Runtime/CapnpSerializable.cs +++ b/Capnp.Net.Runtime/CapnpSerializable.cs @@ -10,15 +10,15 @@ namespace Capnp /// public static class CapnpSerializable { - interface IConstructibleFromDeserializerState + interface IConstructibleFromDeserializerState { - T Create(DeserializerState state); + object? Create(DeserializerState state); } - class FromStruct: IConstructibleFromDeserializerState + class FromStruct: IConstructibleFromDeserializerState where T : ICapnpSerializable, new() { - public T Create(DeserializerState state) + public object Create(DeserializerState state) { var result = new T(); if (state.Kind != ObjectKind.Nil) @@ -29,7 +29,7 @@ namespace Capnp } } - class FromList: IConstructibleFromDeserializerState> + class FromList: IConstructibleFromDeserializerState where T: class { readonly Func _elementSerializer; @@ -39,23 +39,23 @@ namespace Capnp _elementSerializer = (Func)GetSerializer(typeof(T)); } - public IReadOnlyList Create(DeserializerState state) + public object Create(DeserializerState state) { return state.RequireList().Cast(_elementSerializer); } } - class FromCapability: IConstructibleFromDeserializerState + class FromCapability: IConstructibleFromDeserializerState where T: class { - public T Create(DeserializerState state) + public object? Create(DeserializerState state) { return state.RequireCap(); } } - static readonly ConditionalWeakTable> _typeMap = - new ConditionalWeakTable>(); + static readonly ConditionalWeakTable> _typeMap = + new ConditionalWeakTable>(); static CapnpSerializable() { @@ -73,14 +73,14 @@ namespace Capnp _typeMap.Add(typeof(IReadOnlyList), d => d.RequireList().CastDouble()); } - static Func CreateSerializer(Type type) + static Func CreateSerializer(Type type) { if (typeof(ICapnpSerializable).IsAssignableFrom(type)) { try { - return ((IConstructibleFromDeserializerState) - Activator.CreateInstance(typeof(FromStruct<>).MakeGenericType(type))).Create; + return ((IConstructibleFromDeserializerState) + Activator.CreateInstance(typeof(FromStruct<>).MakeGenericType(type))!).Create; } catch (Exception ex) { @@ -94,12 +94,12 @@ namespace Capnp try { var elementType = type.GetGenericArguments()[0]; - return ((IConstructibleFromDeserializerState) - Activator.CreateInstance(typeof(FromList<>).MakeGenericType(elementType))).Create; + return ((IConstructibleFromDeserializerState) + Activator.CreateInstance(typeof(FromList<>).MakeGenericType(elementType))!).Create; } catch (TargetInvocationException ex) { - throw ex.InnerException; + throw ex.InnerException!; } catch (Exception ex) { @@ -123,8 +123,8 @@ namespace Capnp try { - return ((IConstructibleFromDeserializerState) - Activator.CreateInstance(typeof(FromCapability<>).MakeGenericType(type))).Create; + return ((IConstructibleFromDeserializerState) + Activator.CreateInstance(typeof(FromCapability<>).MakeGenericType(type))!).Create; } catch (Exception ex) { @@ -135,7 +135,7 @@ namespace Capnp } } - static Func GetSerializer(Type type) + static Func GetSerializer(Type type) { return _typeMap.GetValue(type, CreateSerializer); } @@ -148,26 +148,28 @@ namespace Capnp /// Type implementing . The type must must have a public parameterless constructor. /// A capability interface ( for further explanation) /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// whereby T is one of the things listed here. + /// IReadOnlyList{Boolean} + /// IReadOnlyList{SByte}" + /// IReadOnlyList{Byte}" + /// IReadOnlyList{Int16}" + /// IReadOnlyList{UInt16}" + /// IReadOnlyList{Int32}" + /// IReadOnlyList{UInt32}" + /// IReadOnlyList{Int64}" + /// IReadOnlyList{UInt64}" + /// IReadOnlyList{Single}" + /// IReadOnlyList{Double}" + /// IReadOnlyList{T} whereby T is one of the things listed here. /// /// - /// - /// - public static T Create(DeserializerState state) + /// deserializer state to construct from + /// The domain object instance. Nullability note: The returned reference will be null if (and only if) is a capability interface and + /// represents the nil object (obtained from a null pointer). For all other types, when the state is nil, + /// the method still constructs a valid but "empty" object instance (such as domain object without any properties set, empty string, empty list etc.) + public static T? Create(DeserializerState state) where T: class { - return (T)GetSerializer(typeof(T))(state); + return (T?)GetSerializer(typeof(T))(state); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/DeserializationException.cs b/Capnp.Net.Runtime/DeserializationException.cs index a9dfcaa..6275002 100644 --- a/Capnp.Net.Runtime/DeserializationException.cs +++ b/Capnp.Net.Runtime/DeserializationException.cs @@ -22,4 +22,4 @@ namespace Capnp { } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/DeserializerState.cs b/Capnp.Net.Runtime/DeserializerState.cs index 830ff83..8dd7ce8 100644 --- a/Capnp.Net.Runtime/DeserializerState.cs +++ b/Capnp.Net.Runtime/DeserializerState.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Capnp { @@ -47,7 +48,7 @@ namespace Capnp /// /// The capabilities imported from the capability table. Only valid in RPC context. /// - public IList Caps { get; set; } + public IList? Caps { get; set; } /// /// Current segment (essentially Segments[CurrentSegmentIndex] /// @@ -83,10 +84,15 @@ namespace Capnp /// The conversion is cheap, since it does not involve copying any payload. /// /// The serializer state to be converted + /// is null + /// is not bound to a MessageBuilder public static implicit operator DeserializerState(SerializerState state) { if (state == null) throw new ArgumentNullException(nameof(state)); + + if (state.MsgBuilder == null) + throw new InvalidOperationException("state is not bound to a MessageBuilder"); switch (state.Kind) { @@ -100,7 +106,7 @@ namespace Capnp case ObjectKind.ListOfStructs: case ObjectKind.Nil: case ObjectKind.Struct: - return new DeserializerState(state.Allocator.Segments) + return new DeserializerState(state.Allocator!.Segments) { CurrentSegmentIndex = state.SegmentIndex, Offset = state.Offset, @@ -112,7 +118,7 @@ namespace Capnp }; case ObjectKind.Capability: - return new DeserializerState(state.Allocator.Segments) + return new DeserializerState(state.Allocator!.Segments) { Kind = ObjectKind.Capability, Caps = state.Caps, @@ -376,11 +382,11 @@ namespace Capnp /// the capability table. Does not mutate this state. /// /// Offset relative to this.Offset within current segment - /// the low-level capability object + /// the low-level capability object, or null if it is a null pointer /// offset negative or out of range /// capability table not set /// not a capability pointer or invalid capability index - internal Rpc.ConsumedCapability DecodeCapPointer(int offset) + internal Rpc.ConsumedCapability? DecodeCapPointer(int offset) { if (offset < 0) { @@ -490,7 +496,7 @@ namespace Capnp return state; } - internal Rpc.ConsumedCapability StructReadRawCap(int index) + internal Rpc.ConsumedCapability? StructReadRawCap(int index) { if (Kind != ObjectKind.Struct && Kind != ObjectKind.Nil) throw new InvalidOperationException("Allowed on structs only"); @@ -567,7 +573,8 @@ namespace Capnp /// negative index /// state does not represent a struct, invalid pointer, /// non-list-of-bytes pointer, traversal limit exceeded - public string ReadText(int index, string defaultText = null) + [return: NotNullIfNotNull("defaultText")] + public string? ReadText(int index, string? defaultText = null) { return StructReadPointer(index).RequireList().CastText() ?? defaultText; } @@ -646,7 +653,7 @@ namespace Capnp /// negative index /// state does not represent a struct, invalid pointer, /// non-capability pointer, traversal limit exceeded - public T ReadCap(int index, + public T? ReadCap(int index, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) where T: class @@ -677,7 +684,7 @@ namespace Capnp /// capability instance or null if pointer was null /// negative index /// state does not represent a capability - public T RequireCap() where T: class + public T? RequireCap() where T: class { if (Kind == ObjectKind.Nil) return null; @@ -685,7 +692,10 @@ namespace Capnp if (Kind != ObjectKind.Capability) throw new DeserializationException("Expected a capability"); - return Rpc.CapabilityReflection.CreateProxy(Caps[(int)CapabilityIndex]) as T; + if (Caps == null) + throw new InvalidOperationException("Capability table not set. This is a bug."); + + return (Rpc.CapabilityReflection.CreateProxy(Caps[(int)CapabilityIndex]) as T)!; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/DynamicSerializerState.cs b/Capnp.Net.Runtime/DynamicSerializerState.cs index 793c8f9..679a59f 100644 --- a/Capnp.Net.Runtime/DynamicSerializerState.cs +++ b/Capnp.Net.Runtime/DynamicSerializerState.cs @@ -144,7 +144,7 @@ namespace Capnp /// A ]]> whereby each list item is one of the things listed here. /// /// - public void SetObject(object obj) + public void SetObject(object? obj) { switch (obj) { @@ -225,4 +225,4 @@ namespace Capnp } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/EmptyList.cs b/Capnp.Net.Runtime/EmptyList.cs index 8db5d94..0c1ebc6 100644 --- a/Capnp.Net.Runtime/EmptyList.cs +++ b/Capnp.Net.Runtime/EmptyList.cs @@ -35,4 +35,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/EmptyListDeserializer.cs b/Capnp.Net.Runtime/EmptyListDeserializer.cs index ac7be4f..76ee7d1 100644 --- a/Capnp.Net.Runtime/EmptyListDeserializer.cs +++ b/Capnp.Net.Runtime/EmptyListDeserializer.cs @@ -85,4 +85,4 @@ namespace Capnp /// public override IReadOnlyList CastUShort() => new EmptyList(); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/FramePump.cs b/Capnp.Net.Runtime/FramePump.cs index fa841cc..0ff6791 100644 --- a/Capnp.Net.Runtime/FramePump.cs +++ b/Capnp.Net.Runtime/FramePump.cs @@ -2,9 +2,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -22,7 +20,7 @@ namespace Capnp int _disposing; readonly Stream _stream; - readonly BinaryWriter _writer; + readonly BinaryWriter? _writer; readonly object _writeLock = new object(); readonly List _tracers = new List(); @@ -62,7 +60,7 @@ namespace Capnp /// /// Event handler for frame reception. /// - public event Action FrameReceived; + public event Action? FrameReceived; /// /// Sends a message over the stream. @@ -195,4 +193,4 @@ namespace Capnp _tracers.Add(tracer); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/FrameTracing/RpcFrameTracer.cs b/Capnp.Net.Runtime/FrameTracing/RpcFrameTracer.cs index f2c3ca1..fdd4ac2 100644 --- a/Capnp.Net.Runtime/FrameTracing/RpcFrameTracer.cs +++ b/Capnp.Net.Runtime/FrameTracing/RpcFrameTracer.cs @@ -244,4 +244,4 @@ namespace Capnp.FrameTracing } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Framing.cs b/Capnp.Net.Runtime/Framing.cs index 8e39cc5..7d505ff 100644 --- a/Capnp.Net.Runtime/Framing.cs +++ b/Capnp.Net.Runtime/Framing.cs @@ -122,4 +122,4 @@ namespace Capnp } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ICapnpSerializable.cs b/Capnp.Net.Runtime/ICapnpSerializable.cs index 36eaeea..0a5adfd 100644 --- a/Capnp.Net.Runtime/ICapnpSerializable.cs +++ b/Capnp.Net.Runtime/ICapnpSerializable.cs @@ -18,4 +18,4 @@ /// Source deserializer state void Deserialize(DeserializerState state); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ISegmentAllocator.cs b/Capnp.Net.Runtime/ISegmentAllocator.cs index abcfb8d..80ddf0d 100644 --- a/Capnp.Net.Runtime/ISegmentAllocator.cs +++ b/Capnp.Net.Runtime/ISegmentAllocator.cs @@ -26,4 +26,4 @@ namespace Capnp /// Whether allocation was successful bool Allocate(uint nwords, uint preferredSegment, out SegmentSlice slice, bool forcePreferredSegment); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/IStructDeserializer.cs b/Capnp.Net.Runtime/IStructDeserializer.cs index 24cd8d3..a851ed0 100644 --- a/Capnp.Net.Runtime/IStructDeserializer.cs +++ b/Capnp.Net.Runtime/IStructDeserializer.cs @@ -19,4 +19,4 @@ namespace Capnp /// this state does not represent a struct ulong StructReadData(ulong bitOffset, int bitCount); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/IStructSerializer.cs b/Capnp.Net.Runtime/IStructSerializer.cs index 8678c33..83ebd30 100644 --- a/Capnp.Net.Runtime/IStructSerializer.cs +++ b/Capnp.Net.Runtime/IStructSerializer.cs @@ -24,4 +24,4 @@ namespace Capnp /// Span StructDataSection { get; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListDeserializer.cs b/Capnp.Net.Runtime/ListDeserializer.cs index cfe2acd..8db896b 100644 --- a/Capnp.Net.Runtime/ListDeserializer.cs +++ b/Capnp.Net.Runtime/ListDeserializer.cs @@ -10,7 +10,7 @@ namespace Capnp { static class GenericCasts { - public static Func CastFunc; + public static Func? CastFunc; } static ListDeserializer() @@ -400,4 +400,4 @@ namespace Capnp return Cast(sd => sd.ReadDataDouble(0)); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListKind.cs b/Capnp.Net.Runtime/ListKind.cs index 66d5492..9e39ec4 100644 --- a/Capnp.Net.Runtime/ListKind.cs +++ b/Capnp.Net.Runtime/ListKind.cs @@ -45,4 +45,4 @@ /// ListOfStructs = 7 } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfBitsDeserializer.cs b/Capnp.Net.Runtime/ListOfBitsDeserializer.cs index 7415ffb..0e5ff07 100644 --- a/Capnp.Net.Runtime/ListOfBitsDeserializer.cs +++ b/Capnp.Net.Runtime/ListOfBitsDeserializer.cs @@ -76,4 +76,4 @@ namespace Capnp throw new NotSupportedException("Cannot cast a list of bits to anything else"); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfBitsSerializer.cs b/Capnp.Net.Runtime/ListOfBitsSerializer.cs index cbbfe3d..6c00c7a 100644 --- a/Capnp.Net.Runtime/ListOfBitsSerializer.cs +++ b/Capnp.Net.Runtime/ListOfBitsSerializer.cs @@ -73,7 +73,7 @@ namespace Capnp /// List content. Can be null in which case the list is simply not initialized. /// The list was already initialized /// More than 2^29-1 items. - public void Init(IReadOnlyList items) + public void Init(IReadOnlyList? items) { if (items == null) { @@ -95,4 +95,4 @@ namespace Capnp IEnumerator IEnumerable.GetEnumerator() => this.ToArray().GetEnumerator(); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfCapsDeserializer.cs b/Capnp.Net.Runtime/ListOfCapsDeserializer.cs index c80eff3..22a9ac9 100644 --- a/Capnp.Net.Runtime/ListOfCapsDeserializer.cs +++ b/Capnp.Net.Runtime/ListOfCapsDeserializer.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Text; namespace Capnp { @@ -29,7 +28,7 @@ namespace Capnp if (index < 0 || index >= Count) throw new IndexOutOfRangeException(); - return Rpc.CapabilityReflection.CreateProxy(State.DecodeCapPointer(index)) as T; + return (Rpc.CapabilityReflection.CreateProxy(State.DecodeCapPointer(index)) as T)!; } } @@ -69,4 +68,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfCapsSerializer.cs b/Capnp.Net.Runtime/ListOfCapsSerializer.cs index 960a8e3..eef1d7c 100644 --- a/Capnp.Net.Runtime/ListOfCapsSerializer.cs +++ b/Capnp.Net.Runtime/ListOfCapsSerializer.cs @@ -1,7 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Text; +using System.Diagnostics.CodeAnalysis; namespace Capnp { @@ -11,7 +11,7 @@ namespace Capnp /// Capability interface public class ListOfCapsSerializer : SerializerState, - IReadOnlyList + IReadOnlyList where T : class { /// @@ -32,9 +32,10 @@ namespace Capnp /// Proxy object of capability at given element index /// List was not initialized, or attempting to overwrite an already set element. /// is out of range. + [AllowNull] public T this[int index] { - get => Rpc.CapabilityReflection.CreateProxy(DecodeCapPointer(index)) as T; + get => (Rpc.CapabilityReflection.CreateProxy(DecodeCapPointer(index)) as T)!; set { if (!IsAllocated) @@ -43,10 +44,7 @@ namespace Capnp if (index < 0 || index >= RawData.Length) throw new IndexOutOfRangeException("index out of range"); - uint id = ProvideCapability(value); - WirePointer ptr = default; - ptr.SetCapability(id); - RawData[index] = id; + RawData[index] = ProvideCapability(value); } } @@ -67,7 +65,7 @@ namespace Capnp /// List content. Can be null in which case the list is simply not initialized. /// The list was already initialized /// More than 2^29-1 items. - public void Init(IReadOnlyList caps) + public void Init(IReadOnlyList? caps) { if (caps == null) { @@ -108,4 +106,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfEmptyDeserializer.cs b/Capnp.Net.Runtime/ListOfEmptyDeserializer.cs index e8d1d2f..9b6ed42 100644 --- a/Capnp.Net.Runtime/ListOfEmptyDeserializer.cs +++ b/Capnp.Net.Runtime/ListOfEmptyDeserializer.cs @@ -63,4 +63,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfEmptySerializer.cs b/Capnp.Net.Runtime/ListOfEmptySerializer.cs index 7638b61..b6aa31f 100644 --- a/Capnp.Net.Runtime/ListOfEmptySerializer.cs +++ b/Capnp.Net.Runtime/ListOfEmptySerializer.cs @@ -30,4 +30,4 @@ namespace Capnp SetListOfValues(0, count); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfPointersDeserializer.cs b/Capnp.Net.Runtime/ListOfPointersDeserializer.cs index a3e679e..520e0e7 100644 --- a/Capnp.Net.Runtime/ListOfPointersDeserializer.cs +++ b/Capnp.Net.Runtime/ListOfPointersDeserializer.cs @@ -88,4 +88,4 @@ namespace Capnp return this.LazyListSelect(d => d.RequireCapList()); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfPointersSerializer.cs b/Capnp.Net.Runtime/ListOfPointersSerializer.cs index 15d9cdd..b6b42fe 100644 --- a/Capnp.Net.Runtime/ListOfPointersSerializer.cs +++ b/Capnp.Net.Runtime/ListOfPointersSerializer.cs @@ -1,8 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Capnp { @@ -12,7 +10,7 @@ namespace Capnp /// SerializerState which represents the element type public class ListOfPointersSerializer: SerializerState, - IReadOnlyList + IReadOnlyList where TS: SerializerState, new() { /// @@ -51,7 +49,7 @@ namespace Capnp /// public int Count => ListElementCount; - IEnumerable Enumerate() + IEnumerable Enumerate() { int count = Count; @@ -64,7 +62,7 @@ namespace Capnp /// /// Implements . /// - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { return Enumerate().GetEnumerator(); } @@ -94,7 +92,7 @@ namespace Capnp /// Serialization action to transfer a particular item into the serializer state. /// The list was already initialized /// More than 2^29-1 items. - public void Init(IReadOnlyList items, Action init) + public void Init(IReadOnlyList? items, Action init) { if (items == null) { @@ -114,5 +112,4 @@ namespace Capnp return GetEnumerator(); } } -} - +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfPrimitivesDeserializer.cs b/Capnp.Net.Runtime/ListOfPrimitivesDeserializer.cs index 2c9d887..1cb357a 100644 --- a/Capnp.Net.Runtime/ListOfPrimitivesDeserializer.cs +++ b/Capnp.Net.Runtime/ListOfPrimitivesDeserializer.cs @@ -231,4 +231,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfPrimitivesSerializer.cs b/Capnp.Net.Runtime/ListOfPrimitivesSerializer.cs index a558475..b70a3a9 100644 --- a/Capnp.Net.Runtime/ListOfPrimitivesSerializer.cs +++ b/Capnp.Net.Runtime/ListOfPrimitivesSerializer.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; namespace Capnp { @@ -70,7 +69,7 @@ namespace Capnp /// List content. Can be null in which case the list is simply not initialized. /// The list was already initialized /// More than 2^29-1 items. - public void Init(IReadOnlyList items) + public void Init(IReadOnlyList? items) { if (items == null) { @@ -93,4 +92,4 @@ namespace Capnp IEnumerator IEnumerable.GetEnumerator() => Data.ToArray().GetEnumerator(); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfStructsDeserializer.cs b/Capnp.Net.Runtime/ListOfStructsDeserializer.cs index 0b42b07..57794e3 100644 --- a/Capnp.Net.Runtime/ListOfStructsDeserializer.cs +++ b/Capnp.Net.Runtime/ListOfStructsDeserializer.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; namespace Capnp { @@ -78,4 +77,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfStructsSerializer.cs b/Capnp.Net.Runtime/ListOfStructsSerializer.cs index 6f25afb..e84441b 100644 --- a/Capnp.Net.Runtime/ListOfStructsSerializer.cs +++ b/Capnp.Net.Runtime/ListOfStructsSerializer.cs @@ -72,7 +72,7 @@ namespace Capnp /// Serialization action to transfer a particular item into the serializer state. /// The list was already initialized /// More than 2^29-1 items. - public void Init(IReadOnlyList items, Action init) + public void Init(IReadOnlyList? items, Action init) { if (items == null) { @@ -92,4 +92,4 @@ namespace Capnp return GetEnumerator(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ListOfTextSerializer.cs b/Capnp.Net.Runtime/ListOfTextSerializer.cs index b8e4da1..5bd63e7 100644 --- a/Capnp.Net.Runtime/ListOfTextSerializer.cs +++ b/Capnp.Net.Runtime/ListOfTextSerializer.cs @@ -9,7 +9,7 @@ namespace Capnp /// public class ListOfTextSerializer : SerializerState, - IReadOnlyList + IReadOnlyList { /// /// Gets or sets the text at given index. Once an element is set, it cannot be overwritten. @@ -18,7 +18,7 @@ namespace Capnp /// List is not initialized /// is out of range. /// UTF-8 encoding exceeds 2^29-2 bytes - public string this[int index] + public string? this[int index] { get { @@ -47,7 +47,7 @@ namespace Capnp /// public int Count => ListElementCount; - IEnumerable Enumerate() + IEnumerable Enumerate() { int count = Count; @@ -60,7 +60,7 @@ namespace Capnp /// /// Implementation of /> /// - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { return Enumerate().GetEnumerator(); } @@ -88,7 +88,7 @@ namespace Capnp /// List content. Can be null in which case the list is simply not initialized. /// The list was already initialized /// More than 2^29-1 items, or the UTF-8 encoding of an individual string requires more than 2^29-2 bytes. - public void Init(IReadOnlyList items) + public void Init(IReadOnlyList? items) { if (items == null) { @@ -108,5 +108,4 @@ namespace Capnp return GetEnumerator(); } } -} - +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Logging.cs b/Capnp.Net.Runtime/Logging.cs index 53e2e42..ce79635 100644 --- a/Capnp.Net.Runtime/Logging.cs +++ b/Capnp.Net.Runtime/Logging.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; namespace Capnp { @@ -20,4 +19,4 @@ namespace Capnp /// The logger instance public static ILogger CreateLogger() => LoggerFactory.CreateLogger(); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/MessageBuilder.cs b/Capnp.Net.Runtime/MessageBuilder.cs index d0fe6a0..9a5d826 100644 --- a/Capnp.Net.Runtime/MessageBuilder.cs +++ b/Capnp.Net.Runtime/MessageBuilder.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; namespace Capnp { @@ -12,7 +10,7 @@ namespace Capnp { readonly ISegmentAllocator _allocator; readonly DynamicSerializerState _rootPtrBuilder; - List _capTable; + List? _capTable; MessageBuilder(ISegmentAllocator allocator) { @@ -56,10 +54,11 @@ namespace Capnp /// Gets or sets the root object. The root object must be set exactly once per message. /// Setting it manually is only required (and allowed) when it was created with . /// - public SerializerState Root + /// Attempt to set null reference + public SerializerState? Root { get => _rootPtrBuilder.TryGetPointer(0); - set => _rootPtrBuilder.Link(0, value); + set => _rootPtrBuilder.Link(0, value ?? throw new ArgumentNullException(nameof(value))); } /// @@ -90,13 +89,13 @@ namespace Capnp if (_capTable != null) throw new InvalidOperationException("Capability table was already initialized"); - _capTable = new List(); + _capTable = new List(); } /// /// Returns this message builder's segment allocator. /// public ISegmentAllocator Allocator => _allocator; - internal List Caps => _capTable; + internal List? Caps => _capTable; } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/NullableAttributes.cs b/Capnp.Net.Runtime/NullableAttributes.cs new file mode 100644 index 0000000..4e65208 --- /dev/null +++ b/Capnp.Net.Runtime/NullableAttributes.cs @@ -0,0 +1,140 @@ +#pragma warning disable MA0048 // File name must match type name +#define INTERNAL_NULLABLE_ATTRIBUTES +#if NETSTANDARD2_0 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NET45 || NET451 || NET452 || NET6 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48 + +// https://github.com/dotnet/corefx/blob/48363ac826ccf66fbe31a5dcb1dc2aab9a7dd768/src/Common/src/CoreLib/System/Diagnostics/CodeAnalysis/NullableAttributes.cs + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Diagnostics.CodeAnalysis +{ + /// Specifies that null is allowed as an input even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class AllowNullAttribute : Attribute + { } + + /// Specifies that null is disallowed as an input even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DisallowNullAttribute : Attribute + { } + + /// Specifies that an output may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class MaybeNullAttribute : Attribute + { } + + /// Specifies that an output will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullAttribute : Attribute + { } + + /// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class MaybeNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter may be null. + /// + public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullWhenAttribute : Attribute + { + /// Initializes the attribute with the specified return value condition. + /// + /// The return value condition. If the method returns this value, the associated parameter will not be null. + /// + public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; + + /// Gets the return value condition. + public bool ReturnValue { get; } + } + + /// Specifies that the output will be non-null if the named parameter is non-null. + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class NotNullIfNotNullAttribute : Attribute + { + /// Initializes the attribute with the associated parameter name. + /// + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. + /// + public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; + + /// Gets the associated parameter name. + public string ParameterName { get; } + } + + /// Applied to a method that will never return under any circumstance. + [AttributeUsage(AttributeTargets.Method, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DoesNotReturnAttribute : Attribute + { } + + /// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. + [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] +#if INTERNAL_NULLABLE_ATTRIBUTES + internal +#else + public +#endif + sealed class DoesNotReturnIfAttribute : Attribute + { + /// Initializes the attribute with the specified parameter value. + /// + /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to + /// the associated parameter matches this value. + /// + public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; + + /// Gets the condition parameter value. + public bool ParameterValue { get; } + } +} +#endif \ No newline at end of file diff --git a/Capnp.Net.Runtime/ObjectKind.cs b/Capnp.Net.Runtime/ObjectKind.cs index c3b83f8..bdabf6f 100644 --- a/Capnp.Net.Runtime/ObjectKind.cs +++ b/Capnp.Net.Runtime/ObjectKind.cs @@ -70,4 +70,4 @@ namespace Capnp /// Value = 16 } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/PrimitiveCoder.cs b/Capnp.Net.Runtime/PrimitiveCoder.cs index 3614f67..9feee41 100644 --- a/Capnp.Net.Runtime/PrimitiveCoder.cs +++ b/Capnp.Net.Runtime/PrimitiveCoder.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Capnp { @@ -8,7 +6,7 @@ namespace Capnp { class Coder { - public static Func Fn { get; set; } + public static Func? Fn { get; set; } } static PrimitiveCoder() @@ -44,4 +42,4 @@ namespace Capnp throw new NotSupportedException("Generic type argument is not a supported primitive type, no coder defined"); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/ReadOnlyListExtensions.cs b/Capnp.Net.Runtime/ReadOnlyListExtensions.cs index 656ec19..96ba7e5 100644 --- a/Capnp.Net.Runtime/ReadOnlyListExtensions.cs +++ b/Capnp.Net.Runtime/ReadOnlyListExtensions.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Capnp { @@ -70,4 +69,4 @@ namespace Capnp return source.Select(selector).ToList().AsReadOnly(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Reserializing.cs b/Capnp.Net.Runtime/Reserializing.cs index a2bbf6c..2ad6a87 100644 --- a/Capnp.Net.Runtime/Reserializing.cs +++ b/Capnp.Net.Runtime/Reserializing.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; namespace Capnp { @@ -102,4 +101,4 @@ namespace Capnp to.InheritFrom(ds); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/AnswerOrCounterquestion.cs b/Capnp.Net.Runtime/Rpc/AnswerOrCounterquestion.cs index 1cdd5d6..05cfc70 100644 --- a/Capnp.Net.Runtime/Rpc/AnswerOrCounterquestion.cs +++ b/Capnp.Net.Runtime/Rpc/AnswerOrCounterquestion.cs @@ -33,11 +33,11 @@ /// /// SerializerState, if applicable /// - public SerializerState Answer => _obj as SerializerState; + public SerializerState? Answer => _obj as SerializerState; /// /// PendingQuestion, if applicable /// - public PendingQuestion Counterquestion => _obj as PendingQuestion; + public PendingQuestion? Counterquestion => _obj as PendingQuestion; } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/BareProxy.cs b/Capnp.Net.Runtime/Rpc/BareProxy.cs index 50d993d..5f9dca5 100644 --- a/Capnp.Net.Runtime/Rpc/BareProxy.cs +++ b/Capnp.Net.Runtime/Rpc/BareProxy.cs @@ -33,7 +33,7 @@ /// Constructs an instance and binds it to the given low-level capability. /// /// low-level capability - public BareProxy(ConsumedCapability cap): base(cap) + public BareProxy(ConsumedCapability? cap): base(cap) { } @@ -49,4 +49,4 @@ return base.Call(interfaceId, methodId, args, default); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs b/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs index 2cde6e6..42ae7ca 100644 --- a/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs +++ b/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; @@ -110,7 +109,7 @@ namespace Capnp.Rpc return (SkeletonFactory)Activator.CreateInstance( typeof(SkeletonFactory<>) - .MakeGenericType(skeletonClass)); + .MakeGenericType(skeletonClass))!; } static SkeletonFactory GetSkeletonFactory(Type type) @@ -190,7 +189,7 @@ namespace Capnp.Rpc return (ProxyFactory)Activator.CreateInstance( typeof(ProxyFactory<>) - .MakeGenericType(proxyClass)); + .MakeGenericType(proxyClass))!; } else { @@ -263,7 +262,7 @@ namespace Capnp.Rpc /// Problem with instatiating the Proxy (constructor threw exception). /// Caller does not have permission to invoke the Proxy constructor. /// Problem with building the Proxy type, or problem with loading some dependent class. - public static Proxy CreateProxy(ConsumedCapability cap, + public static Proxy CreateProxy(ConsumedCapability? cap, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) @@ -285,4 +284,4 @@ namespace Capnp.Rpc return proxy; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/ConnectionState.cs b/Capnp.Net.Runtime/Rpc/ConnectionState.cs index 5084a54..4453ba8 100644 --- a/Capnp.Net.Runtime/Rpc/ConnectionState.cs +++ b/Capnp.Net.Runtime/Rpc/ConnectionState.cs @@ -21,4 +21,4 @@ /// Down } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs b/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs index 8152d44..d628571 100644 --- a/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/ConsumedCapability.cs @@ -1,8 +1,4 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Capnp.Rpc +namespace Capnp.Rpc { /// /// Base class for a low-level capability at consumer side. It is created by the . An application does not directly interact with it @@ -18,7 +14,7 @@ namespace Capnp.Rpc /// protected abstract void ReleaseRemotely(); internal abstract void Export(IRpcEndpoint endpoint, CapDescriptor.WRITER writer); - internal abstract void Freeze(out IRpcEndpoint boundEndpoint); + internal abstract void Freeze(out IRpcEndpoint? boundEndpoint); internal abstract void Unfreeze(); internal abstract void AddRef(); @@ -30,4 +26,4 @@ namespace Capnp.Rpc public int CreatorLineNumber { get; set; } #endif } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IConnection.cs b/Capnp.Net.Runtime/Rpc/IConnection.cs index b18fc5c..28311f3 100644 --- a/Capnp.Net.Runtime/Rpc/IConnection.cs +++ b/Capnp.Net.Runtime/Rpc/IConnection.cs @@ -67,4 +67,4 @@ namespace Capnp.Rpc /// void Close(); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IEndpoint.cs b/Capnp.Net.Runtime/Rpc/IEndpoint.cs index 5c695f2..267cafa 100644 --- a/Capnp.Net.Runtime/Rpc/IEndpoint.cs +++ b/Capnp.Net.Runtime/Rpc/IEndpoint.cs @@ -15,4 +15,4 @@ /// void Dismiss(); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IMonoSkeleton.cs b/Capnp.Net.Runtime/Rpc/IMonoSkeleton.cs index 4c41061..66c6f52 100644 --- a/Capnp.Net.Runtime/Rpc/IMonoSkeleton.cs +++ b/Capnp.Net.Runtime/Rpc/IMonoSkeleton.cs @@ -10,4 +10,4 @@ /// ulong InterfaceId { get; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs b/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs index aedcbe4..250aa18 100644 --- a/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs +++ b/Capnp.Net.Runtime/Rpc/IPromisedAnswer.cs @@ -22,6 +22,6 @@ namespace Capnp.Rpc /// /// Path to the desired capability inside the result struct. /// Pipelined low-level capability - ConsumedCapability Access(MemberAccessPath access); + ConsumedCapability? Access(MemberAccessPath access); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IProvidedCapability.cs b/Capnp.Net.Runtime/Rpc/IProvidedCapability.cs index 3cbc384..93fd94b 100644 --- a/Capnp.Net.Runtime/Rpc/IProvidedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/IProvidedCapability.cs @@ -21,4 +21,4 @@ namespace Capnp.Rpc Task Invoke(ulong interfaceId, ushort methodId, DeserializerState args, CancellationToken cancellationToken = default); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IResolvingCapability.cs b/Capnp.Net.Runtime/Rpc/IResolvingCapability.cs index e8b29da..36f8bf0 100644 --- a/Capnp.Net.Runtime/Rpc/IResolvingCapability.cs +++ b/Capnp.Net.Runtime/Rpc/IResolvingCapability.cs @@ -12,4 +12,4 @@ namespace Capnp.Rpc /// Task WhenResolved { get; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs b/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs index e72e140..339ec26 100644 --- a/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs +++ b/Capnp.Net.Runtime/Rpc/IRpcEndpoint.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; namespace Capnp.Rpc @@ -18,4 +16,4 @@ namespace Capnp.Rpc Task RequestSenderLoopback(Action writer); void DeleteQuestion(PendingQuestion question); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Impatient.cs b/Capnp.Net.Runtime/Rpc/Impatient.cs index 9dd1e08..1a0a81e 100644 --- a/Capnp.Net.Runtime/Rpc/Impatient.cs +++ b/Capnp.Net.Runtime/Rpc/Impatient.cs @@ -11,7 +11,7 @@ namespace Capnp.Rpc public static class Impatient { static readonly ConditionalWeakTable _taskTable = new ConditionalWeakTable(); - static readonly ThreadLocal _askingEndpoint = new ThreadLocal(); + static readonly ThreadLocal _askingEndpoint = new ThreadLocal(); /// /// Attaches a continuation to the given promise and registers the resulting task for pipelining. @@ -51,7 +51,7 @@ namespace Capnp.Rpc } else if (rtask.IsFaulted) { - rtask = Task.FromException(rtask.Exception.InnerException); + rtask = Task.FromException(rtask.Exception!.InnerException!); } else { @@ -86,7 +86,7 @@ namespace Capnp.Rpc return answer; } - internal static IPromisedAnswer TryGetAnswer(Task task) + internal static IPromisedAnswer? TryGetAnswer(Task task) { _taskTable.TryGetValue(task, out var answer); return answer; @@ -102,10 +102,10 @@ namespace Capnp.Rpc return proxy; case null: - return null; + return CapabilityReflection.CreateProxy(null); } - var skel = Skeleton.GetOrCreateSkeleton(item, false); + var skel = Skeleton.GetOrCreateSkeleton(item!, false); var localCap = LocalCapability.Create(skel); return CapabilityReflection.CreateProxy(localCap); } @@ -131,7 +131,7 @@ namespace Capnp.Rpc where TInterface : class { var lazyCap = new LazyCapability(AwaitProxy(task)); - return CapabilityReflection.CreateProxy(lazyCap, memberName, sourceFilePath, sourceLineNumber) as TInterface; + return (CapabilityReflection.CreateProxy(lazyCap, memberName, sourceFilePath, sourceLineNumber) as TInterface)!; } static readonly MemberAccessPath Path_OneAndOnly = new MemberAccessPath(0U); @@ -168,15 +168,15 @@ namespace Capnp.Rpc } var lazyCap = new LazyCapability(AwaitProxy(task)); - return CapabilityReflection.CreateProxy(lazyCap) as TInterface; + return (CapabilityReflection.CreateProxy(lazyCap) as TInterface)!; } else { - return CapabilityReflection.CreateProxy(answer.Access(Path_OneAndOnly)) as TInterface; + return (CapabilityReflection.CreateProxy(answer.Access(Path_OneAndOnly)) as TInterface)!; } } - internal static IRpcEndpoint AskingEndpoint + internal static IRpcEndpoint? AskingEndpoint { get => _askingEndpoint.Value; set { _askingEndpoint.Value = value; } @@ -251,4 +251,4 @@ namespace Capnp.Rpc return MaybeTailCall(task, (ValueTuple t) => func(t.Item1, t.Item2, t.Item3, t.Item4, t.Item5, t.Item6, t.Item7)); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/ImportedCapability.cs b/Capnp.Net.Runtime/Rpc/ImportedCapability.cs index c821634..9645022 100644 --- a/Capnp.Net.Runtime/Rpc/ImportedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/ImportedCapability.cs @@ -1,6 +1,4 @@ -using System.Threading.Tasks; - -namespace Capnp.Rpc +namespace Capnp.Rpc { /// /// Low-level capability which as imported from a remote peer. @@ -51,4 +49,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs b/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs index 8daaaba..c8ea190 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/CallContext.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -34,7 +31,7 @@ namespace Capnp.Rpc.Interception return new Proxy(Access(access)); } - public ConsumedCapability Access(MemberAccessPath access) + public ConsumedCapability? Access(MemberAccessPath access) { if (_futureResult.Task.IsCompleted) { @@ -44,7 +41,7 @@ namespace Capnp.Rpc.Interception } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } } else @@ -107,7 +104,7 @@ namespace Capnp.Rpc.Interception /// /// Input arguments /// - public SerializerState InArgs { get; set; } + public SerializerState? InArgs { get; set; } /// /// Output arguments ("return value") @@ -117,7 +114,7 @@ namespace Capnp.Rpc.Interception /// /// Exception text, or null if there is no exception /// - public string Exception { get; set; } + public string? Exception { get; set; } /// /// Whether the call should return in canceled state to Alice (the original caller). @@ -156,7 +153,7 @@ namespace Capnp.Rpc.Interception /// null /// /// - public object Bob + public object? Bob { get => _bob; set @@ -196,11 +193,11 @@ namespace Capnp.Rpc.Interception } } - internal Proxy BobProxy { get; private set; } + internal Proxy? BobProxy { get; private set; } readonly CensorCapability _censorCapability; PromisedAnswer _promisedAnswer; - object _bob; + object? _bob; internal IPromisedAnswer Answer => _promisedAnswer; @@ -224,8 +221,13 @@ namespace Capnp.Rpc.Interception { for (int i = 0; i < state.Caps.Count; i++) { - state.Caps[i] = policy.Attach(state.Caps[i]); - state.Caps[i].AddRef(); + var cap = state.Caps[i]; + if (cap != null) + { + cap = policy.Attach(cap); + state.Caps[i] = cap; + cap.AddRef(); + } } } } @@ -236,8 +238,13 @@ namespace Capnp.Rpc.Interception { for (int i = 0; i < state.Caps.Count; i++) { - state.Caps[i] = policy.Detach(state.Caps[i]); - state.Caps[i].AddRef(); + var cap = state.Caps[i]; + if (cap != null) + { + cap = policy.Detach(cap); + state.Caps[i] = cap; + cap.AddRef(); + } } } } @@ -246,8 +253,12 @@ namespace Capnp.Rpc.Interception /// Intercepts all capabilies inside the input arguments /// /// Policy to use, or null to further use present policy - public void InterceptInCaps(IInterceptionPolicy policyOverride = null) + /// InArgs not set + public void InterceptInCaps(IInterceptionPolicy? policyOverride = null) { + if (InArgs == null) + throw new InvalidOperationException("InArgs not set"); + InterceptCaps(InArgs, policyOverride ?? _censorCapability.Policy); } @@ -255,7 +266,7 @@ namespace Capnp.Rpc.Interception /// Intercepts all capabilies inside the output arguments /// /// Policy to use, or null to further use present policy - public void InterceptOutCaps(IInterceptionPolicy policyOverride = null) + public void InterceptOutCaps(IInterceptionPolicy? policyOverride = null) { InterceptCaps(OutArgs, policyOverride ?? _censorCapability.Policy); } @@ -264,8 +275,12 @@ namespace Capnp.Rpc.Interception /// Unintercepts all capabilies inside the input arguments /// /// Policy to remove, or null to remove present policy - public void UninterceptInCaps(IInterceptionPolicy policyOverride = null) + /// InArgs not set + public void UninterceptInCaps(IInterceptionPolicy? policyOverride = null) { + if (InArgs == null) + throw new InvalidOperationException("InArgs not set"); + UninterceptCaps(InArgs, policyOverride ?? _censorCapability.Policy); } @@ -273,7 +288,7 @@ namespace Capnp.Rpc.Interception /// Unintercepts all capabilies inside the output arguments /// /// Policy to remove, or null to remove present policy - public void UninterceptOutCaps(IInterceptionPolicy policyOverride = null) + public void UninterceptOutCaps(IInterceptionPolicy? policyOverride = null) { UninterceptCaps(OutArgs, policyOverride ?? _censorCapability.Policy); } @@ -281,14 +296,16 @@ namespace Capnp.Rpc.Interception /// /// Forwards this intercepted call to the target capability ("Bob"). /// + /// Bob/InArgs not set public void ForwardToBob() { if (Bob == null) - { throw new InvalidOperationException("Bob is null"); - } - - var answer = BobProxy.Call(InterfaceId, MethodId, InArgs.Rewrap(), default, CancelToBob); + + if (InArgs == null) + throw new InvalidOperationException("InArgs not set"); + + var answer = BobProxy!.Call(InterfaceId, MethodId, InArgs.Rewrap(), default, CancelToBob); State = InterceptionState.ForwardedToBob; diff --git a/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs b/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs index abaa526..89573ba 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/CensorCapability.cs @@ -32,7 +32,7 @@ writer.SenderHosted = endpoint.AllocateExport(MyVine, out bool _); } - internal override void Freeze(out IRpcEndpoint boundEndpoint) + internal override void Freeze(out IRpcEndpoint? boundEndpoint) { boundEndpoint = null; } @@ -41,4 +41,4 @@ { } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Interception/IInterceptionPolicy.cs b/Capnp.Net.Runtime/Rpc/Interception/IInterceptionPolicy.cs index a4d5706..8aa3ed5 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/IInterceptionPolicy.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/IInterceptionPolicy.cs @@ -20,4 +20,4 @@ namespace Capnp.Rpc.Interception /// void OnReturnFromBob(CallContext callContext); } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Interception/InterceptionState.cs b/Capnp.Net.Runtime/Rpc/Interception/InterceptionState.cs index 67eea0e..a02cfa9 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/InterceptionState.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/InterceptionState.cs @@ -25,4 +25,4 @@ /// ReturnedToAlice } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Interception/Interceptor.cs b/Capnp.Net.Runtime/Rpc/Interception/Interceptor.cs index 91c3ee3..1413f6c 100644 --- a/Capnp.Net.Runtime/Rpc/Interception/Interceptor.cs +++ b/Capnp.Net.Runtime/Rpc/Interception/Interceptor.cs @@ -45,16 +45,16 @@ namespace Capnp.Rpc.Interception switch (cap) { case Proxy proxy: - return CapabilityReflection.CreateProxy(Attach(policy, proxy.ConsumedCap)) as TCap; + return (CapabilityReflection.CreateProxy(Attach(policy, proxy.ConsumedCap!)) as TCap)!; case ConsumedCapability ccap: - return new CensorCapability(ccap, policy) as TCap; + return (new CensorCapability(ccap, policy) as TCap)!; default: - return Attach(policy, - CapabilityReflection.CreateProxy( + return (Attach(policy, + (CapabilityReflection.CreateProxy( LocalCapability.Create( - Skeleton.GetOrCreateSkeleton(cap, false))) as TCap); + Skeleton.GetOrCreateSkeleton(cap, false))) as TCap)!)); } } @@ -79,11 +79,11 @@ namespace Capnp.Rpc.Interception switch (cap) { case Proxy proxy: - return CapabilityReflection.CreateProxy(Detach(policy, proxy.ConsumedCap)) as TCap; + return (CapabilityReflection.CreateProxy(Detach(policy, proxy.ConsumedCap!)) as TCap)!; case CensorCapability ccap: { - var cur = ccap; + CensorCapability? cur = ccap; var stk = new Stack(); do @@ -96,7 +96,7 @@ namespace Capnp.Rpc.Interception { cur2 = p.Attach(cur2); } - return cur2 as TCap; + return (cur2 as TCap)!; } stk.Push(cur.Policy); @@ -104,7 +104,7 @@ namespace Capnp.Rpc.Interception } while (cur != null); - return ccap as TCap; + return (ccap as TCap)!; } default: @@ -112,4 +112,4 @@ namespace Capnp.Rpc.Interception } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/InvalidCapabilityInterfaceException.cs b/Capnp.Net.Runtime/Rpc/InvalidCapabilityInterfaceException.cs index 2ce9466..b08aa3a 100644 --- a/Capnp.Net.Runtime/Rpc/InvalidCapabilityInterfaceException.cs +++ b/Capnp.Net.Runtime/Rpc/InvalidCapabilityInterfaceException.cs @@ -21,4 +21,4 @@ { } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/LazyCapability.cs b/Capnp.Net.Runtime/Rpc/LazyCapability.cs index ed2ac40..965d054 100644 --- a/Capnp.Net.Runtime/Rpc/LazyCapability.cs +++ b/Capnp.Net.Runtime/Rpc/LazyCapability.cs @@ -27,7 +27,7 @@ namespace Capnp.Rpc WhenResolved = capabilityTask; } - internal override void Freeze(out IRpcEndpoint boundEndpoint) + internal override void Freeze(out IRpcEndpoint? boundEndpoint) { if (WhenResolved.IsCompleted) { @@ -37,7 +37,7 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } } else @@ -105,4 +105,4 @@ namespace Capnp.Rpc return new LocalAnswer(cts, CallImpl(interfaceId, methodId, args, cts.Token)); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/LocalAnswer.cs b/Capnp.Net.Runtime/Rpc/LocalAnswer.cs index 80b5ac0..8744cb6 100644 --- a/Capnp.Net.Runtime/Rpc/LocalAnswer.cs +++ b/Capnp.Net.Runtime/Rpc/LocalAnswer.cs @@ -49,4 +49,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs b/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs index 3dbf83b..195d139 100644 --- a/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs +++ b/Capnp.Net.Runtime/Rpc/LocalAnswerCapability.cs @@ -15,7 +15,7 @@ namespace Capnp.Rpc _access = access; } - internal override void Freeze(out IRpcEndpoint boundEndpoint) + internal override void Freeze(out IRpcEndpoint? boundEndpoint) { boundEndpoint = null; } @@ -43,7 +43,7 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } using (var proxy = new Proxy(_access.Eval(result))) @@ -86,4 +86,4 @@ namespace Capnp.Rpc this.DisposeWhenResolved(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/LocalCapability.cs b/Capnp.Net.Runtime/Rpc/LocalCapability.cs index 3328a5f..4bff9e6 100644 --- a/Capnp.Net.Runtime/Rpc/LocalCapability.cs +++ b/Capnp.Net.Runtime/Rpc/LocalCapability.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -14,7 +13,7 @@ namespace Capnp.Rpc public static ConsumedCapability Create(Skeleton skeleton) { if (skeleton is Vine vine) - return vine.Proxy.ConsumedCap; + return vine.Proxy.ConsumedCap!; else return _localCaps.GetValue(skeleton, _ => new LocalCapability(_)); } @@ -22,7 +21,7 @@ namespace Capnp.Rpc static async Task AwaitAnswer(Task call) { var aorcq = await call; - return aorcq.Answer ?? await aorcq.Counterquestion.WhenReturned; + return aorcq.Answer ?? await aorcq.Counterquestion!.WhenReturned; } public Skeleton ProvidedCap { get; } @@ -55,7 +54,7 @@ namespace Capnp.Rpc capDesc.SenderHosted = endpoint.AllocateExport(ProvidedCap, out bool _); } - internal override void Freeze(out IRpcEndpoint boundEndpoint) + internal override void Freeze(out IRpcEndpoint? boundEndpoint) { boundEndpoint = null; } @@ -68,4 +67,4 @@ namespace Capnp.Rpc { } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs b/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs index 7b887c8..4843c08 100644 --- a/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs +++ b/Capnp.Net.Runtime/Rpc/MemberAccessPath.cs @@ -169,7 +169,7 @@ namespace Capnp.Rpc /// The object (usually "params struct") on which to evaluate this path. /// Resulting low-level capability /// Evaluation of this path did not give a capability - public ConsumedCapability Eval(DeserializerState rpcState) + public ConsumedCapability? Eval(DeserializerState rpcState) { var cur = rpcState; @@ -184,11 +184,11 @@ namespace Capnp.Rpc return null; case ObjectKind.Capability: - return rpcState.Caps[(int)cur.CapabilityIndex]; + return rpcState.Caps![(int)cur.CapabilityIndex]; default: throw new DeserializationException("Access path did not result in a capability"); } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/PendingAnswer.cs b/Capnp.Net.Runtime/Rpc/PendingAnswer.cs index 4031501..6660725 100644 --- a/Capnp.Net.Runtime/Rpc/PendingAnswer.cs +++ b/Capnp.Net.Runtime/Rpc/PendingAnswer.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -8,14 +7,14 @@ namespace Capnp.Rpc class PendingAnswer: IDisposable { readonly object _reentrancyBlocker = new object(); - readonly CancellationTokenSource _cts; + readonly CancellationTokenSource? _cts; readonly TaskCompletionSource _whenCanceled; Task _callTask; - Task _initialTask; - Task _chainedTask; + Task? _initialTask; + Task? _chainedTask; bool _disposed; - public PendingAnswer(Task callTask, CancellationTokenSource cts) + public PendingAnswer(Task callTask, CancellationTokenSource? cts) { _cts = cts; _callTask = callTask ?? throw new ArgumentNullException(nameof(callTask)); @@ -138,7 +137,7 @@ namespace Capnp.Rpc case ObjectKind.Capability: try { - var cap = aorcq.Answer.Caps[(int)cur.CapabilityIndex]; + var cap = aorcq.Answer.Caps![(int)cur.CapabilityIndex]; proxy = new Proxy(cap ?? LazyCapability.Null); } catch (ArgumentOutOfRangeException) @@ -154,7 +153,7 @@ namespace Capnp.Rpc else { var path = MemberAccessPath.Deserialize(rd); - var cap = new RemoteAnswerCapability(aorcq.Counterquestion, path); + var cap = new RemoteAnswerCapability(aorcq.Counterquestion!, path); return new Proxy(cap); } } @@ -169,7 +168,7 @@ namespace Capnp.Rpc { if (_cts != null) { - Task chainedTask; + Task? chainedTask; lock (_reentrancyBlocker) { @@ -198,4 +197,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/PendingQuestion.cs b/Capnp.Net.Runtime/Rpc/PendingQuestion.cs index 2d7addc..227f189 100644 --- a/Capnp.Net.Runtime/Rpc/PendingQuestion.cs +++ b/Capnp.Net.Runtime/Rpc/PendingQuestion.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Threading; using System.Threading.Tasks; namespace Capnp.Rpc @@ -61,11 +59,11 @@ namespace Capnp.Rpc readonly TaskCompletionSource _tcs = new TaskCompletionSource(); readonly uint _questionId; - ConsumedCapability _target; - SerializerState _inParams; + ConsumedCapability? _target; + SerializerState? _inParams; int _inhibitFinishCounter; - internal PendingQuestion(IRpcEndpoint ep, uint id, ConsumedCapability target, SerializerState inParams) + internal PendingQuestion(IRpcEndpoint ep, uint id, ConsumedCapability? target, SerializerState? inParams) { RpcEndpoint = ep ?? throw new ArgumentNullException(nameof(ep)); _questionId = id; @@ -75,7 +73,7 @@ namespace Capnp.Rpc if (inParams != null) { - foreach (var cap in inParams.Caps) + foreach (var cap in inParams.Caps!) { cap?.AddRef(); } @@ -236,7 +234,7 @@ namespace Capnp.Rpc /// Access path /// Low-level capability /// The referenced member does not exist or does not resolve to a capability pointer. - public ConsumedCapability Access(MemberAccessPath access) + public ConsumedCapability? Access(MemberAccessPath access) { lock (ReentrancyBlocker) { @@ -249,7 +247,7 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } } else @@ -259,11 +257,11 @@ namespace Capnp.Rpc } } - static void ReleaseCaps(ConsumedCapability target, SerializerState inParams) + static void ReleaseCaps(ConsumedCapability? target, SerializerState? inParams) { if (inParams != null) { - foreach (var cap in inParams.Caps) + foreach (var cap in inParams.Caps!) { cap?.Release(); } @@ -277,7 +275,7 @@ namespace Capnp.Rpc static void ReleaseOutCaps(DeserializerState outParams) { - foreach (var cap in outParams.Caps) + foreach (var cap in outParams.Caps!) { cap?.Release(); } @@ -285,12 +283,13 @@ namespace Capnp.Rpc internal void Send() { - SerializerState inParams; - ConsumedCapability target; + SerializerState? inParams; + ConsumedCapability? target; lock (ReentrancyBlocker) { - Debug.Assert(!StateFlags.HasFlag(State.Sent)); + if (StateFlags.HasFlag(State.Sent)) + throw new InvalidOperationException("Already sent"); inParams = _inParams; _inParams = null; @@ -299,7 +298,7 @@ namespace Capnp.Rpc StateFlags |= State.Sent; } - var msg = (Message.WRITER)inParams.MsgBuilder.Root; + var msg = (Message.WRITER)inParams!.MsgBuilder!.Root!; Debug.Assert(msg.Call.Target.which != MessageTarget.WHICH.undefined); var call = msg.Call; call.QuestionId = QuestionId; @@ -316,15 +315,15 @@ namespace Capnp.Rpc OnException(exception); } - ReleaseCaps(target, inParams); + ReleaseCaps(target!, inParams); } #region IDisposable Support void Dispose(bool disposing) { - SerializerState inParams; - ConsumedCapability target; + SerializerState? inParams; + ConsumedCapability? target; bool justDisposed = false; lock (ReentrancyBlocker) @@ -376,4 +375,4 @@ namespace Capnp.Rpc } #endregion } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/PolySkeleton.cs b/Capnp.Net.Runtime/Rpc/PolySkeleton.cs index a159f8e..002a75f 100644 --- a/Capnp.Net.Runtime/Rpc/PolySkeleton.cs +++ b/Capnp.Net.Runtime/Rpc/PolySkeleton.cs @@ -70,4 +70,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/PromisedCapability.cs b/Capnp.Net.Runtime/Rpc/PromisedCapability.cs index b704c7e..083a13d 100644 --- a/Capnp.Net.Runtime/Rpc/PromisedCapability.cs +++ b/Capnp.Net.Runtime/Rpc/PromisedCapability.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Threading; using System.Threading.Tasks; namespace Capnp.Rpc @@ -19,7 +18,7 @@ namespace Capnp.Rpc public override Task WhenResolved => _resolvedCap.Task; - internal override void Freeze(out IRpcEndpoint boundEndpoint) + internal override void Freeze(out IRpcEndpoint? boundEndpoint) { lock (_reentrancyBlocker) { @@ -31,7 +30,7 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } } else @@ -148,7 +147,7 @@ namespace Capnp.Rpc } } - protected override Proxy ResolvedCap + protected override Proxy? ResolvedCap { get { @@ -158,7 +157,7 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } } } @@ -257,4 +256,4 @@ namespace Capnp.Rpc return call; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Proxy.cs b/Capnp.Net.Runtime/Rpc/Proxy.cs index 1574c5d..ed0a976 100644 --- a/Capnp.Net.Runtime/Rpc/Proxy.cs +++ b/Capnp.Net.Runtime/Rpc/Proxy.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging; -using System; +using System; using System.Threading; using System.Threading.Tasks; @@ -38,7 +37,7 @@ namespace Capnp.Rpc /// /// Underlying low-level capability /// - protected internal ConsumedCapability ConsumedCap { get; private set; } + protected internal ConsumedCapability? ConsumedCap { get; private set; } /// /// Whether is this a broken capability. @@ -99,12 +98,12 @@ namespace Capnp.Rpc { } - internal Proxy(ConsumedCapability cap) + internal Proxy(ConsumedCapability? cap) { Bind(cap); } - internal void Bind(ConsumedCapability cap) + internal void Bind(ConsumedCapability? cap) { if (ConsumedCap != null) throw new InvalidOperationException("Proxy was already bound"); @@ -116,7 +115,7 @@ namespace Capnp.Rpc cap.AddRef(); } - internal IProvidedCapability GetProvider() + internal IProvidedCapability? GetProvider() { switch (ConsumedCap) { @@ -200,7 +199,7 @@ namespace Capnp.Rpc using (disposeThis ? this : null) { - return CapabilityReflection.CreateProxy(ConsumedCap) as T; + return (CapabilityReflection.CreateProxy(ConsumedCap) as T)!; } } @@ -215,7 +214,7 @@ namespace Capnp.Rpc ConsumedCap.Export(endpoint, writer); } - internal void Freeze(out IRpcEndpoint boundEndpoint) + internal void Freeze(out IRpcEndpoint? boundEndpoint) { if (_disposedValue) throw new ObjectDisposedException(nameof(Proxy)); @@ -238,4 +237,4 @@ namespace Capnp.Rpc public int CreatorLineNumber { get; set; } #endif } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/ProxyAttribute.cs b/Capnp.Net.Runtime/Rpc/ProxyAttribute.cs index ccf38c5..951581c 100644 --- a/Capnp.Net.Runtime/Rpc/ProxyAttribute.cs +++ b/Capnp.Net.Runtime/Rpc/ProxyAttribute.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Capnp.Rpc { @@ -27,4 +25,4 @@ namespace Capnp.Rpc /// public Type ProxyClass { get; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs index e60e3dc..290cca4 100644 --- a/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RefCountingCapability.cs @@ -1,5 +1,4 @@ using System; -using System.Threading; using System.Threading.Tasks; namespace Capnp.Rpc @@ -111,4 +110,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs b/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs index 27f8961..e3269e6 100644 --- a/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RemoteAnswerCapability.cs @@ -1,6 +1,4 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Diagnostics; +using System; using System.Threading.Tasks; namespace Capnp.Rpc @@ -18,7 +16,7 @@ namespace Capnp.Rpc readonly PendingQuestion _question; readonly MemberAccessPath _access; - Proxy _resolvedCap; + Proxy? _resolvedCap; public RemoteAnswerCapability(PendingQuestion question, MemberAccessPath access): base(question.RpcEndpoint) { @@ -59,7 +57,7 @@ namespace Capnp.Rpc } } - protected override Proxy ResolvedCap + protected override Proxy? ResolvedCap { get { @@ -74,7 +72,7 @@ namespace Capnp.Rpc } catch (AggregateException exception) { - throw exception.InnerException; + throw exception.InnerException!; } _resolvedCap = new Proxy(_access.Eval(result)); @@ -87,7 +85,11 @@ namespace Capnp.Rpc async Task AwaitWhenResolved() { await _question.WhenReturned; - return ResolvedCap; + + if (_question.IsTailCall) + throw new InvalidOperationException("Question is a tail call, so won't resolve back."); + + return ResolvedCap!; } public override Task WhenResolved => AwaitWhenResolved(); @@ -168,7 +170,7 @@ namespace Capnp.Rpc return call; } - internal override void Freeze(out IRpcEndpoint boundEndpoint) + internal override void Freeze(out IRpcEndpoint? boundEndpoint) { lock (_question.ReentrancyBlocker) { @@ -216,7 +218,7 @@ namespace Capnp.Rpc if (_question.StateFlags.HasFlag(PendingQuestion.State.Returned)) { - ResolvedCap.Export(endpoint, writer); + ResolvedCap?.Export(endpoint, writer); } else { @@ -254,4 +256,4 @@ namespace Capnp.Rpc this.DisposeWhenResolved(); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RemoteCapability.cs b/Capnp.Net.Runtime/Rpc/RemoteCapability.cs index 2dc470e..f198b29 100644 --- a/Capnp.Net.Runtime/Rpc/RemoteCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RemoteCapability.cs @@ -1,7 +1,5 @@ using System; using System.Diagnostics; -using System.Threading; -using System.Threading.Tasks; namespace Capnp.Rpc { @@ -24,6 +22,9 @@ namespace Capnp.Rpc protected virtual Call.WRITER SetupMessage(DynamicSerializerState args, ulong interfaceId, ushort methodId) { + if (args.MsgBuilder == null) + throw new ArgumentException("Unbound serializer state", nameof(args)); + var callMsg = args.MsgBuilder.BuildRoot(); callMsg.which = Message.WHICH.Call; @@ -37,4 +38,4 @@ namespace Capnp.Rpc return call; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RemoteResolvingCapability.cs b/Capnp.Net.Runtime/Rpc/RemoteResolvingCapability.cs index 4c8c9fb..225c8e1 100644 --- a/Capnp.Net.Runtime/Rpc/RemoteResolvingCapability.cs +++ b/Capnp.Net.Runtime/Rpc/RemoteResolvingCapability.cs @@ -23,14 +23,17 @@ namespace Capnp.Rpc } protected int _pendingCallsOnPromise; - Task _disembargo; + Task? _disembargo; - protected abstract Proxy ResolvedCap { get; } + protected abstract Proxy? ResolvedCap { get; } protected abstract void GetMessageTarget(MessageTarget.WRITER wr); protected IPromisedAnswer CallOnResolution(ulong interfaceId, ushort methodId, DynamicSerializerState args) { + if (ResolvedCap == null) + throw new InvalidOperationException("Capability not yet resolved, calling on resolution not possible"); + try { ResolvedCap.Freeze(out var resolvedCapEndpoint); @@ -123,4 +126,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs b/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs index d59173b..9b68f7e 100644 --- a/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs +++ b/Capnp.Net.Runtime/Rpc/ResolvingCapabilityExtensions.cs @@ -19,7 +19,7 @@ { var resolvedCap = await cap.WhenResolved; - endpoint.Resolve(preliminaryId, vine, () => resolvedCap.ConsumedCap); + endpoint.Resolve(preliminaryId, vine, () => resolvedCap.ConsumedCap!); } catch (System.Exception exception) { @@ -41,4 +41,4 @@ } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RpcEngine.cs b/Capnp.Net.Runtime/Rpc/RpcEngine.cs index 316e048..2378959 100644 --- a/Capnp.Net.Runtime/Rpc/RpcEngine.cs +++ b/Capnp.Net.Runtime/Rpc/RpcEngine.cs @@ -4,9 +4,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -65,8 +62,8 @@ namespace Capnp.Rpc internal class RpcEndpoint : IEndpoint, IRpcEndpoint { - static readonly ThreadLocal _exportCapTablePostActions = new ThreadLocal(); - static readonly ThreadLocal _tailCall = new ThreadLocal(); + static readonly ThreadLocal _exportCapTablePostActions = new ThreadLocal(); + static readonly ThreadLocal _tailCall = new ThreadLocal(); static readonly ThreadLocal _canDeferCalls = new ThreadLocal(); ILogger Logger { get; } = Logging.CreateLogger(); @@ -145,8 +142,7 @@ namespace Capnp.Rpc Tx(mb.Frame); } - void IRpcEndpoint.Resolve(uint preliminaryId, Skeleton preliminaryCap, - Func resolvedCapGetter) + void IRpcEndpoint.Resolve(uint preliminaryId, Skeleton preliminaryCap, Func resolvedCapGetter) { lock (_reentrancyBlocker) { @@ -232,7 +228,7 @@ namespace Capnp.Rpc return AllocateExport(providedCapability, out first); } - PendingQuestion AllocateQuestion(ConsumedCapability target, SerializerState inParams) + PendingQuestion AllocateQuestion(ConsumedCapability? target, SerializerState? inParams) { lock (_reentrancyBlocker) { @@ -293,7 +289,7 @@ namespace Capnp.Rpc uint q = req.QuestionId; var bootstrap = DynamicSerializerState.CreateForRpc(); - var ans = bootstrap.MsgBuilder.BuildRoot(); + var ans = bootstrap.MsgBuilder!.BuildRoot(); ans.which = Message.WHICH.Return; var ret = ans.Return; @@ -305,7 +301,7 @@ namespace Capnp.Rpc if (bootstrapCap != null) { ret.which = Return.WHICH.Results; - bootstrap.SetCapability(bootstrap.ProvideCapability(LocalCapability.Create(_host.BootstrapCap))); + bootstrap.SetCapability(bootstrap.ProvideCapability(LocalCapability.Create(bootstrapCap))); ret.Results.Content = bootstrap; bootstrapTask = Task.FromResult(bootstrap); @@ -371,12 +367,12 @@ namespace Capnp.Rpc } catch (RpcException exception) { - Logger.LogWarning($"Unable to return call: {exception.InnerException.Message}"); + Logger.LogWarning($"Unable to return call: {exception.InnerException?.Message ?? exception.Message}"); } } - IProvidedCapability cap; - PendingAnswer pendingAnswer = null; + IProvidedCapability? cap; + PendingAnswer pendingAnswer; bool releaseParamCaps = false; void AwaitAnswerAndReply() @@ -414,8 +410,8 @@ namespace Capnp.Rpc } else if (aorcq.Answer != null || aorcq.Counterquestion != _tailCall.Value) { - var results = aorcq.Answer ?? (DynamicSerializerState)(await aorcq.Counterquestion.WhenReturned); - var ret = SetupReturn(results.MsgBuilder); + var results = aorcq.Answer ?? (DynamicSerializerState)(await aorcq.Counterquestion!.WhenReturned); + var ret = SetupReturn(results.MsgBuilder!); switch (req.SendResultsTo.which) { @@ -569,7 +565,7 @@ namespace Capnp.Rpc case MessageTarget.WHICH.PromisedAnswer: { bool exists; - PendingAnswer previousAnswer; + PendingAnswer? previousAnswer; lock (_reentrancyBlocker) { @@ -578,7 +574,7 @@ namespace Capnp.Rpc if (exists) { - previousAnswer.Chain( + previousAnswer!.Chain( false, req.Target.PromisedAnswer, async t => @@ -633,7 +629,7 @@ namespace Capnp.Rpc void ProcessReturn(Return.READER req) { - PendingQuestion question; + PendingQuestion? question; lock (_reentrancyBlocker) { @@ -674,7 +670,7 @@ namespace Capnp.Rpc case Return.WHICH.TakeFromOtherQuestion: { bool exists; - PendingAnswer pendingAnswer; + PendingAnswer? pendingAnswer; lock (_reentrancyBlocker) { @@ -683,7 +679,7 @@ namespace Capnp.Rpc if (exists) { - pendingAnswer.Chain(false, async t => + pendingAnswer!.Chain(false, async t => { try { @@ -747,6 +743,8 @@ namespace Capnp.Rpc lock (_reentrancyBlocker) { var resolvedCap = ImportCap(resolve.Cap); + if (resolvedCap == null) + resolvedCap = LazyCapability.CreateBrokenCap("Failed to resolve this capability"); resolvableCap.ResolveTo(resolvedCap); } break; @@ -935,7 +933,7 @@ namespace Capnp.Rpc { foreach (var cap in results.Caps) { - cap.Release(); + cap?.Release(); } } }); @@ -984,8 +982,8 @@ namespace Capnp.Rpc try { int icount = checked((int)count); - rc.Release(icount); - rc.Cap.Relinquish(icount); + rc!.Release(icount); + rc!.Cap.Relinquish(icount); if (rc.RefCount == 0) { @@ -1171,7 +1169,7 @@ namespace Capnp.Rpc } } - ConsumedCapability ImportCap(CapDescriptor.READER capDesc) + ConsumedCapability? ImportCap(CapDescriptor.READER capDesc) { lock (_reentrancyBlocker) { @@ -1192,8 +1190,7 @@ namespace Capnp.Rpc rcw.Cap.SetTarget(impCap); } - Debug.Assert(impCap != null); - return impCap; + return impCap!; } else { @@ -1236,7 +1233,6 @@ namespace Capnp.Rpc case CapDescriptor.WHICH.ReceiverHosted: if (_exportTable.TryGetValue(capDesc.ReceiverHosted, out var rc)) { - Debug.Assert(rc.Cap != null); return LocalCapability.Create(rc.Cap); } else @@ -1311,9 +1307,9 @@ namespace Capnp.Rpc } } - public IList ImportCapTable(Payload.READER payload) + public IList ImportCapTable(Payload.READER payload) { - var list = new List(); + var list = new List(); if (payload.CapTable != null) { @@ -1341,7 +1337,7 @@ namespace Capnp.Rpc Debug.Assert(_exportCapTablePostActions.Value == null); _exportCapTablePostActions.Value = null; - payload.CapTable.Init(state.MsgBuilder.Caps.Count); + payload.CapTable.Init(state.MsgBuilder!.Caps!.Count); int i = 0; foreach (var cap in state.MsgBuilder.Caps) @@ -1454,7 +1450,7 @@ namespace Capnp.Rpc } catch (RpcException exception) { - Logger.LogWarning($"Unable to release import: {exception.InnerException.Message}"); + Logger.LogWarning($"Unable to release import: {exception.InnerException?.Message ?? exception.Message}"); } } } @@ -1492,12 +1488,12 @@ namespace Capnp.Rpc return inboundEndpoint; } - Skeleton _bootstrapCap; + Skeleton? _bootstrapCap; /// /// Gets or sets the bootstrap capability. /// - public Skeleton BootstrapCap + public Skeleton? BootstrapCap { get => _bootstrapCap; set @@ -1508,4 +1504,4 @@ namespace Capnp.Rpc } } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RpcException.cs b/Capnp.Net.Runtime/Rpc/RpcException.cs index 9629cf9..6c9a4ef 100644 --- a/Capnp.Net.Runtime/Rpc/RpcException.cs +++ b/Capnp.Net.Runtime/Rpc/RpcException.cs @@ -19,4 +19,4 @@ { } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/RpcUnimplementedException.cs b/Capnp.Net.Runtime/Rpc/RpcUnimplementedException.cs index f700e34..6947741 100644 --- a/Capnp.Net.Runtime/Rpc/RpcUnimplementedException.cs +++ b/Capnp.Net.Runtime/Rpc/RpcUnimplementedException.cs @@ -3,4 +3,4 @@ class RpcUnimplementedException : System.Exception { } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Skeleton.cs b/Capnp.Net.Runtime/Rpc/Skeleton.cs index 856f2a1..842bf06 100644 --- a/Capnp.Net.Runtime/Rpc/Skeleton.cs +++ b/Capnp.Net.Runtime/Rpc/Skeleton.cs @@ -1,8 +1,5 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Diagnostics; +using System; using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -179,8 +176,8 @@ namespace Capnp.Rpc ILogger Logger { get; } = Logging.CreateLogger>(); #endif - Func>[] _methods; - CancellationTokenSource _disposed = new CancellationTokenSource(); + Func>[] _methods = null!; + CancellationTokenSource? _disposed = new CancellationTokenSource(); readonly object _reentrancyBlocker = new object(); int _pendingCalls; @@ -204,7 +201,7 @@ namespace Capnp.Rpc /// /// Gets the underlying capability implementation. /// - protected T Impl { get; private set; } + protected T Impl { get; private set; } = default!; /// /// Gets the ID of the implemented interface. @@ -298,4 +295,4 @@ namespace Capnp.Rpc Impl = (T)impl; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/SkeletonAttribute.cs b/Capnp.Net.Runtime/Rpc/SkeletonAttribute.cs index b8b01d6..0b437b6 100644 --- a/Capnp.Net.Runtime/Rpc/SkeletonAttribute.cs +++ b/Capnp.Net.Runtime/Rpc/SkeletonAttribute.cs @@ -31,4 +31,4 @@ namespace Capnp.Rpc /// public Type SkeletonClass { get; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs b/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs index def2f78..02a975d 100644 --- a/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs +++ b/Capnp.Net.Runtime/Rpc/TcpRpcClient.cs @@ -1,13 +1,9 @@ using Capnp.FrameTracing; using Microsoft.Extensions.Logging; using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Net; using System.Net.Sockets; -using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -46,17 +42,17 @@ namespace Capnp.Rpc readonly RpcEngine _rpcEngine; readonly TcpClient _client; Func _createLayers = _ => _; - RpcEngine.RpcEndpoint _inboundEndpoint; - OutboundTcpEndpoint _outboundEndpoint; - FramePump _pump; - Thread _pumpThread; - Action _attachTracerAction; + RpcEngine.RpcEndpoint? _inboundEndpoint; + OutboundTcpEndpoint? _outboundEndpoint; + FramePump? _pump; + Thread? _pumpThread; + Action? _attachTracerAction; /// /// Gets a Task which completes when TCP is connected. Will be /// null until connection is actually requested (either by calling Connect or using appropriate constructor). /// - public Task WhenConnected { get; private set; } + public Task? WhenConnected { get; private set; } async Task ConnectAsync(string host, int port) { @@ -156,8 +152,14 @@ namespace Capnp.Rpc /// /// Bootstrap capability interface /// A proxy for the bootstrap capability + /// Not connected public TProxy GetMain() where TProxy: class { + if (WhenConnected == null) + { + throw new InvalidOperationException("Not connecting"); + } + if (!WhenConnected.IsCompleted) { throw new InvalidOperationException("Connection not yet established"); @@ -168,9 +170,7 @@ namespace Capnp.Rpc throw new InvalidOperationException("Connection not successfully established"); } - Debug.Assert(_inboundEndpoint != null); - - return CapabilityReflection.CreateProxy(_inboundEndpoint.QueryMain()) as TProxy; + return (CapabilityReflection.CreateProxy(_inboundEndpoint!.QueryMain()) as TProxy)!; } /// @@ -182,7 +182,7 @@ namespace Capnp.Rpc try { - if (!WhenConnected.Wait(500)) + if (WhenConnected != null && !WhenConnected.Wait(500)) { Logger.LogError("Unable to join connection task within timeout"); } @@ -218,7 +218,7 @@ namespace Capnp.Rpc _attachTracerAction += () => { - _pump.AttachTracer(tracer); + _pump?.AttachTracer(tracer); }; } @@ -257,33 +257,33 @@ namespace Capnp.Rpc /// /// Gets the number of RPC protocol messages sent by this client so far. /// - public long SendCount => _inboundEndpoint.SendCount; + public long SendCount => _inboundEndpoint?.SendCount ?? 0; /// /// Gets the number of RPC protocol messages received by this client so far. /// - public long RecvCount => _inboundEndpoint.RecvCount; + public long RecvCount => _inboundEndpoint?.RecvCount ?? 0; /// /// Gets the remote port number which this client is connected to, /// or null if the connection is not yet established. /// - public int? RemotePort => ((IPEndPoint)_client.Client?.RemoteEndPoint)?.Port; + public int? RemotePort => ((IPEndPoint)_client.Client.RemoteEndPoint)?.Port; /// /// Gets the local port number which this client using, /// or null if the connection is not yet established. /// - public int? LocalPort => ((IPEndPoint)_client.Client?.LocalEndPoint)?.Port; + public int? LocalPort => ((IPEndPoint)_client.Client.LocalEndPoint)?.Port; /// /// Whether the I/O thread is currently running /// - public bool IsComputing => _pumpThread.ThreadState == System.Threading.ThreadState.Running; + public bool IsComputing => _pumpThread?.ThreadState == System.Threading.ThreadState.Running; /// /// Whether the I/O thread is waiting for data to receive /// - public bool IsWaitingForData => _pump.IsWaitingForData; + public bool IsWaitingForData => _pump?.IsWaitingForData ?? false; } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/TcpRpcServer.cs b/Capnp.Net.Runtime/Rpc/TcpRpcServer.cs index 131f0ce..dcd05fc 100644 --- a/Capnp.Net.Runtime/Rpc/TcpRpcServer.cs +++ b/Capnp.Net.Runtime/Rpc/TcpRpcServer.cs @@ -109,12 +109,12 @@ namespace Capnp.Rpc public FramePump Pump { get; private set; } public OutboundTcpEndpoint OutboundEp { get; private set; } public RpcEngine.RpcEndpoint InboundEp { get; private set; } - public Thread PumpRunner { get; private set; } + public Thread? PumpRunner { get; private set; } public int? LocalPort => ((IPEndPoint)Client.Client.LocalEndPoint)?.Port; public int? RemotePort => ((IPEndPoint)Client.Client.RemoteEndPoint)?.Port; public long RecvCount => InboundEp.RecvCount; public long SendCount => InboundEp.SendCount; - public bool IsComputing => PumpRunner.ThreadState == ThreadState.Running; + public bool IsComputing => PumpRunner?.ThreadState == ThreadState.Running; public bool IsWaitingForData => Pump.IsWaitingForData; public void AttachTracer(IFrameTracer tracer) @@ -184,7 +184,7 @@ namespace Capnp.Rpc connection.Start(); } - connection.PumpRunner.Start(); + connection.PumpRunner!.Start(); } } catch (SocketException) @@ -199,8 +199,13 @@ namespace Capnp.Rpc } } - void SafeJoin(Thread thread) + void SafeJoin(Thread? thread) { + if (thread == null) + { + return; + } + for (int retry = 0; retry < 5; ++retry) { try @@ -332,6 +337,6 @@ namespace Capnp.Rpc /// /// Fires when a new incoming connection was accepted, or when an active connection is closed. /// - public event Action OnConnectionChanged; + public event Action? OnConnectionChanged; } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Vine.cs b/Capnp.Net.Runtime/Rpc/Vine.cs index 47bc10e..52f10c1 100644 --- a/Capnp.Net.Runtime/Rpc/Vine.cs +++ b/Capnp.Net.Runtime/Rpc/Vine.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -69,4 +67,4 @@ namespace Capnp.Rpc base.Dispose(disposing); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/rpc.cs b/Capnp.Net.Runtime/Rpc/rpc.cs index 61139b0..066bd98 100644 --- a/Capnp.Net.Runtime/Rpc/rpc.cs +++ b/Capnp.Net.Runtime/Rpc/rpc.cs @@ -1,4 +1,5 @@ #pragma warning disable CS1591 +#nullable disable using Capnp; using Capnp.Rpc; @@ -2640,4 +2641,6 @@ namespace Capnp.Rpc unimplemented } } -} \ No newline at end of file +} + +#nullable restore \ No newline at end of file diff --git a/Capnp.Net.Runtime/SecurityOptions.cs b/Capnp.Net.Runtime/SecurityOptions.cs index eb0b463..92de4c5 100644 --- a/Capnp.Net.Runtime/SecurityOptions.cs +++ b/Capnp.Net.Runtime/SecurityOptions.cs @@ -15,4 +15,4 @@ /// public static int RecursionLimit { get; set; } = 64; } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/SegmentAllocator.cs b/Capnp.Net.Runtime/SegmentAllocator.cs index 36c67ea..eb591f5 100644 --- a/Capnp.Net.Runtime/SegmentAllocator.cs +++ b/Capnp.Net.Runtime/SegmentAllocator.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; namespace Capnp { @@ -144,4 +143,4 @@ namespace Capnp return true; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/SegmentSlice.cs b/Capnp.Net.Runtime/SegmentSlice.cs index 22f5c9d..8965fc5 100644 --- a/Capnp.Net.Runtime/SegmentSlice.cs +++ b/Capnp.Net.Runtime/SegmentSlice.cs @@ -1,6 +1,4 @@ -using System; - -namespace Capnp +namespace Capnp { /// /// Helper struct to represent the tuple (segment index, offset) @@ -17,4 +15,4 @@ namespace Capnp /// public int Offset; } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/SerializerExtensions.cs b/Capnp.Net.Runtime/SerializerExtensions.cs index d9d384e..84529f4 100644 --- a/Capnp.Net.Runtime/SerializerExtensions.cs +++ b/Capnp.Net.Runtime/SerializerExtensions.cs @@ -338,4 +338,4 @@ namespace Capnp WriteData(d, bitOffset, bits, defaultBits); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/SerializerState.cs b/Capnp.Net.Runtime/SerializerState.cs index 37d0475..4490ada 100644 --- a/Capnp.Net.Runtime/SerializerState.cs +++ b/Capnp.Net.Runtime/SerializerState.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -29,10 +28,10 @@ namespace Capnp return s; } - internal MessageBuilder MsgBuilder { get; set; } - internal ISegmentAllocator Allocator => MsgBuilder?.Allocator; - internal List Caps => MsgBuilder?.Caps; - internal SerializerState Owner { get; set; } + internal MessageBuilder? MsgBuilder { get; set; } + internal ISegmentAllocator? Allocator => MsgBuilder?.Allocator; + internal List? Caps => MsgBuilder?.Caps; + internal SerializerState? Owner { get; set; } internal int OwnerSlot { get; set; } internal uint SegmentIndex { get; set; } internal int Offset { get; set; } @@ -43,7 +42,7 @@ namespace Capnp internal ObjectKind Kind { get; set; } internal uint CapabilityIndex { get; set; } - SerializerState[] _linkedStates; + SerializerState[]? _linkedStates; /// /// Constructs an unbound serializer state. @@ -129,7 +128,7 @@ namespace Capnp if (Owner != null) ts.Bind(Owner, OwnerSlot); else - ts.Bind(MsgBuilder); + ts.Bind(MsgBuilder ?? throw Unbound()); return ts; } @@ -152,8 +151,8 @@ namespace Capnp /// public bool IsAllocated => Offset >= 0; - Span SegmentSpan => IsAllocated ? Allocator.Segments[(int)SegmentIndex].Span : Span.Empty; - Span FarSpan(uint index) => Allocator.Segments[(int)index].Span; + Span SegmentSpan => IsAllocated && Allocator != null ? Allocator.Segments[(int)SegmentIndex].Span : Span.Empty; + Span FarSpan(uint index) => Allocator!.Segments[(int)index].Span; /// /// Given this state describes a struct and is allocated, returns the struct's data section. @@ -181,6 +180,9 @@ namespace Capnp } else { + if (Allocator == null) + throw Unbound(); + SegmentIndex = Owner?.SegmentIndex ?? SegmentIndex; Allocator.Allocate(count, SegmentIndex, out var slice, false); SegmentIndex = slice.SegmentIndex; @@ -191,7 +193,7 @@ namespace Capnp } /// - /// Allocates storage for the underlying object. Does nothing if it is already allocated. From the point the object is allocated, its type cannot by changed + /// Allocates storage for the underlying object. Does nothing if it is already allocated. From the point the object is allocated, its type cannot be changed /// anymore (e.g. changing from struct to list, or modifying the struct's section sizes). /// public void Allocate() @@ -250,6 +252,9 @@ namespace Capnp if (!target.IsAllocated) throw new InvalidOperationException("Target must be allocated before a pointer can be built"); + if (MsgBuilder == null) + throw Unbound(); + try { if (SegmentSpan[offset] != 0) @@ -345,7 +350,7 @@ namespace Capnp { WirePointer farPtr = default; - if (Allocator.Allocate(1, target.SegmentIndex, out var landingPadSlice, true)) + if (Allocator!.Allocate(1, target.SegmentIndex, out var landingPadSlice, true)) { farPtr.SetFarPointer(target.SegmentIndex, landingPadSlice.Offset, false); SegmentSpan[offset] = farPtr; @@ -372,7 +377,7 @@ namespace Capnp } } - internal Rpc.ConsumedCapability DecodeCapPointer(int offset) + internal Rpc.ConsumedCapability? DecodeCapPointer(int offset) { if (offset < 0) throw new IndexOutOfRangeException(nameof(offset)); @@ -455,7 +460,7 @@ namespace Capnp throw new InvalidOperationException("This object cannot own pointers to sub-objects"); } - _linkedStates[slot] = target; + _linkedStates![slot] = target; } /// @@ -476,6 +481,7 @@ namespace Capnp } static InvalidOperationException AlreadySet() => new InvalidOperationException("The object type was already set"); + static InvalidOperationException Unbound() => new InvalidOperationException("This state is not bound to a MessageBuilder"); void VerifyNotYetAllocated() { @@ -654,14 +660,21 @@ namespace Capnp /// Trying to obtain the UTF-8 encoding might throw this exception. /// The object type was already set to something different /// UTF-8 encoding exceeds 2^29-2 bytes - protected void WriteText(string text) + protected void WriteText(string? text) { - byte[] srcBytes = Encoding.UTF8.GetBytes(text); - SetListOfValues(8, srcBytes.Length + 1); - var srcSpan = new ReadOnlySpan(srcBytes); - var dstSpan = ListGetBytes(); - dstSpan = dstSpan.Slice(0, dstSpan.Length - 1); - srcSpan.CopyTo(dstSpan); + if (text == null) + { + VerifyNotYetAllocated(); + } + else + { + byte[] srcBytes = Encoding.UTF8.GetBytes(text); + SetListOfValues(8, srcBytes.Length + 1); + var srcSpan = new ReadOnlySpan(srcBytes); + var dstSpan = ListGetBytes(); + dstSpan = dstSpan.Slice(0, dstSpan.Length - 1); + srcSpan.CopyTo(dstSpan); + } } /// @@ -761,7 +774,7 @@ namespace Capnp if (Kind != ObjectKind.Struct && Kind != ObjectKind.ListOfPointers) throw new InvalidOperationException("This is not a struct or list of pointers"); - ref var state = ref _linkedStates[index]; + ref var state = ref _linkedStates![index]; if (state == null) { @@ -784,12 +797,12 @@ namespace Capnp /// Object at given position is not compatible with the desired target serializer type. /// /// is out of bounds. - public TS TryGetPointer(int index) where TS : SerializerState, new() + public TS? TryGetPointer(int index) where TS : SerializerState, new() { if (Kind != ObjectKind.Struct && Kind != ObjectKind.ListOfPointers) throw new InvalidOperationException("This is not a struct or list of pointers"); - var state = _linkedStates[index]; + var state = _linkedStates![index]; if (state == null) return null; @@ -820,7 +833,7 @@ namespace Capnp /// Object at given position is not compatible with the desired target serializer type. /// /// is out of bounds. - public SerializerState TryGetPointer(int index) => TryGetPointer(index); + public SerializerState? TryGetPointer(int index) => TryGetPointer(index); /// /// Reads text from a struct field or list element. @@ -829,7 +842,7 @@ namespace Capnp /// If the underlying object is a list of pointers: Element index /// String to return in case of null /// The decoded text - public string ReadText(int index, string defaultText = null) + public string? ReadText(int index, string? defaultText = null) { var b = BuildPointer(index); @@ -851,7 +864,7 @@ namespace Capnp /// Object at given position was already set. /// /// is out of bounds. - public void WriteText(int index, string text) + public void WriteText(int index, string? text) { BuildPointer(index).WriteText(text); } @@ -869,7 +882,7 @@ namespace Capnp /// Object at given position was already set. /// /// is out of bounds. - public void WriteText(int index, string text, string defaultText) + public void WriteText(int index, string? text, string defaultText) { BuildPointer(index).WriteText(text ?? defaultText); } @@ -886,11 +899,11 @@ namespace Capnp if (Kind != ObjectKind.ListOfStructs) throw new InvalidOperationException("This is not a list of structs"); - ref var state = ref _linkedStates[index]; + ref var state = ref _linkedStates![index]; if (state == null) { - state = new SerializerState(MsgBuilder); + state = new SerializerState(MsgBuilder!); state.SetStruct(StructDataCount, StructPtrCount); state.SegmentIndex = SegmentIndex; state.Offset = Offset + 1 + index * (StructDataCount + StructPtrCount); @@ -913,12 +926,12 @@ namespace Capnp if (Kind != ObjectKind.ListOfStructs) throw new InvalidOperationException("This is not a list of structs"); - ref var state = ref _linkedStates[index]; + ref var state = ref _linkedStates![index]; if (state == null) { state = new TS(); - state.Bind(MsgBuilder); + state.Bind(MsgBuilder!); state.SetStruct(StructDataCount, StructPtrCount); state.SegmentIndex = SegmentIndex; int stride = StructDataCount + StructPtrCount; @@ -942,19 +955,19 @@ namespace Capnp for (int offset = minOffset; offset < maxOffset; offset++) { - ref var state = ref _linkedStates[offset - minOffset]; + ref var state = ref _linkedStates![offset - minOffset]; if (state == null) { state = new TS(); - state.Bind(MsgBuilder); + state.Bind(MsgBuilder!); state.SetStruct(StructDataCount, StructPtrCount); state.SegmentIndex = SegmentIndex; state.Offset = offset; } } - return _linkedStates.LazyListSelect(ts => (TS)ts); + return _linkedStates!.LazyListSelect(ts => (TS)ts); } /// @@ -1240,7 +1253,7 @@ namespace Capnp /// The low-level capability object to provide. /// Index of the given capability in the capability table /// The underlying message builder was not configured for capability table support. - public uint ProvideCapability(Rpc.ConsumedCapability capability) + public uint ProvideCapability(Rpc.ConsumedCapability? capability) { if (Caps == null) throw new InvalidOperationException("Underlying MessageBuilder was not enabled to support capabilities"); @@ -1279,7 +1292,7 @@ namespace Capnp /// /// Index of the given capability in the capability table /// The underlying message builder was not configured for capability table support. - public uint ProvideCapability(object obj) + public uint ProvideCapability(object? obj) { if (obj == null) return ProvideCapability(default(Rpc.ConsumedCapability)); @@ -1352,7 +1365,7 @@ namespace Capnp } } - internal Rpc.ConsumedCapability StructReadRawCap(int index) + internal Rpc.ConsumedCapability? StructReadRawCap(int index) { if (Kind != ObjectKind.Struct && Kind != ObjectKind.Nil) throw new InvalidOperationException("Allowed on structs only"); @@ -1372,7 +1385,7 @@ namespace Capnp /// is out of range. /// The desired interface does not qualify as capability interface () /// This state does not represent a struct. - public T ReadCap(int slot) where T : class + public T? ReadCap(int slot) where T : class { var cap = StructReadRawCap(slot); return Rpc.CapabilityReflection.CreateProxy(cap) as T; @@ -1391,4 +1404,4 @@ namespace Capnp return new Rpc.BareProxy(cap); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/TypeIdAttribute.cs b/Capnp.Net.Runtime/TypeIdAttribute.cs index 098dd03..8b6e2bb 100644 --- a/Capnp.Net.Runtime/TypeIdAttribute.cs +++ b/Capnp.Net.Runtime/TypeIdAttribute.cs @@ -24,4 +24,4 @@ namespace Capnp /// public ulong Id { get; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/UtilityExtensions.cs b/Capnp.Net.Runtime/UtilityExtensions.cs index 745e202..90a4acb 100644 --- a/Capnp.Net.Runtime/UtilityExtensions.cs +++ b/Capnp.Net.Runtime/UtilityExtensions.cs @@ -4,8 +4,8 @@ using System.Threading.Tasks; namespace Capnp { - internal static class UtilityExtensions - { + internal static class UtilityExtensions + { /// /// This method exists until NET Standard 2.1 is released /// @@ -23,7 +23,7 @@ namespace Capnp return true; } #else - public static bool ReplacementTryAdd(this Dictionary thisDict, K key, V value) => thisDict.TryAdd(key, value); + public static bool ReplacementTryAdd(this Dictionary thisDict, K key, V value) where K: struct => thisDict.TryAdd(key, value); #endif /// @@ -40,14 +40,16 @@ namespace Capnp { if (!thisDict.ContainsKey(key)) { - value = default; + value = default!; // OK here since .NET Standard 2.0 does not support (non-)nullability anyway. return false; } value = thisDict[key]; return thisDict.Remove(key); } #else +#pragma warning disable CS8714 public static bool ReplacementTryRemove(this Dictionary thisDict, K key, out V value) => thisDict.Remove(key, out value); +#pragma warning restore CS8714 #endif /// diff --git a/Capnp.Net.Runtime/WireFrame.cs b/Capnp.Net.Runtime/WireFrame.cs index 0de1f7e..3705b0a 100644 --- a/Capnp.Net.Runtime/WireFrame.cs +++ b/Capnp.Net.Runtime/WireFrame.cs @@ -21,4 +21,4 @@ namespace Capnp Segments = segments; } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/WirePointer.cs b/Capnp.Net.Runtime/WirePointer.cs index 9b41a67..197886e 100644 --- a/Capnp.Net.Runtime/WirePointer.cs +++ b/Capnp.Net.Runtime/WirePointer.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Capnp { @@ -227,4 +225,4 @@ namespace Capnp _ptrData = ((ulong)index << 32) | (ulong)PointerKind.Other; } } -} +} \ No newline at end of file diff --git a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj index 55dba85..77462b1 100644 --- a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj +++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.0 CapnpC.CSharp.Generator.Tests false @@ -10,15 +10,15 @@ - - + + - - - + + + diff --git a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature index 3485d84..6d8d53f 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature @@ -49,11 +49,25 @@ Scenario: Multiple errors Scenario Outline: Valid generator output Given I have a binary code generator request + And I enable generation of nullable reference types according to + And I enable the compiler support of nullable reference types according to When I invoke capnpc-csharp - Then the invocation must succeed and the generated code must compile + Then the invocation must succeed and attempting to compile the generated code gives Examples: - | bin | - | Issue19.capnp.bin | - | Issue21.capnp.bin | - | Issue22.capnp.bin | \ No newline at end of file + | bin | nullablegen | nullablesupp | outcome | + | test.capnp.bin | false | false | success | + | test.capnp.bin | true | false | errors | + | test.capnp.bin | false | true | warnings | + | test.capnp.bin | true | true | success | + | Issue19.capnp.bin | false | false | success | + | Issue21.capnp.bin | false | false | success | + | Issue22.capnp.bin | false | false | success | + | NullableDisable.capnp.bin | true | false | success | + | NullableDisable.capnp.bin | true | true | warnings | + | NullableEnable.capnp.bin | false | true | success | + | NullableEnable.capnp.bin | false | false | errors | + | NullableDisable2.capnp.bin | false | false | errors | + | NullableDisable2.capnp.bin | false | true | success | + | NullableEnable2.capnp.bin | false | false | errors | + | NullableEnable2.capnp.bin | false | true | success | \ 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 de6a0cc..3fa5c2c 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs @@ -1,8 +1,8 @@ // ------------------------------------------------------------------------------ // // This code was generated by SpecFlow (http://www.specflow.org/). -// SpecFlow Version:3.0.0.0 -// SpecFlow Generator Version:3.0.0.0 +// SpecFlow Version:3.1.0.0 +// SpecFlow Generator Version:3.1.0.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -13,9 +13,11 @@ namespace CapnpC.CSharp.Generator.Tests { using TechTalk.SpecFlow; + using System; + using System.Linq; - [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.0.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "3.1.0.0")] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()] public partial class CodeGeneratorFeature @@ -25,6 +27,8 @@ namespace CapnpC.CSharp.Generator.Tests private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext; + private string[] _featureTags = ((string[])(null)); + #line 1 "CodeGenerator.feature" #line hidden @@ -68,7 +72,7 @@ namespace CapnpC.CSharp.Generator.Tests } [Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()] - public virtual void ScenarioTearDown() + public virtual void TestTearDown() { testRunner.OnScenarioEnd(); } @@ -94,35 +98,78 @@ namespace CapnpC.CSharp.Generator.Tests [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] public virtual void ComparingBackendOutputWithReference() { + string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Comparing backend output with reference", null, ((string[])(null))); #line 6 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 7 testRunner.Given("I have a binary code generator request \"test.capnp.bin\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden #line 8 testRunner.And("my reference output is \"test.cs\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 9 testRunner.When("I invoke capnpc-csharp", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden #line 10 testRunner.Then("the generated output must match the reference", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden + } this.ScenarioCleanup(); } public virtual void InvalidBinaryCodeGeneratorRequests(string bin, string[] exampleTags) { + string[] tagsOfScenario = exampleTags; TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Invalid binary code generator requests", null, exampleTags); #line 12 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 13 testRunner.Given(string.Format("I have a binary code generator request {0}", bin), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden #line 14 testRunner.When("I invoke capnpc-csharp", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden #line 15 testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden + } this.ScenarioCleanup(); } @@ -155,19 +202,41 @@ this.InvalidBinaryCodeGeneratorRequests("test.cs", ((string[])(null))); [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] public virtual void CombiningFrontendAndBackend() { + string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Combining frontend and backend", null, ((string[])(null))); #line 22 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 23 testRunner.Given("capnp.exe is installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden #line 24 testRunner.And("I have a schema \"UnitTest1.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 25 testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden #line 26 testRunner.Then("code generation must succeed", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden + } this.ScenarioCleanup(); } @@ -176,19 +245,41 @@ this.ScenarioInitialize(scenarioInfo); [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] public virtual void MissingFrontend() { + string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Missing frontend", null, ((string[])(null))); #line 28 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 29 testRunner.Given("capnp.exe is not installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden #line 30 testRunner.And("I have a schema \"UnitTest1.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 31 testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden #line 32 testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden + } this.ScenarioCleanup(); } @@ -197,23 +288,47 @@ this.ScenarioInitialize(scenarioInfo); [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] public virtual void SchemaWithoutID() { + string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Schema without ID", null, ((string[])(null))); #line 34 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 35 testRunner.Given("capnp.exe is installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden #line 36 testRunner.And("I have a schema \"Empty1.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 37 testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden #line 38 testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden #line 39 testRunner.And("the reason must be bad input", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 40 testRunner.And("the error output must contain \"File does not declare an ID\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); #line hidden + } this.ScenarioCleanup(); } @@ -222,75 +337,316 @@ this.ScenarioInitialize(scenarioInfo); [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] public virtual void MultipleErrors() { + string[] tagsOfScenario = ((string[])(null)); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Multiple errors", null, ((string[])(null))); #line 42 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 43 testRunner.Given("capnp.exe is installed on my system", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden #line 44 testRunner.And("I have a schema \"invalid.capnp\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 45 testRunner.When("I try to generate code from that schema", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden #line 46 testRunner.Then("the invocation must fail", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden #line 47 testRunner.And("the reason must be bad input", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden #line 48 testRunner.And("the error output must contain multiple messages", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); #line hidden + } this.ScenarioCleanup(); } - public virtual void ValidGeneratorOutput(string bin, string[] exampleTags) + public virtual void ValidGeneratorOutput(string bin, string nullablegen, string nullablesupp, string outcome, string[] exampleTags) { + string[] tagsOfScenario = exampleTags; TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Valid generator output", null, exampleTags); #line 50 this.ScenarioInitialize(scenarioInfo); - this.ScenarioStart(); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); #line 51 testRunner.Given(string.Format("I have a binary code generator request {0}", bin), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); -#line 52 - testRunner.When("I invoke capnpc-csharp", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); -#line 53 - testRunner.Then("the invocation must succeed and the generated code must compile", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden +#line 52 + testRunner.And(string.Format("I enable generation of nullable reference types according to {0}", nullablegen), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 53 + testRunner.And(string.Format("I enable the compiler support of nullable reference types according to {0}", nullablesupp), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 54 + testRunner.When("I invoke capnpc-csharp", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 55 + testRunner.Then(string.Format("the invocation must succeed and attempting to compile the generated code gives {0" + + "}", outcome), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } this.ScenarioCleanup(); } [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Issue19.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 0")] [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Issue19.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 0")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "test.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant0() + { +#line 50 +this.ValidGeneratorOutput("test.capnp.bin", "false", "false", "success", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 1")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "test.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "errors")] + public virtual void ValidGeneratorOutput_Variant1() + { +#line 50 +this.ValidGeneratorOutput("test.capnp.bin", "true", "false", "errors", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 2")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 2")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "test.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "warnings")] + public virtual void ValidGeneratorOutput_Variant2() + { +#line 50 +this.ValidGeneratorOutput("test.capnp.bin", "false", "true", "warnings", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 3")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 3")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "test.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant3() + { +#line 50 +this.ValidGeneratorOutput("test.capnp.bin", "true", "true", "success", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 4")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 4")] [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "Issue19.capnp.bin")] - public virtual void ValidGeneratorOutput_Issue19_Capnp_Bin() + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant4() { #line 50 -this.ValidGeneratorOutput("Issue19.capnp.bin", ((string[])(null))); +this.ValidGeneratorOutput("Issue19.capnp.bin", "false", "false", "success", ((string[])(null))); #line hidden } [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Issue21.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 5")] [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Issue21.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 5")] [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "Issue21.capnp.bin")] - public virtual void ValidGeneratorOutput_Issue21_Capnp_Bin() + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant5() { #line 50 -this.ValidGeneratorOutput("Issue21.capnp.bin", ((string[])(null))); +this.ValidGeneratorOutput("Issue21.capnp.bin", "false", "false", "success", ((string[])(null))); #line hidden } [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] - [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Issue22.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 6")] [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] - [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Issue22.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 6")] [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "Issue22.capnp.bin")] - public virtual void ValidGeneratorOutput_Issue22_Capnp_Bin() + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant6() { #line 50 -this.ValidGeneratorOutput("Issue22.capnp.bin", ((string[])(null))); +this.ValidGeneratorOutput("Issue22.capnp.bin", "false", "false", "success", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 7")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 7")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableDisable.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant7() + { +#line 50 +this.ValidGeneratorOutput("NullableDisable.capnp.bin", "true", "false", "success", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 8")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 8")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableDisable.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "warnings")] + public virtual void ValidGeneratorOutput_Variant8() + { +#line 50 +this.ValidGeneratorOutput("NullableDisable.capnp.bin", "true", "true", "warnings", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 9")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 9")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableEnable.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant9() + { +#line 50 +this.ValidGeneratorOutput("NullableEnable.capnp.bin", "false", "true", "success", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 10")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 10")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableEnable.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "errors")] + public virtual void ValidGeneratorOutput_Variant10() + { +#line 50 +this.ValidGeneratorOutput("NullableEnable.capnp.bin", "false", "false", "errors", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 11")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 11")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableDisable2.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "errors")] + public virtual void ValidGeneratorOutput_Variant11() + { +#line 50 +this.ValidGeneratorOutput("NullableDisable2.capnp.bin", "false", "false", "errors", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 12")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 12")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableDisable2.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant12() + { +#line 50 +this.ValidGeneratorOutput("NullableDisable2.capnp.bin", "false", "true", "success", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 13")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 13")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableEnable2.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "errors")] + public virtual void ValidGeneratorOutput_Variant13() + { +#line 50 +this.ValidGeneratorOutput("NullableEnable2.capnp.bin", "false", "false", "errors", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Variant 14")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Variant 14")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "NullableEnable2.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablegen", "false")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:nullablesupp", "true")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:outcome", "success")] + public virtual void ValidGeneratorOutput_Variant14() + { +#line 50 +this.ValidGeneratorOutput("NullableEnable2.capnp.bin", "false", "true", "success", ((string[])(null))); #line hidden } } diff --git a/CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs b/CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs index 162e09a..4ccbd9b 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs +++ b/CapnpC.CSharp.Generator.Tests/CodeGeneratorUnitTests.cs @@ -22,7 +22,7 @@ namespace CapnpC.CSharp.Generator.Tests [TestMethod] public void Test01NestedClash() { - var (model, codegen) = LoadAndGenerate("UnitTest1.capnp.bin"); + var (model, codegen, _) = LoadAndGenerate("UnitTest1.capnp.bin"); var structFoo = GetTypeDef(0x93db6ba5509bac24, model); var names = codegen.GetNames(); var fieldName = names.GetCodeIdentifier(structFoo.Fields[0]).ToString(); @@ -51,7 +51,7 @@ namespace CapnpC.CSharp.Generator.Tests [TestMethod] public void Test10ImportedNamespaces() { - var (model, codegen) = LoadAndGenerate("UnitTest10.capnp.bin"); + var (model, codegen, _) = LoadAndGenerate("UnitTest10.capnp.bin"); var outerTypeDef = GetGeneratedFile("UnitTest10.capnp", model).NestedTypes.First(); var outerType = Model.Types.FromDefinition(outerTypeDef); var innerType = outerTypeDef.Fields[0].Type; @@ -81,6 +81,60 @@ namespace CapnpC.CSharp.Generator.Tests LoadAndGenerate("UnitTest12.capnp.bin"); } + [TestMethod] + public void Test13CSharpNamespace() + { + var (model, _, _) = LoadAndGenerate("UnitTest13.capnp.bin"); + var outerTypeDef = GetGeneratedFile("UnitTest13.capnp", model).NestedTypes.First(); + string[] outerNamespace = { "Foo", "Bar", "Baz" }; + CollectionAssert.AreEqual(outerNamespace, (outerTypeDef.DeclaringElement as Model.GenFile).Namespace); + } + + [TestMethod] + public void Test14CSharpNamespacePrecedesCxxNamespace() + { + var (model, _, _) = LoadAndGenerate("UnitTest14.capnp.bin"); + var outerTypeDef = GetGeneratedFile("UnitTest14.capnp", model).NestedTypes.First(); + string[] outerNamespace = { "Foo", "Bar", "Baz" }; + CollectionAssert.AreEqual(outerNamespace, (outerTypeDef.DeclaringElement as Model.GenFile).Namespace); + } + + [TestMethod] + public void Test15CSharpMemberNames() + { + var (_, _, code) = LoadAndGenerate("UnitTest15.capnp.bin"); + try + { + Assert.IsTrue(code.Contains("CsStruct", StringComparison.Ordinal), "Generated code must contain C# struct name"); + Assert.IsFalse(code.Contains("SomeStruct", StringComparison.Ordinal), "Generated code must not contain original struct name"); + Assert.IsTrue(code.Contains("CsField", StringComparison.Ordinal), "Generated code must contain C# field name"); + Assert.IsFalse(code.Contains("someField", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original field name"); + Assert.IsTrue(code.Contains("CsUnion", StringComparison.Ordinal), "Generated code must contain C# union name"); + Assert.IsFalse(code.Contains("someUnion", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original union name"); + Assert.IsTrue(code.Contains("CsGroup", StringComparison.Ordinal), "Generated code must contain C# group name"); + Assert.IsFalse(code.Contains("someGroup", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original group name"); + Assert.IsTrue(code.Contains("CsEnum", StringComparison.Ordinal), "Generated code must contain C# enum name"); + Assert.IsFalse(code.Contains("SomeEnum", StringComparison.Ordinal), "Generated code must not contain original enum name"); + Assert.IsTrue(code.Contains("CsEnumerant", StringComparison.Ordinal), "Generated code must contain C# enumerant name"); + Assert.IsFalse(code.Contains("someEnumerant", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original enumerant name"); + Assert.IsTrue(code.Contains("CsField", StringComparison.Ordinal), "Generated code must contain C# field name"); + Assert.IsFalse(code.Contains("someField", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original field name"); + Assert.IsTrue(code.Contains("CsInterface", StringComparison.Ordinal), "Generated code must contain C# interface name"); + Assert.IsFalse(code.Contains("SomeInterface", StringComparison.Ordinal), "Generated code must not contain original interface name"); + Assert.IsTrue(code.Contains("CsMethod", StringComparison.Ordinal), "Generated code must contain C# method name"); + Assert.IsFalse(code.Contains("someMethod", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original method name"); + Assert.IsTrue(code.Contains("CsField", StringComparison.Ordinal), "Generated code must contain C# field name"); + Assert.IsFalse(code.Contains("someField", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original field name"); + Assert.IsTrue(code.Contains("CsResult", StringComparison.Ordinal), "Generated code must contain C# method parameter name"); + Assert.IsFalse(code.Contains("someResult", StringComparison.OrdinalIgnoreCase), "Generated code must not contain original method parameter name"); + } + catch (AssertFailedException) + { + Console.WriteLine(code); + throw; + } + } + [TestMethod] public void Test20AnnotationAndConst() { @@ -93,15 +147,20 @@ namespace CapnpC.CSharp.Generator.Tests LoadAndGenerate("schema-with-offsets.capnp.bin"); } - static (Model.SchemaModel, CodeGen.CodeGenerator) LoadAndGenerate(string inputName) + static (Model.SchemaModel, CodeGen.CodeGenerator, string) LoadAndGenerate(string inputName) { var model = Load(inputName); var codegen = new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions()); var code = model.FilesToGenerate.Select(f => codegen.Transform(f)).ToArray(); - Assert.IsTrue(Util.InlineAssemblyCompiler.TryCompileCapnp(code), "Compilation was not successful"); + Assert.AreEqual( + Util.InlineAssemblyCompiler.CompileSummary.Success, + Util.InlineAssemblyCompiler.TryCompileCapnp( + Microsoft.CodeAnalysis.NullableContextOptions.Disable, + code), + "Compilation was not successful with no warnings"); - return (model, codegen); + return (model, codegen, code[0]); } static Model.GenFile GetGeneratedFile(string name, Model.SchemaModel model) diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin new file mode 100644 index 0000000..14f05c8 Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin new file mode 100644 index 0000000..dcc032a Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableDisable2.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin new file mode 100644 index 0000000..4a92c1a Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin new file mode 100644 index 0000000..45ae2c0 Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/NullableEnable2.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest13.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest13.capnp.bin new file mode 100644 index 0000000..bcf65cb Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest13.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest14.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest14.capnp.bin new file mode 100644 index 0000000..0e48988 Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest14.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest15.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest15.capnp.bin new file mode 100644 index 0000000..2cd9b98 Binary files /dev/null and b/CapnpC.CSharp.Generator.Tests/Embedded Resources/UnitTest15.capnp.bin differ diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs index 84c9f1d..3a90610 100644 --- a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs +++ b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs @@ -56,7 +56,7 @@ namespace Capnproto_test.Capnp.Test Float64List = reader.Float64List; TextList = reader.TextList; DataList = reader.DataList; - StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + StructList = reader.StructList?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); EnumList = reader.EnumList; InterfaceList = reader.InterfaceList; applyDefaults(); @@ -581,7 +581,7 @@ namespace Capnproto_test.Capnp.Test Float64List = reader.Float64List; TextList = reader.TextList; DataList = reader.DataList; - StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + StructList = reader.StructList?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); EnumList = reader.EnumList; InterfaceList = reader.InterfaceList; applyDefaults(); @@ -1185,7 +1185,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); AnyStructField = CapnpSerializable.Create(reader.AnyStructField); - AnyListField = reader.AnyListField.ToReadOnlyList(_ => (object)_); + AnyListField = reader.AnyListField?.ToReadOnlyList(_ => (object)_); CapabilityField = reader.CapabilityField; applyDefaults(); } @@ -1454,10 +1454,10 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Union0 = CapnpSerializable.Create(reader.Union0); - Union1 = CapnpSerializable.Create(reader.Union1); - Union2 = CapnpSerializable.Create(reader.Union2); - Union3 = CapnpSerializable.Create(reader.Union3); + Union0 = CapnpSerializable.Create(reader.Union0); + Union1 = CapnpSerializable.Create(reader.Union1); + Union2 = CapnpSerializable.Create(reader.Union2); + Union3 = CapnpSerializable.Create(reader.Union3); Bit0 = reader.Bit0; Bit2 = reader.Bit2; Bit3 = reader.Bit3; @@ -1494,25 +1494,25 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestUnion.@union0 Union0 + public Capnproto_test.Capnp.Test.TestUnion.union0 Union0 { get; set; } - public Capnproto_test.Capnp.Test.TestUnion.@union1 Union1 + public Capnproto_test.Capnp.Test.TestUnion.union1 Union1 { get; set; } - public Capnproto_test.Capnp.Test.TestUnion.@union2 Union2 + public Capnproto_test.Capnp.Test.TestUnion.union2 Union2 { get; set; } - public Capnproto_test.Capnp.Test.TestUnion.@union3 Union3 + public Capnproto_test.Capnp.Test.TestUnion.union3 Union3 { get; set; @@ -1577,10 +1577,10 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @union0.READER Union0 => new @union0.READER(ctx); - public @union1.READER Union1 => new @union1.READER(ctx); - public @union2.READER Union2 => new @union2.READER(ctx); - public @union3.READER Union3 => new @union3.READER(ctx); + public union0.READER Union0 => new union0.READER(ctx); + public union1.READER Union1 => new union1.READER(ctx); + public union2.READER Union2 => new union2.READER(ctx); + public union3.READER Union3 => new union3.READER(ctx); public bool Bit0 => ctx.ReadDataBool(128UL, false); public bool Bit2 => ctx.ReadDataBool(130UL, false); public bool Bit3 => ctx.ReadDataBool(131UL, false); @@ -1598,24 +1598,24 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(8, 2); } - public @union0.WRITER Union0 + public union0.WRITER Union0 { - get => Rewrap<@union0.WRITER>(); + get => Rewrap(); } - public @union1.WRITER Union1 + public union1.WRITER Union1 { - get => Rewrap<@union1.WRITER>(); + get => Rewrap(); } - public @union2.WRITER Union2 + public union2.WRITER Union2 { - get => Rewrap<@union2.WRITER>(); + get => Rewrap(); } - public @union3.WRITER Union3 + public union3.WRITER Union3 { - get => Rewrap<@union3.WRITER>(); + get => Rewrap(); } public bool Bit0 @@ -1668,7 +1668,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfc76a82eecb7a718UL)] - public class @union0 : ICapnpSerializable + public class union0 : ICapnpSerializable { public const UInt64 typeId = 0xfc76a82eecb7a718UL; public enum WHICH : ushort @@ -2088,7 +2088,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xee0a6b99b7dc7ab2UL)] - public class @union1 : ICapnpSerializable + public class union1 : ICapnpSerializable { public const UInt64 typeId = 0xee0a6b99b7dc7ab2UL; public enum WHICH : ushort @@ -2670,7 +2670,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xafc5fd419f0d66d4UL)] - public class @union2 : ICapnpSerializable + public class union2 : ICapnpSerializable { public const UInt64 typeId = 0xafc5fd419f0d66d4UL; public enum WHICH : ushort @@ -2885,7 +2885,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa2fb022ec7f30053UL)] - public class @union3 : ICapnpSerializable + public class union3 : ICapnpSerializable { public const UInt64 typeId = 0xa2fb022ec7f30053UL; public enum WHICH : ushort @@ -3288,7 +3288,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Outer = CapnpSerializable.Create(reader.Outer); + Outer = CapnpSerializable.Create(reader.Outer); applyDefaults(); } @@ -3306,7 +3306,7 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestUnionInUnion.@outer Outer + public Capnproto_test.Capnp.Test.TestUnionInUnion.outer Outer { get; set; @@ -3323,7 +3323,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @outer.READER Outer => new @outer.READER(ctx); + public outer.READER Outer => new outer.READER(ctx); } public class WRITER : SerializerState @@ -3333,14 +3333,14 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(2, 0); } - public @outer.WRITER Outer + public outer.WRITER Outer { - get => Rewrap<@outer.WRITER>(); + get => Rewrap(); } } [TypeId(0xd005f6c63707670cUL)] - public class @outer : ICapnpSerializable + public class outer : ICapnpSerializable { public const UInt64 typeId = 0xd005f6c63707670cUL; public enum WHICH : ushort @@ -3356,7 +3356,7 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.Inner: - Inner = CapnpSerializable.Create(reader.Inner); + Inner = CapnpSerializable.Create(reader.Inner); break; case WHICH.Baz: Baz = reader.Baz; @@ -3411,9 +3411,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestUnionInUnion.@outer.@inner Inner + public Capnproto_test.Capnp.Test.TestUnionInUnion.outer.inner Inner { - get => _which == WHICH.Inner ? (Capnproto_test.Capnp.Test.TestUnionInUnion.@outer.@inner)_content : null; + get => _which == WHICH.Inner ? (Capnproto_test.Capnp.Test.TestUnionInUnion.outer.inner)_content : null; set { _which = WHICH.Inner; @@ -3443,7 +3443,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(64U, (ushort)0); - public @inner.READER Inner => which == WHICH.Inner ? new @inner.READER(ctx) : default; + public inner.READER Inner => which == WHICH.Inner ? new inner.READER(ctx) : default; public int Baz => which == WHICH.Baz ? ctx.ReadDataInt(0UL, 0) : default; } @@ -3459,9 +3459,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(64U, (ushort)value, (ushort)0); } - public @inner.WRITER Inner + public inner.WRITER Inner { - get => which == WHICH.Inner ? Rewrap<@inner.WRITER>() : default; + get => which == WHICH.Inner ? Rewrap() : default; } public int Baz @@ -3472,7 +3472,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xff9ce111c6f8e5dbUL)] - public class @inner : ICapnpSerializable + public class inner : ICapnpSerializable { public const UInt64 typeId = 0xff9ce111c6f8e5dbUL; public enum WHICH : ushort @@ -3614,7 +3614,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Groups = CapnpSerializable.Create(reader.Groups); + Groups = CapnpSerializable.Create(reader.Groups); applyDefaults(); } @@ -3632,7 +3632,7 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestGroups.@groups Groups + public Capnproto_test.Capnp.Test.TestGroups.groups Groups { get; set; @@ -3649,7 +3649,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @groups.READER Groups => new @groups.READER(ctx); + public groups.READER Groups => new groups.READER(ctx); } public class WRITER : SerializerState @@ -3659,14 +3659,14 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(2, 2); } - public @groups.WRITER Groups + public groups.WRITER Groups { - get => Rewrap<@groups.WRITER>(); + get => Rewrap(); } } [TypeId(0xe22ae74ff9113268UL)] - public class @groups : ICapnpSerializable + public class groups : ICapnpSerializable { public const UInt64 typeId = 0xe22ae74ff9113268UL; public enum WHICH : ushort @@ -3683,13 +3683,13 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.Foo: - Foo = CapnpSerializable.Create(reader.Foo); + Foo = CapnpSerializable.Create(reader.Foo); break; case WHICH.Baz: - Baz = CapnpSerializable.Create(reader.Baz); + Baz = CapnpSerializable.Create(reader.Baz); break; case WHICH.Bar: - Bar = CapnpSerializable.Create(reader.Bar); + Bar = CapnpSerializable.Create(reader.Bar); break; } @@ -3747,9 +3747,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestGroups.@groups.@foo Foo + public Capnproto_test.Capnp.Test.TestGroups.groups.foo Foo { - get => _which == WHICH.Foo ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@foo)_content : null; + get => _which == WHICH.Foo ? (Capnproto_test.Capnp.Test.TestGroups.groups.foo)_content : null; set { _which = WHICH.Foo; @@ -3757,9 +3757,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestGroups.@groups.@baz Baz + public Capnproto_test.Capnp.Test.TestGroups.groups.baz Baz { - get => _which == WHICH.Baz ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@baz)_content : null; + get => _which == WHICH.Baz ? (Capnproto_test.Capnp.Test.TestGroups.groups.baz)_content : null; set { _which = WHICH.Baz; @@ -3767,9 +3767,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestGroups.@groups.@bar Bar + public Capnproto_test.Capnp.Test.TestGroups.groups.bar Bar { - get => _which == WHICH.Bar ? (Capnproto_test.Capnp.Test.TestGroups.@groups.@bar)_content : null; + get => _which == WHICH.Bar ? (Capnproto_test.Capnp.Test.TestGroups.groups.bar)_content : null; set { _which = WHICH.Bar; @@ -3789,9 +3789,9 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(32U, (ushort)0); - public @foo.READER Foo => which == WHICH.Foo ? new @foo.READER(ctx) : default; - public @baz.READER Baz => which == WHICH.Baz ? new @baz.READER(ctx) : default; - public @bar.READER Bar => which == WHICH.Bar ? new @bar.READER(ctx) : default; + public foo.READER Foo => which == WHICH.Foo ? new foo.READER(ctx) : default; + public baz.READER Baz => which == WHICH.Baz ? new baz.READER(ctx) : default; + public bar.READER Bar => which == WHICH.Bar ? new bar.READER(ctx) : default; } public class WRITER : SerializerState @@ -3806,24 +3806,24 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(32U, (ushort)value, (ushort)0); } - public @foo.WRITER Foo + public foo.WRITER Foo { - get => which == WHICH.Foo ? Rewrap<@foo.WRITER>() : default; + get => which == WHICH.Foo ? Rewrap() : default; } - public @baz.WRITER Baz + public baz.WRITER Baz { - get => which == WHICH.Baz ? Rewrap<@baz.WRITER>() : default; + get => which == WHICH.Baz ? Rewrap() : default; } - public @bar.WRITER Bar + public bar.WRITER Bar { - get => which == WHICH.Bar ? Rewrap<@bar.WRITER>() : default; + get => which == WHICH.Bar ? Rewrap() : default; } } [TypeId(0xf5fcba89c0c1196fUL)] - public class @foo : ICapnpSerializable + public class foo : ICapnpSerializable { public const UInt64 typeId = 0xf5fcba89c0c1196fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -3912,7 +3912,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf0fa30304066a4b3UL)] - public class @baz : ICapnpSerializable + public class baz : ICapnpSerializable { public const UInt64 typeId = 0xf0fa30304066a4b3UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4001,7 +4001,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb727c0d0091a001dUL)] - public class @bar : ICapnpSerializable + public class bar : ICapnpSerializable { public const UInt64 typeId = 0xb727c0d0091a001dUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4098,8 +4098,8 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Group1 = CapnpSerializable.Create(reader.Group1); - Group2 = CapnpSerializable.Create(reader.Group2); + Group1 = CapnpSerializable.Create(reader.Group1); + Group2 = CapnpSerializable.Create(reader.Group2); applyDefaults(); } @@ -4118,13 +4118,13 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1 Group1 + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group1 Group1 { get; set; } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2 Group2 + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group2 Group2 { get; set; @@ -4141,8 +4141,8 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @group1.READER Group1 => new @group1.READER(ctx); - public @group2.READER Group2 => new @group2.READER(ctx); + public group1.READER Group1 => new group1.READER(ctx); + public group2.READER Group2 => new group2.READER(ctx); } public class WRITER : SerializerState @@ -4152,19 +4152,19 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(6, 6); } - public @group1.WRITER Group1 + public group1.WRITER Group1 { - get => Rewrap<@group1.WRITER>(); + get => Rewrap(); } - public @group2.WRITER Group2 + public group2.WRITER Group2 { - get => Rewrap<@group2.WRITER>(); + get => Rewrap(); } } [TypeId(0xc7485a3516c7d3c8UL)] - public class @group1 : ICapnpSerializable + public class group1 : ICapnpSerializable { public const UInt64 typeId = 0xc7485a3516c7d3c8UL; public enum WHICH : ushort @@ -4184,7 +4184,7 @@ namespace Capnproto_test.Capnp.Test Qux = reader.Qux; break; case WHICH.Corge: - Corge = CapnpSerializable.Create(reader.Corge); + Corge = CapnpSerializable.Create(reader.Corge); break; case WHICH.Fred: Fred = reader.Fred; @@ -4274,9 +4274,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1.@corge Corge + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group1.corge Corge { - get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.@group1.@corge)_content : null; + get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.group1.corge)_content : null; set { _which = WHICH.Corge; @@ -4315,7 +4315,7 @@ namespace Capnproto_test.Capnp.Test public uint Foo => ctx.ReadDataUInt(0UL, 0U); public ulong Bar => ctx.ReadDataULong(64UL, 0UL); public ushort Qux => which == WHICH.Qux ? ctx.ReadDataUShort(192UL, (ushort)0) : default; - public @corge.READER Corge => which == WHICH.Corge ? new @corge.READER(ctx) : default; + public corge.READER Corge => which == WHICH.Corge ? new corge.READER(ctx) : default; public string Waldo => ctx.ReadText(0, ""); public string Fred => which == WHICH.Fred ? ctx.ReadText(2, "") : default; } @@ -4350,9 +4350,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(192UL, value, (ushort)0); } - public @corge.WRITER Corge + public corge.WRITER Corge { - get => which == WHICH.Corge ? Rewrap<@corge.WRITER>() : default; + get => which == WHICH.Corge ? Rewrap() : default; } public string Waldo @@ -4369,7 +4369,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdb0afd413f4a313aUL)] - public class @corge : ICapnpSerializable + public class corge : ICapnpSerializable { public const UInt64 typeId = 0xdb0afd413f4a313aUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4474,7 +4474,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xcc85a335569990e9UL)] - public class @group2 : ICapnpSerializable + public class group2 : ICapnpSerializable { public const UInt64 typeId = 0xcc85a335569990e9UL; public enum WHICH : ushort @@ -4494,7 +4494,7 @@ namespace Capnproto_test.Capnp.Test Qux = reader.Qux; break; case WHICH.Corge: - Corge = CapnpSerializable.Create(reader.Corge); + Corge = CapnpSerializable.Create(reader.Corge); break; case WHICH.Fred: Fred = reader.Fred; @@ -4584,9 +4584,9 @@ namespace Capnproto_test.Capnp.Test } } - public Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2.@corge Corge + public Capnproto_test.Capnp.Test.TestInterleavedGroups.group2.corge Corge { - get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.@group2.@corge)_content : null; + get => _which == WHICH.Corge ? (Capnproto_test.Capnp.Test.TestInterleavedGroups.group2.corge)_content : null; set { _which = WHICH.Corge; @@ -4625,7 +4625,7 @@ namespace Capnproto_test.Capnp.Test public uint Foo => ctx.ReadDataUInt(32UL, 0U); public ulong Bar => ctx.ReadDataULong(128UL, 0UL); public ushort Qux => which == WHICH.Qux ? ctx.ReadDataUShort(208UL, (ushort)0) : default; - public @corge.READER Corge => which == WHICH.Corge ? new @corge.READER(ctx) : default; + public corge.READER Corge => which == WHICH.Corge ? new corge.READER(ctx) : default; public string Waldo => ctx.ReadText(1, ""); public string Fred => which == WHICH.Fred ? ctx.ReadText(3, "") : default; } @@ -4660,9 +4660,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(208UL, value, (ushort)0); } - public @corge.WRITER Corge + public corge.WRITER Corge { - get => which == WHICH.Corge ? Rewrap<@corge.WRITER>() : default; + get => which == WHICH.Corge ? Rewrap() : default; } public string Waldo @@ -4679,7 +4679,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa017f0366827ee37UL)] - public class @corge : ICapnpSerializable + public class corge : ICapnpSerializable { public const UInt64 typeId = 0xa017f0366827ee37UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -4814,16 +4814,16 @@ namespace Capnproto_test.Capnp.Test public void applyDefaults() { S16s8s64s8Set = S16s8s64s8Set ?? new Capnproto_test.Capnp.Test.TestUnion() - {Union0 = new Capnproto_test.Capnp.Test.TestUnion.@union0() - {}, Union1 = new Capnproto_test.Capnp.Test.TestUnion.@union1() - {}, Union2 = new Capnproto_test.Capnp.Test.TestUnion.@union2() - {}, Union3 = new Capnproto_test.Capnp.Test.TestUnion.@union3() + {Union0 = new Capnproto_test.Capnp.Test.TestUnion.union0() + {}, Union1 = new Capnproto_test.Capnp.Test.TestUnion.union1() + {}, Union2 = new Capnproto_test.Capnp.Test.TestUnion.union2() + {}, Union3 = new Capnproto_test.Capnp.Test.TestUnion.union3() {}, Bit0 = false, Bit2 = false, Bit3 = false, Bit4 = false, Bit5 = false, Bit6 = false, Bit7 = false, Byte0 = 0}; S0sps1s32Set = S0sps1s32Set ?? new Capnproto_test.Capnp.Test.TestUnion() - {Union0 = new Capnproto_test.Capnp.Test.TestUnion.@union0() - {}, Union1 = new Capnproto_test.Capnp.Test.TestUnion.@union1() - {}, Union2 = new Capnproto_test.Capnp.Test.TestUnion.@union2() - {}, Union3 = new Capnproto_test.Capnp.Test.TestUnion.@union3() + {Union0 = new Capnproto_test.Capnp.Test.TestUnion.union0() + {}, Union1 = new Capnproto_test.Capnp.Test.TestUnion.union1() + {}, Union2 = new Capnproto_test.Capnp.Test.TestUnion.union2() + {}, Union3 = new Capnproto_test.Capnp.Test.TestUnion.union3() {}, Bit0 = false, Bit2 = false, Bit3 = false, Bit4 = false, Bit5 = false, Bit6 = false, Bit7 = false, Byte0 = 0}; Unnamed1 = Unnamed1 ?? new Capnproto_test.Capnp.Test.TestUnnamedUnion() {Before = null, Middle = 0, After = null}; @@ -5173,16 +5173,16 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - List0 = reader.List0.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List1 = reader.List1.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List8 = reader.List8.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List16 = reader.List16.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List32 = reader.List32.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - List64 = reader.List64.ToReadOnlyList(_ => CapnpSerializable.Create(_)); - ListP = reader.ListP.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List0 = reader.List0?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List1 = reader.List1?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List8 = reader.List8?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List16 = reader.List16?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List32 = reader.List32?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List64 = reader.List64?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + ListP = reader.ListP?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); Int32ListList = reader.Int32ListList; TextListList = reader.TextListList; - StructListList = reader.StructListList.ToReadOnlyList(_2 => _2.ToReadOnlyList(_ => CapnpSerializable.Create(_))); + StructListList = reader.StructListList?.ToReadOnlyList(_2 => _2?.ToReadOnlyList(_ => CapnpSerializable.Create(_))); applyDefaults(); } @@ -6462,8 +6462,8 @@ namespace Capnproto_test.Capnp.Test Foo = reader.Foo; Bar = reader.Bar; Baz = reader.Baz; - TheUnion = CapnpSerializable.Create(reader.TheUnion); - AnotherUnion = CapnpSerializable.Create(reader.AnotherUnion); + TheUnion = CapnpSerializable.Create(reader.TheUnion); + AnotherUnion = CapnpSerializable.Create(reader.AnotherUnion); applyDefaults(); } @@ -6503,13 +6503,13 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestLateUnion.@theUnion TheUnion + public Capnproto_test.Capnp.Test.TestLateUnion.theUnion TheUnion { get; set; } - public Capnproto_test.Capnp.Test.TestLateUnion.@anotherUnion AnotherUnion + public Capnproto_test.Capnp.Test.TestLateUnion.anotherUnion AnotherUnion { get; set; @@ -6529,8 +6529,8 @@ namespace Capnproto_test.Capnp.Test public int Foo => ctx.ReadDataInt(0UL, 0); public string Bar => ctx.ReadText(0, ""); public short Baz => ctx.ReadDataShort(32UL, (short)0); - public @theUnion.READER TheUnion => new @theUnion.READER(ctx); - public @anotherUnion.READER AnotherUnion => new @anotherUnion.READER(ctx); + public theUnion.READER TheUnion => new theUnion.READER(ctx); + public anotherUnion.READER AnotherUnion => new anotherUnion.READER(ctx); } public class WRITER : SerializerState @@ -6558,19 +6558,19 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(32UL, value, (short)0); } - public @theUnion.WRITER TheUnion + public theUnion.WRITER TheUnion { - get => Rewrap<@theUnion.WRITER>(); + get => Rewrap(); } - public @anotherUnion.WRITER AnotherUnion + public anotherUnion.WRITER AnotherUnion { - get => Rewrap<@anotherUnion.WRITER>(); + get => Rewrap(); } } [TypeId(0x807280a2901aa079UL)] - public class @theUnion : ICapnpSerializable + public class theUnion : ICapnpSerializable { public const UInt64 typeId = 0x807280a2901aa079UL; public enum WHICH : ushort @@ -6731,7 +6731,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc1973984dee98e3aUL)] - public class @anotherUnion : ICapnpSerializable + public class anotherUnion : ICapnpSerializable { public const UInt64 typeId = 0xc1973984dee98e3aUL; public enum WHICH : ushort @@ -7237,7 +7237,7 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.A: - A = CapnpSerializable.Create(reader.A); + A = CapnpSerializable.Create(reader.A); break; case WHICH.B: B = reader.B; @@ -7292,9 +7292,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestNewUnionVersion.@a A + public Capnproto_test.Capnp.Test.TestNewUnionVersion.a A { - get => _which == WHICH.A ? (Capnproto_test.Capnp.Test.TestNewUnionVersion.@a)_content : null; + get => _which == WHICH.A ? (Capnproto_test.Capnp.Test.TestNewUnionVersion.a)_content : null; set { _which = WHICH.A; @@ -7324,7 +7324,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); - public @a.READER A => which == WHICH.A ? new @a.READER(ctx) : default; + public a.READER A => which == WHICH.A ? new a.READER(ctx) : default; public ulong B => which == WHICH.B ? ctx.ReadDataULong(64UL, 0UL) : default; } @@ -7341,9 +7341,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(0U, (ushort)value, (ushort)0); } - public @a.WRITER A + public a.WRITER A { - get => which == WHICH.A ? Rewrap<@a.WRITER>() : default; + get => which == WHICH.A ? Rewrap() : default; } public ulong B @@ -7354,7 +7354,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x86232c1de4513e84UL)] - public class @a : ICapnpSerializable + public class a : ICapnpSerializable { public const UInt64 typeId = 0x86232c1de4513e84UL; public enum WHICH : ushort @@ -7476,7 +7476,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - Un = CapnpSerializable.Create(reader.Un); + Un = CapnpSerializable.Create(reader.Un); applyDefaults(); } @@ -7494,7 +7494,7 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestStructUnion.@un Un + public Capnproto_test.Capnp.Test.TestStructUnion.un Un { get; set; @@ -7511,7 +7511,7 @@ namespace Capnproto_test.Capnp.Test public static READER create(DeserializerState ctx) => new READER(ctx); public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); - public @un.READER Un => new @un.READER(ctx); + public un.READER Un => new un.READER(ctx); } public class WRITER : SerializerState @@ -7521,14 +7521,14 @@ namespace Capnproto_test.Capnp.Test this.SetStruct(1, 1); } - public @un.WRITER Un + public un.WRITER Un { - get => Rewrap<@un.WRITER>(); + get => Rewrap(); } } [TypeId(0x992edc677bef5a3cUL)] - public class @un : ICapnpSerializable + public class un : ICapnpSerializable { public const UInt64 typeId = 0x992edc677bef5a3cUL; public enum WHICH : ushort @@ -7745,7 +7745,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); SomeText = reader.SomeText; - StructList = reader.StructList.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + StructList = reader.StructList?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); applyDefaults(); } @@ -7984,13 +7984,13 @@ namespace Capnproto_test.Capnp.Test which = reader.which; break; case WHICH.Ug: - Ug = CapnpSerializable.Create.@ug>(reader.Ug); + Ug = CapnpSerializable.Create.ug>(reader.Ug); break; } Foo = CapnpSerializable.Create(reader.Foo); Rev = CapnpSerializable.Create>(reader.Rev); - List = reader.List.ToReadOnlyList(_ => CapnpSerializable.Create.Inner>(_)); + List = reader.List?.ToReadOnlyList(_ => CapnpSerializable.Create.Inner>(_)); applyDefaults(); } @@ -8053,9 +8053,9 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics.@ug Ug + public Capnproto_test.Capnp.Test.TestGenerics.ug Ug { - get => _which == WHICH.Ug ? (Capnproto_test.Capnp.Test.TestGenerics.@ug)_content : null; + get => _which == WHICH.Ug ? (Capnproto_test.Capnp.Test.TestGenerics.ug)_content : null; set { _which = WHICH.Ug; @@ -8083,7 +8083,7 @@ namespace Capnproto_test.Capnp.Test public WHICH which => (WHICH)ctx.ReadDataUShort(0U, (ushort)0); public DeserializerState Foo => ctx.StructReadPointer(0); public Capnproto_test.Capnp.Test.TestGenerics.READER Rev => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.READER.create); - public @ug.READER Ug => which == WHICH.Ug ? new @ug.READER(ctx) : default; + public ug.READER Ug => which == WHICH.Ug ? new ug.READER(ctx) : default; public IReadOnlyList.Inner.READER> List => ctx.ReadList(2).Cast(Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); } @@ -8112,9 +8112,9 @@ namespace Capnproto_test.Capnp.Test set => Link(1, value); } - public @ug.WRITER Ug + public ug.WRITER Ug { - get => which == WHICH.Ug ? Rewrap<@ug.WRITER>() : default; + get => which == WHICH.Ug ? Rewrap() : default; } public ListOfStructsSerializer.Inner.WRITER> List @@ -8125,7 +8125,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb46a779beaf3384eUL)] - public class @ug : ICapnpSerializable + public class ug : ICapnpSerializable { public const UInt64 typeId = 0xb46a779beaf3384eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8476,12 +8476,12 @@ namespace Capnproto_test.Capnp.Test { public async Task Call(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Params_call.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestGenerics.Inner2.DeepNest.DeepNestInterface.Params_call() + var in_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Params_Call.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestGenerics.Inner2.DeepNest.DeepNestInterface.Params_Call() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(9816138025992274567UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_call>(d_); + var r_ = CapnpSerializable.Create.Inner2.DeepNest.DeepNestInterface.Result_Call>(d_); return; } } @@ -8497,7 +8497,7 @@ namespace Capnproto_test.Capnp.Test async Task Call(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Call(cancellationToken_); - var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_call.WRITER>(); + var s_ = SerializerState.CreateForRpc.Inner2.DeepNest.DeepNestInterface.Result_Call.WRITER>(); return s_; } } @@ -8506,7 +8506,7 @@ namespace Capnproto_test.Capnp.Test where TQuux : class { [TypeId(0xb84eecc799437049UL)] - public class Params_call : ICapnpSerializable + public class Params_Call : ICapnpSerializable { public const UInt64 typeId = 0xb84eecc799437049UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8551,7 +8551,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe080f0fc54614f6fUL)] - public class Result_call : ICapnpSerializable + public class Result_Call : ICapnpSerializable { public const UInt64 typeId = 0xe080f0fc54614f6fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8609,10 +8609,10 @@ namespace Capnproto_test.Capnp.Test public Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc.Inner2.WRITER>(); - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(14548678385738242652UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create.Interface.Result_call>(d_); + var r_ = CapnpSerializable.Create.Interface.Result_Call>(d_); return (r_.Qux, r_.Gen); } @@ -8632,8 +8632,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.Call(CapnpSerializable.Create.Inner2>(d_), cancellationToken_), (qux, gen) => { - var s_ = SerializerState.CreateForRpc.Interface.Result_call.WRITER>(); - var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_call{Qux = qux, Gen = gen}; + var s_ = SerializerState.CreateForRpc.Interface.Result_Call.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestGenerics.Interface.Result_Call{Qux = qux, Gen = gen}; r_.serialize(s_); return s_; } @@ -8646,7 +8646,7 @@ namespace Capnproto_test.Capnp.Test where TQux : class { [TypeId(0xa5b46224e33581adUL)] - public class Result_call : ICapnpSerializable + public class Result_Call : ICapnpSerializable { public const UInt64 typeId = 0xa5b46224e33581adUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -8980,19 +8980,19 @@ namespace Capnproto_test.Capnp.Test [TypeId(0x8b9717a3f8d85a9aUL), Proxy(typeof(TestImplicitMethodParams_Proxy)), Skeleton(typeof(TestImplicitMethodParams_Skeleton))] public interface ITestImplicitMethodParams : IDisposable { - Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } public class TestImplicitMethodParams_Proxy : Proxy, ITestImplicitMethodParams { - public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + public Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class { - var in_ = SerializerState.CreateForRpc.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParams.Params_call() - {Foo = foo, Bar = bar}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParams.Params_Call() + {Foo = Foo, Bar = Bar}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(10058534285777328794UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { var r_ = CapnpSerializable.Create>(d_); @@ -9014,7 +9014,7 @@ namespace Capnproto_test.Capnp.Test Task Call(DeserializerState d_, CancellationToken cancellationToken_) where TT : class where TU : class { - var in_ = CapnpSerializable.Create>(d_); + var in_ = CapnpSerializable.Create>(d_); return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => { var s_ = SerializerState.CreateForRpc.WRITER>(); @@ -9029,7 +9029,7 @@ namespace Capnproto_test.Capnp.Test public static class TestImplicitMethodParams { [TypeId(0xf83f8caf54bdc486UL)] - public class Params_call : ICapnpSerializable where TT : class where TU : class + public class Params_Call : ICapnpSerializable where TT : class where TU : class { public const UInt64 typeId = 0xf83f8caf54bdc486UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -9107,19 +9107,19 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xdf9ccdeb81a704c9UL), Proxy(typeof(TestImplicitMethodParamsInGeneric_Proxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGeneric_Skeleton<>))] public interface ITestImplicitMethodParamsInGeneric : IDisposable where TV : class { - Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } public class TestImplicitMethodParamsInGeneric_Proxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class { - public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) + public Task> Call(TT Foo, TU Bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class { - var in_ = SerializerState.CreateForRpc.Params_call.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParamsInGeneric.Params_call() - {Foo = foo, Bar = bar}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc.Params_Call.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestImplicitMethodParamsInGeneric.Params_Call() + {Foo = Foo, Bar = Bar}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(16112979978201007305UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { var r_ = CapnpSerializable.Create>(d_); @@ -9141,7 +9141,7 @@ namespace Capnproto_test.Capnp.Test Task Call(DeserializerState d_, CancellationToken cancellationToken_) where TT : class where TU : class { - var in_ = CapnpSerializable.Create.Params_call>(d_); + var in_ = CapnpSerializable.Create.Params_Call>(d_); return Impatient.MaybeTailCall(Impl.Call(in_.Foo, in_.Bar, cancellationToken_), r_ => { var s_ = SerializerState.CreateForRpc.WRITER>(); @@ -9157,7 +9157,7 @@ namespace Capnproto_test.Capnp.Test where TV : class { [TypeId(0x9aab8e25c808d71eUL)] - public class Params_call : ICapnpSerializable where TT : class where TU : class + public class Params_Call : ICapnpSerializable where TT : class where TU : class { public const UInt64 typeId = 0x9aab8e25c808d71eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -9918,7 +9918,7 @@ namespace Capnproto_test.Capnp.Test AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); - AnyListAsList = reader.AnyListAsList.ToReadOnlyList(_ => (object)_); + AnyListAsList = reader.AnyListAsList?.ToReadOnlyList(_ => (object)_); applyDefaults(); } @@ -10016,43 +10016,43 @@ namespace Capnproto_test.Capnp.Test [TypeId(0x88eb12a0e0af92b2UL), Proxy(typeof(TestInterface_Proxy)), Skeleton(typeof(TestInterface_Skeleton))] public interface ITestInterface : IDisposable { - Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default); + Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default); Task Bar(CancellationToken cancellationToken_ = default); - Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default); + Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default); } public class TestInterface_Proxy : Proxy, ITestInterface { - public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() - {I = i, J = j}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() + {I = I, J = J}; + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.X); } public async Task Bar(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } - public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() - {S = s}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() + {S = S}; + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } } @@ -10067,11 +10067,11 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9865999890858873522UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.J, cancellationToken_), x => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_foo{X = x}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestInterface.Result_Foo{X = x}; r_.serialize(s_); return s_; } @@ -10082,15 +10082,15 @@ namespace Capnproto_test.Capnp.Test async Task Bar(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Bar(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } async Task Baz(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); await Impl.Baz(in_.S, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } } @@ -10098,7 +10098,7 @@ namespace Capnproto_test.Capnp.Test public static class TestInterface { [TypeId(0xb874edc0d559b391UL)] - public class Params_foo : ICapnpSerializable + public class Params_Foo : ICapnpSerializable { public const UInt64 typeId = 0xb874edc0d559b391UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10173,7 +10173,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb04fcaddab714ba4UL)] - public class Result_foo : ICapnpSerializable + public class Result_Foo : ICapnpSerializable { public const UInt64 typeId = 0xb04fcaddab714ba4UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10233,7 +10233,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xd044893357b42568UL)] - public class Params_bar : ICapnpSerializable + public class Params_Bar : ICapnpSerializable { public const UInt64 typeId = 0xd044893357b42568UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10278,7 +10278,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9bf141df4247d52fUL)] - public class Result_bar : ICapnpSerializable + public class Result_Bar : ICapnpSerializable { public const UInt64 typeId = 0x9bf141df4247d52fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10323,7 +10323,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xd9ac8abb2a91cfbcUL)] - public class Params_baz : ICapnpSerializable + public class Params_Baz : ICapnpSerializable { public const UInt64 typeId = 0xd9ac8abb2a91cfbcUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10383,7 +10383,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9b99d14f2f375b2dUL)] - public class Result_baz : ICapnpSerializable + public class Result_Baz : ICapnpSerializable { public const UInt64 typeId = 0x9b99d14f2f375b2dUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10440,65 +10440,65 @@ namespace Capnproto_test.Capnp.Test { public async Task Qux(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_qux() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Qux() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Grault(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_grault() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Grault() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; var r_ = CapnpSerializable.Create(d_); return r_; } - public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() - {I = i, J = j}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() + {I = I, J = J}; + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.X); } public async Task Bar(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } - public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() - {S = s}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() + {S = S}; + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } } @@ -10514,14 +10514,14 @@ namespace Capnproto_test.Capnp.Test async Task Qux(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Qux(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } async Task Corge(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Corge(CapnpSerializable.Create(d_), cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } @@ -10541,7 +10541,7 @@ namespace Capnproto_test.Capnp.Test public static class TestExtends { [TypeId(0x83a4bc5471363f17UL)] - public class Params_qux : ICapnpSerializable + public class Params_Qux : ICapnpSerializable { public const UInt64 typeId = 0x83a4bc5471363f17UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10586,7 +10586,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8e4b3d1a3e2753ddUL)] - public class Result_qux : ICapnpSerializable + public class Result_Qux : ICapnpSerializable { public const UInt64 typeId = 0x8e4b3d1a3e2753ddUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10631,7 +10631,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xacf67532a7e7bad9UL)] - public class Result_corge : ICapnpSerializable + public class Result_Corge : ICapnpSerializable { public const UInt64 typeId = 0xacf67532a7e7bad9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10676,7 +10676,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf3b834e851ea8af6UL)] - public class Params_grault : ICapnpSerializable + public class Params_Grault : ICapnpSerializable { public const UInt64 typeId = 0xf3b834e851ea8af6UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -10730,65 +10730,65 @@ namespace Capnproto_test.Capnp.Test { public async Task Qux(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_qux() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Qux() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(16494920484927878984UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Corge(Capnproto_test.Capnp.Test.TestAllTypes arg_, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(16494920484927878984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Grault(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_grault() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestExtends.Params_Grault() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(16494920484927878984UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; var r_ = CapnpSerializable.Create(d_); return r_; } - public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) + public async Task Foo(uint I, bool J, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_foo() - {I = i, J = j}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Foo() + {I = I, J = J}; + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.X); } public async Task Bar(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_bar() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Bar() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } - public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default) + public async Task Baz(Capnproto_test.Capnp.Test.TestAllTypes S, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_baz() - {S = s}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestInterface.Params_Baz() + {S = S}; + arg_?.serialize(in_); var d_ = await Call(9865999890858873522UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } } @@ -10806,48 +10806,48 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xa5a404caa61d4cd0UL), Proxy(typeof(TestPipeline_Proxy)), Skeleton(typeof(TestPipeline_Skeleton))] public interface ITestPipeline : IDisposable { - Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); - Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); - Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); + Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint N, Capnproto_test.Capnp.Test.ITestInterface InCap, CancellationToken cancellationToken_ = default); + Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface Cap, object Obj, IReadOnlyList List, CancellationToken cancellationToken_ = default); + Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint N, BareProxy InCap, CancellationToken cancellationToken_ = default); } public class TestPipeline_Proxy : Proxy, ITestPipeline { - public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default) + public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint N, Capnproto_test.Capnp.Test.ITestInterface InCap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_getCap() - {N = n, InCap = inCap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_GetCap() + {N = N, InCap = InCap}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(11935670180855499984UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.S, r_.OutBox); } ); } - public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) + public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface Cap, object Obj, IReadOnlyList List, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_testPointers() - {Cap = cap, Obj = obj, List = list}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_TestPointers() + {Cap = Cap, Obj = Obj, List = List}; + arg_?.serialize(in_); var d_ = await Call(11935670180855499984UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } - public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default) + public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint N, BareProxy InCap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_getAnyCap() - {N = n, InCap = inCap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_GetAnyCap() + {N = N, InCap = InCap}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(11935670180855499984UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.S, r_.OutBox); } @@ -10865,11 +10865,11 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11935670180855499984UL; Task GetCap(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.GetCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_getCap{S = s, OutBox = outBox}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetCap{S = s, OutBox = outBox}; r_.serialize(s_); return s_; } @@ -10879,19 +10879,19 @@ namespace Capnproto_test.Capnp.Test async Task TestPointers(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); await Impl.TestPointers(in_.Cap, in_.Obj, in_.List, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } Task GetAnyCap(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.GetAnyCap(in_.N, in_.InCap, cancellationToken_), (s, outBox) => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_getAnyCap{S = s, OutBox = outBox}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestPipeline.Result_GetAnyCap{S = s, OutBox = outBox}; r_.serialize(s_); return s_; } @@ -11023,7 +11023,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc7e8df5096257034UL)] - public class Params_getCap : ICapnpSerializable + public class Params_GetCap : ICapnpSerializable { public const UInt64 typeId = 0xc7e8df5096257034UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11098,7 +11098,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb2442a9e0ba28fdfUL)] - public class Result_getCap : ICapnpSerializable + public class Result_GetCap : ICapnpSerializable { public const UInt64 typeId = 0xb2442a9e0ba28fdfUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11173,7 +11173,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa604ee63cf37819fUL)] - public class Params_testPointers : ICapnpSerializable + public class Params_TestPointers : ICapnpSerializable { public const UInt64 typeId = 0xa604ee63cf37819fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11263,7 +11263,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8eda54756c6070d6UL)] - public class Result_testPointers : ICapnpSerializable + public class Result_TestPointers : ICapnpSerializable { public const UInt64 typeId = 0x8eda54756c6070d6UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11308,7 +11308,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf8e36b53ab093d4eUL)] - public class Params_getAnyCap : ICapnpSerializable + public class Params_GetAnyCap : ICapnpSerializable { public const UInt64 typeId = 0xf8e36b53ab093d4eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11383,7 +11383,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xbf44b4c94c26ef79UL)] - public class Result_getAnyCap : ICapnpSerializable + public class Result_GetAnyCap : ICapnpSerializable { public const UInt64 typeId = 0xbf44b4c94c26ef79UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11461,19 +11461,19 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xa0e77035bdff0051UL), Proxy(typeof(TestCallOrder_Proxy)), Skeleton(typeof(TestCallOrder_Skeleton))] public interface ITestCallOrder : IDisposable { - Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default); + Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default); } public class TestCallOrder_Proxy : Proxy, ITestCallOrder { - public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) + public async Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_getCallSequence() - {Expected = expected}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_GetCallSequence() + {Expected = Expected}; + arg_?.serialize(in_); var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.N); } } @@ -11488,11 +11488,11 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11594359141811814481UL; Task GetCallSequence(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.GetCallSequence(in_.Expected, cancellationToken_), n => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_getCallSequence{N = n}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestCallOrder.Result_GetCallSequence{N = n}; r_.serialize(s_); return s_; } @@ -11504,7 +11504,7 @@ namespace Capnproto_test.Capnp.Test public static class TestCallOrder { [TypeId(0x8f1e8cd56ceb74dcUL)] - public class Params_getCallSequence : ICapnpSerializable + public class Params_GetCallSequence : ICapnpSerializable { public const UInt64 typeId = 0x8f1e8cd56ceb74dcUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11564,7 +11564,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdedbb6bf3810eab7UL)] - public class Result_getCallSequence : ICapnpSerializable + public class Result_GetCallSequence : ICapnpSerializable { public const UInt64 typeId = 0xdedbb6bf3810eab7UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11627,17 +11627,17 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xddd699207eb8e23bUL), Proxy(typeof(TestTailCallee_Proxy)), Skeleton(typeof(TestTailCallee_Skeleton))] public interface ITestTailCallee : IDisposable { - Task Foo(int i, string t, CancellationToken cancellationToken_ = default); + Task Foo(int I, string T, CancellationToken cancellationToken_ = default); } public class TestTailCallee_Proxy : Proxy, ITestTailCallee { - public Task Foo(int i, string t, CancellationToken cancellationToken_ = default) + public Task Foo(int I, string T, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestTailCallee.Params_foo() - {I = i, T = t}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestTailCallee.Params_Foo() + {I = I, T = T}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15985132292242203195UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { var r_ = CapnpSerializable.Create(d_); @@ -11658,7 +11658,7 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15985132292242203195UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.T, cancellationToken_), r_ => { var s_ = SerializerState.CreateForRpc(); @@ -11763,7 +11763,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc5e1efc325614957UL)] - public class Params_foo : ICapnpSerializable + public class Params_Foo : ICapnpSerializable { public const UInt64 typeId = 0xc5e1efc325614957UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11841,17 +11841,17 @@ namespace Capnproto_test.Capnp.Test [TypeId(0x870bf40110ce3035UL), Proxy(typeof(TestTailCaller_Proxy)), Skeleton(typeof(TestTailCaller_Skeleton))] public interface ITestTailCaller : IDisposable { - Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default); + Task Foo(int I, Capnproto_test.Capnp.Test.ITestTailCallee Callee, CancellationToken cancellationToken_ = default); } public class TestTailCaller_Proxy : Proxy, ITestTailCaller { - public Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default) + public Task Foo(int I, Capnproto_test.Capnp.Test.ITestTailCallee Callee, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestTailCaller.Params_foo() - {I = i, Callee = callee}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestTailCaller.Params_Foo() + {I = I, Callee = Callee}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(9731139705278181429UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { var r_ = CapnpSerializable.Create(d_); @@ -11872,7 +11872,7 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 9731139705278181429UL; Task Foo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.Foo(in_.I, in_.Callee, cancellationToken_), r_ => { var s_ = SerializerState.CreateForRpc(); @@ -11887,7 +11887,7 @@ namespace Capnproto_test.Capnp.Test public static class TestTailCaller { [TypeId(0xb07a279515dc8ac5UL)] - public class Params_foo : ICapnpSerializable + public class Params_Foo : ICapnpSerializable { public const UInt64 typeId = 0xb07a279515dc8ac5UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -11984,143 +11984,143 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xddc70bf9784133cfUL), Proxy(typeof(TestMoreStuff_Proxy)), Skeleton(typeof(TestMoreStuff_Skeleton))] public interface ITestMoreStuff : Capnproto_test.Capnp.Test.ITestCallOrder { - Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task Hold(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); + Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task Hold(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); Task CallHeld(CancellationToken cancellationToken_ = default); Task GetHeld(CancellationToken cancellationToken_ = default); - Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder cap, CancellationToken cancellationToken_ = default); - Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); - Task<(string, string)> MethodWithDefaults(string a, uint b, string c, CancellationToken cancellationToken_ = default); + Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder Cap, CancellationToken cancellationToken_ = default); + Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default); + Task<(string, string)> MethodWithDefaults(string A, uint B, string C, CancellationToken cancellationToken_ = default); Task GetHandle(CancellationToken cancellationToken_ = default); Task GetNull(CancellationToken cancellationToken_ = default); Task GetEnormousString(CancellationToken cancellationToken_ = default); - Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default); + Task MethodWithNullDefault(string A, Capnproto_test.Capnp.Test.ITestInterface B, CancellationToken cancellationToken_ = default); } public class TestMoreStuff_Proxy : Proxy, ITestMoreStuff { - public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callFoo() - {Cap = cap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallFoo() + {Cap = Cap}; + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.S); } - public async Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task CallFooWhenResolved(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callFooWhenResolved() - {Cap = cap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallFooWhenResolved() + {Cap = Cap}; + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.S); } - public Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public Task NeverReturn(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_neverReturn() - {Cap = cap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_NeverReturn() + {Cap = Cap}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.CapCopy); } ); } - public async Task Hold(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task Hold(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_hold() - {Cap = cap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_Hold() + {Cap = Cap}; + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task CallHeld(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_callHeld() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_CallHeld() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.S); } public Task GetHeld(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getHeld() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetHeld() {}; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 5, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.Cap); } ); } - public Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder cap, CancellationToken cancellationToken_ = default) + public Task Echo(Capnproto_test.Capnp.Test.ITestCallOrder Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_echo() - {Cap = cap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_Echo() + {Cap = Cap}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 6, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.Cap); } ); } - public async Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) + public async Task ExpectCancel(Capnproto_test.Capnp.Test.ITestInterface Cap, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_expectCancel() - {Cap = cap}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_ExpectCancel() + {Cap = Cap}; + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 7, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } - public async Task<(string, string)> MethodWithDefaults(string a, uint b, string c, CancellationToken cancellationToken_ = default) + public async Task<(string, string)> MethodWithDefaults(string A, uint B, string C, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_methodWithDefaults() - {A = a, B = b, C = c}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_MethodWithDefaults() + {A = A, B = B, C = C}; + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 8, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.D, r_.E); } public Task GetHandle(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getHandle() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetHandle() {}; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 9, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.Handle); } @@ -12129,13 +12129,13 @@ namespace Capnproto_test.Capnp.Test public Task GetNull(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getNull() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetNull() {}; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(15980754968839795663UL, 10, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.NullCap); } @@ -12144,34 +12144,34 @@ namespace Capnproto_test.Capnp.Test public async Task GetEnormousString(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_getEnormousString() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_GetEnormousString() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 11, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.Str); } - public async Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default) + public async Task MethodWithNullDefault(string A, Capnproto_test.Capnp.Test.ITestInterface B, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_methodWithNullDefault() - {A = a, B = b}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Params_MethodWithNullDefault() + {A = A, B = B}; + arg_?.serialize(in_); var d_ = await Call(15980754968839795663UL, 12, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } - public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) + public async Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_getCallSequence() - {Expected = expected}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestCallOrder.Params_GetCallSequence() + {Expected = Expected}; + arg_?.serialize(in_); var d_ = await Call(11594359141811814481UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.N); } } @@ -12186,11 +12186,11 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15980754968839795663UL; Task CallFoo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.CallFoo(in_.Cap, cancellationToken_), s => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callFoo{S = s}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFoo{S = s}; r_.serialize(s_); return s_; } @@ -12200,11 +12200,11 @@ namespace Capnproto_test.Capnp.Test Task CallFooWhenResolved(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.CallFooWhenResolved(in_.Cap, cancellationToken_), s => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callFooWhenResolved{S = s}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallFooWhenResolved{S = s}; r_.serialize(s_); return s_; } @@ -12214,11 +12214,11 @@ namespace Capnproto_test.Capnp.Test Task NeverReturn(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.NeverReturn(in_.Cap, cancellationToken_), capCopy => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_neverReturn{CapCopy = capCopy}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_NeverReturn{CapCopy = capCopy}; r_.serialize(s_); return s_; } @@ -12228,9 +12228,9 @@ namespace Capnproto_test.Capnp.Test async Task Hold(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); await Impl.Hold(in_.Cap, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } @@ -12238,8 +12238,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.CallHeld(cancellationToken_), s => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_callHeld{S = s}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_CallHeld{S = s}; r_.serialize(s_); return s_; } @@ -12251,8 +12251,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.GetHeld(cancellationToken_), cap => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getHeld{Cap = cap}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHeld{Cap = cap}; r_.serialize(s_); return s_; } @@ -12262,11 +12262,11 @@ namespace Capnproto_test.Capnp.Test Task Echo(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.Echo(in_.Cap, cancellationToken_), cap => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_echo{Cap = cap}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_Echo{Cap = cap}; r_.serialize(s_); return s_; } @@ -12276,19 +12276,19 @@ namespace Capnproto_test.Capnp.Test async Task ExpectCancel(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); await Impl.ExpectCancel(in_.Cap, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } Task MethodWithDefaults(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.MethodWithDefaults(in_.A, in_.B, in_.C, cancellationToken_), (d, e) => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_methodWithDefaults{D = d, E = e}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_MethodWithDefaults{D = d, E = e}; r_.serialize(s_); return s_; } @@ -12300,8 +12300,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.GetHandle(cancellationToken_), handle => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getHandle{Handle = handle}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetHandle{Handle = handle}; r_.serialize(s_); return s_; } @@ -12313,8 +12313,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.GetNull(cancellationToken_), nullCap => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getNull{NullCap = nullCap}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetNull{NullCap = nullCap}; r_.serialize(s_); return s_; } @@ -12326,8 +12326,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.GetEnormousString(cancellationToken_), str => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_getEnormousString{Str = str}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMoreStuff.Result_GetEnormousString{Str = str}; r_.serialize(s_); return s_; } @@ -12337,9 +12337,9 @@ namespace Capnproto_test.Capnp.Test async Task MethodWithNullDefault(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); await Impl.MethodWithNullDefault(in_.A, in_.B, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } } @@ -12347,7 +12347,7 @@ namespace Capnproto_test.Capnp.Test public static class TestMoreStuff { [TypeId(0x931ba418da60f6e4UL)] - public class Params_callFoo : ICapnpSerializable + public class Params_CallFoo : ICapnpSerializable { public const UInt64 typeId = 0x931ba418da60f6e4UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12407,7 +12407,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9a28970beccecdd0UL)] - public class Result_callFoo : ICapnpSerializable + public class Result_CallFoo : ICapnpSerializable { public const UInt64 typeId = 0x9a28970beccecdd0UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12467,7 +12467,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfabc700c2ebe6378UL)] - public class Params_callFooWhenResolved : ICapnpSerializable + public class Params_CallFooWhenResolved : ICapnpSerializable { public const UInt64 typeId = 0xfabc700c2ebe6378UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12527,7 +12527,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa54ce1e9aa822f90UL)] - public class Result_callFooWhenResolved : ICapnpSerializable + public class Result_CallFooWhenResolved : ICapnpSerializable { public const UInt64 typeId = 0xa54ce1e9aa822f90UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12587,7 +12587,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x94fe60465c95182bUL)] - public class Params_neverReturn : ICapnpSerializable + public class Params_NeverReturn : ICapnpSerializable { public const UInt64 typeId = 0x94fe60465c95182bUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12647,7 +12647,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdef4e5fa6999c5dcUL)] - public class Result_neverReturn : ICapnpSerializable + public class Result_NeverReturn : ICapnpSerializable { public const UInt64 typeId = 0xdef4e5fa6999c5dcUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12707,7 +12707,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfe7c8fbb769d8e58UL)] - public class Params_hold : ICapnpSerializable + public class Params_Hold : ICapnpSerializable { public const UInt64 typeId = 0xfe7c8fbb769d8e58UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12767,7 +12767,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf839fb1374d003c9UL)] - public class Result_hold : ICapnpSerializable + public class Result_Hold : ICapnpSerializable { public const UInt64 typeId = 0xf839fb1374d003c9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12812,7 +12812,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xf8c5e5ef1edf83beUL)] - public class Params_callHeld : ICapnpSerializable + public class Params_CallHeld : ICapnpSerializable { public const UInt64 typeId = 0xf8c5e5ef1edf83beUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12857,7 +12857,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe59935f160ac7578UL)] - public class Result_callHeld : ICapnpSerializable + public class Result_CallHeld : ICapnpSerializable { public const UInt64 typeId = 0xe59935f160ac7578UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12917,7 +12917,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfeffc025fce317e3UL)] - public class Params_getHeld : ICapnpSerializable + public class Params_GetHeld : ICapnpSerializable { public const UInt64 typeId = 0xfeffc025fce317e3UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -12962,7 +12962,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xef4e146185af67ceUL)] - public class Result_getHeld : ICapnpSerializable + public class Result_GetHeld : ICapnpSerializable { public const UInt64 typeId = 0xef4e146185af67ceUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13022,7 +13022,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc07526f7e2e533b9UL)] - public class Params_echo : ICapnpSerializable + public class Params_Echo : ICapnpSerializable { public const UInt64 typeId = 0xc07526f7e2e533b9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13082,7 +13082,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa6224536593d5b92UL)] - public class Result_echo : ICapnpSerializable + public class Result_Echo : ICapnpSerializable { public const UInt64 typeId = 0xa6224536593d5b92UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13142,7 +13142,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa1cc32d87f3edeb1UL)] - public class Params_expectCancel : ICapnpSerializable + public class Params_ExpectCancel : ICapnpSerializable { public const UInt64 typeId = 0xa1cc32d87f3edeb1UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13202,7 +13202,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8a3eba1758c0916eUL)] - public class Result_expectCancel : ICapnpSerializable + public class Result_ExpectCancel : ICapnpSerializable { public const UInt64 typeId = 0x8a3eba1758c0916eUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13247,7 +13247,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x99160a25fa50fbf1UL)] - public class Params_methodWithDefaults : ICapnpSerializable + public class Params_MethodWithDefaults : ICapnpSerializable { public const UInt64 typeId = 0x99160a25fa50fbf1UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13339,7 +13339,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9c7e066f845a6c56UL)] - public class Result_methodWithDefaults : ICapnpSerializable + public class Result_MethodWithDefaults : ICapnpSerializable { public const UInt64 typeId = 0x9c7e066f845a6c56UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13415,7 +13415,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xead024a301a092a1UL)] - public class Params_getHandle : ICapnpSerializable + public class Params_GetHandle : ICapnpSerializable { public const UInt64 typeId = 0xead024a301a092a1UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13460,7 +13460,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc3490d75420a1fe8UL)] - public class Result_getHandle : ICapnpSerializable + public class Result_GetHandle : ICapnpSerializable { public const UInt64 typeId = 0xc3490d75420a1fe8UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13520,7 +13520,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xd8493f0e175d61f2UL)] - public class Params_getNull : ICapnpSerializable + public class Params_GetNull : ICapnpSerializable { public const UInt64 typeId = 0xd8493f0e175d61f2UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13565,7 +13565,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe6955d8ef1023671UL)] - public class Result_getNull : ICapnpSerializable + public class Result_GetNull : ICapnpSerializable { public const UInt64 typeId = 0xe6955d8ef1023671UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13625,7 +13625,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x805df436f55dd07aUL)] - public class Params_getEnormousString : ICapnpSerializable + public class Params_GetEnormousString : ICapnpSerializable { public const UInt64 typeId = 0x805df436f55dd07aUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13670,7 +13670,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x860e7512dc3925b0UL)] - public class Result_getEnormousString : ICapnpSerializable + public class Result_GetEnormousString : ICapnpSerializable { public const UInt64 typeId = 0x860e7512dc3925b0UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13730,7 +13730,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xfb92899aeb0ee74fUL)] - public class Params_methodWithNullDefault : ICapnpSerializable + public class Params_MethodWithNullDefault : ICapnpSerializable { public const UInt64 typeId = 0xfb92899aeb0ee74fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13805,7 +13805,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8467348247305cf7UL)] - public class Result_methodWithNullDefault : ICapnpSerializable + public class Result_MethodWithNullDefault : ICapnpSerializable { public const UInt64 typeId = 0x8467348247305cf7UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -13854,9 +13854,9 @@ namespace Capnproto_test.Capnp.Test public interface ITestMembrane : IDisposable { Task MakeThing(CancellationToken cancellationToken_ = default); - Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default); - Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default); - Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, CancellationToken cancellationToken_ = default); + Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default); + Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default); + Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, CancellationToken cancellationToken_ = default); Task WaitForever(CancellationToken cancellationToken_ = default); } @@ -13864,50 +13864,50 @@ namespace Capnproto_test.Capnp.Test { public Task MakeThing(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_makeThing() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_MakeThing() {}; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(13870398341137210380UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.Thing); } ); } - public async Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default) + public async Task CallPassThrough(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_callPassThrough() - {Thing = thing, TailCall = tailCall}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_CallPassThrough() + {Thing = Thing, TailCall = TailCall}; + arg_?.serialize(in_); var d_ = await Call(13870398341137210380UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; var r_ = CapnpSerializable.Create(d_); return r_; } - public async Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, bool tailCall, CancellationToken cancellationToken_ = default) + public async Task CallIntercept(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, bool TailCall, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_callIntercept() - {Thing = thing, TailCall = tailCall}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_CallIntercept() + {Thing = Thing, TailCall = TailCall}; + arg_?.serialize(in_); var d_ = await Call(13870398341137210380UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; var r_ = CapnpSerializable.Create(d_); return r_; } - public Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing thing, CancellationToken cancellationToken_ = default) + public Task Loopback(Capnproto_test.Capnp.Test.TestMembrane.IThing Thing, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_loopback() - {Thing = thing}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_Loopback() + {Thing = Thing}; + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(13870398341137210380UL, 3, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return (r_.Thing); } @@ -13916,12 +13916,12 @@ namespace Capnproto_test.Capnp.Test public async Task WaitForever(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_waitForever() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Params_WaitForever() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(13870398341137210380UL, 4, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } } @@ -13938,8 +13938,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.MakeThing(cancellationToken_), thing => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_makeThing{Thing = thing}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_MakeThing{Thing = thing}; r_.serialize(s_); return s_; } @@ -13949,7 +13949,7 @@ namespace Capnproto_test.Capnp.Test Task CallPassThrough(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.CallPassThrough(in_.Thing, in_.TailCall, cancellationToken_), r_ => { var s_ = SerializerState.CreateForRpc(); @@ -13962,7 +13962,7 @@ namespace Capnproto_test.Capnp.Test Task CallIntercept(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.CallIntercept(in_.Thing, in_.TailCall, cancellationToken_), r_ => { var s_ = SerializerState.CreateForRpc(); @@ -13975,11 +13975,11 @@ namespace Capnproto_test.Capnp.Test Task Loopback(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); return Impatient.MaybeTailCall(Impl.Loopback(in_.Thing, cancellationToken_), thing => { - var s_ = SerializerState.CreateForRpc(); - var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_loopback{Thing = thing}; + var s_ = SerializerState.CreateForRpc(); + var r_ = new Capnproto_test.Capnp.Test.TestMembrane.Result_Loopback{Thing = thing}; r_.serialize(s_); return s_; } @@ -13990,7 +13990,7 @@ namespace Capnproto_test.Capnp.Test async Task WaitForever(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.WaitForever(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } } @@ -14008,10 +14008,10 @@ namespace Capnproto_test.Capnp.Test { public async Task PassThrough(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_passThrough() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_PassThrough() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(10615798940090972439UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; var r_ = CapnpSerializable.Create(d_); return r_; @@ -14019,10 +14019,10 @@ namespace Capnproto_test.Capnp.Test public async Task Intercept(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_intercept() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestMembrane.Thing.Params_Intercept() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(10615798940090972439UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; var r_ = CapnpSerializable.Create(d_); return r_; @@ -14065,7 +14065,7 @@ namespace Capnproto_test.Capnp.Test public static class Thing { [TypeId(0xff9bdcd05085d786UL)] - public class Params_passThrough : ICapnpSerializable + public class Params_PassThrough : ICapnpSerializable { public const UInt64 typeId = 0xff9bdcd05085d786UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14110,7 +14110,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xee94bed3615ee745UL)] - public class Params_intercept : ICapnpSerializable + public class Params_Intercept : ICapnpSerializable { public const UInt64 typeId = 0xee94bed3615ee745UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14216,7 +14216,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xd8ac2acc3ece6556UL)] - public class Params_makeThing : ICapnpSerializable + public class Params_MakeThing : ICapnpSerializable { public const UInt64 typeId = 0xd8ac2acc3ece6556UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14261,7 +14261,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xe5d4904814ccbf29UL)] - public class Result_makeThing : ICapnpSerializable + public class Result_MakeThing : ICapnpSerializable { public const UInt64 typeId = 0xe5d4904814ccbf29UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14321,7 +14321,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x945d9f634a6a29daUL)] - public class Params_callPassThrough : ICapnpSerializable + public class Params_CallPassThrough : ICapnpSerializable { public const UInt64 typeId = 0x945d9f634a6a29daUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14396,7 +14396,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8749aac3375c5c71UL)] - public class Params_callIntercept : ICapnpSerializable + public class Params_CallIntercept : ICapnpSerializable { public const UInt64 typeId = 0x8749aac3375c5c71UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14471,7 +14471,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x869a1b7ab34b42c9UL)] - public class Params_loopback : ICapnpSerializable + public class Params_Loopback : ICapnpSerializable { public const UInt64 typeId = 0x869a1b7ab34b42c9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14531,7 +14531,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xecd19398fd88ab5cUL)] - public class Result_loopback : ICapnpSerializable + public class Result_Loopback : ICapnpSerializable { public const UInt64 typeId = 0xecd19398fd88ab5cUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14591,7 +14591,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x8f6bb30cc62917ffUL)] - public class Params_waitForever : ICapnpSerializable + public class Params_WaitForever : ICapnpSerializable { public const UInt64 typeId = 0x8f6bb30cc62917ffUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14636,7 +14636,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc343a4907280be01UL)] - public class Result_waitForever : ICapnpSerializable + public class Result_WaitForever : ICapnpSerializable { public const UInt64 typeId = 0xc343a4907280be01UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -14763,7 +14763,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - List = reader.List.ToReadOnlyList(_ => CapnpSerializable.Create(_)); + List = reader.List?.ToReadOnlyList(_ => CapnpSerializable.Create(_)); applyDefaults(); } @@ -14904,45 +14904,45 @@ namespace Capnproto_test.Capnp.Test { public async Task Delete(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_delete() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Delete() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(11160837778045172988UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Class(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_class() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Class() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(11160837778045172988UL, 1, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Void(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_void() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Void() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(11160837778045172988UL, 2, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } public async Task Return(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_return() + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestKeywordMethods.Params_Return() {}; - arg_.serialize(in_); + arg_?.serialize(in_); var d_ = await Call(11160837778045172988UL, 3, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } } @@ -14958,28 +14958,28 @@ namespace Capnproto_test.Capnp.Test async Task Delete(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Delete(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } async Task Class(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Class(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } async Task Void(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Void(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } async Task Return(DeserializerState d_, CancellationToken cancellationToken_) { await Impl.Return(cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } } @@ -14987,7 +14987,7 @@ namespace Capnproto_test.Capnp.Test public static class TestKeywordMethods { [TypeId(0xca3a89cdeb6bd6b7UL)] - public class Params_delete : ICapnpSerializable + public class Params_Delete : ICapnpSerializable { public const UInt64 typeId = 0xca3a89cdeb6bd6b7UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15032,7 +15032,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xeeb5843598307592UL)] - public class Result_delete : ICapnpSerializable + public class Result_Delete : ICapnpSerializable { public const UInt64 typeId = 0xeeb5843598307592UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15077,7 +15077,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x9cf5a8313c5db036UL)] - public class Params_class : ICapnpSerializable + public class Params_Class : ICapnpSerializable { public const UInt64 typeId = 0x9cf5a8313c5db036UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15122,7 +15122,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc0253868ac12e7d8UL)] - public class Result_class : ICapnpSerializable + public class Result_Class : ICapnpSerializable { public const UInt64 typeId = 0xc0253868ac12e7d8UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15167,7 +15167,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xa4a08763833c7757UL)] - public class Params_void : ICapnpSerializable + public class Params_Void : ICapnpSerializable { public const UInt64 typeId = 0xa4a08763833c7757UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15212,7 +15212,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xde82773089c0aeabUL)] - public class Result_void : ICapnpSerializable + public class Result_Void : ICapnpSerializable { public const UInt64 typeId = 0xde82773089c0aeabUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15257,7 +15257,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0x99817360625e8ca3UL)] - public class Params_return : ICapnpSerializable + public class Params_Return : ICapnpSerializable { public const UInt64 typeId = 0x99817360625e8ca3UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15302,7 +15302,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xb70872e07eaa992fUL)] - public class Result_return : ICapnpSerializable + public class Result_Return : ICapnpSerializable { public const UInt64 typeId = 0xb70872e07eaa992fUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15357,13 +15357,13 @@ namespace Capnproto_test.Capnp.Test { public Task GetCallerId(CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc.Params_getCallerId.WRITER>(); - var arg_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Params_getCallerId() + var in_ = SerializerState.CreateForRpc.Params_GetCallerId.WRITER>(); + var arg_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Params_GetCallerId() {}; - arg_.serialize(in_); + arg_?.serialize(in_); return Impatient.MakePipelineAware(Call(16893789964317726925UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => { - var r_ = CapnpSerializable.Create.Result_getCallerId>(d_); + var r_ = CapnpSerializable.Create.Result_GetCallerId>(d_); return (r_.Caller); } @@ -15383,8 +15383,8 @@ namespace Capnproto_test.Capnp.Test { return Impatient.MaybeTailCall(Impl.GetCallerId(cancellationToken_), caller => { - var s_ = SerializerState.CreateForRpc.Result_getCallerId.WRITER>(); - var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_getCallerId{Caller = caller}; + var s_ = SerializerState.CreateForRpc.Result_GetCallerId.WRITER>(); + var r_ = new Capnproto_test.Capnp.Test.TestAuthenticatedBootstrap.Result_GetCallerId{Caller = caller}; r_.serialize(s_); return s_; } @@ -15397,7 +15397,7 @@ namespace Capnproto_test.Capnp.Test where TVatId : class { [TypeId(0x8ec30e2451f1cffeUL)] - public class Params_getCallerId : ICapnpSerializable + public class Params_GetCallerId : ICapnpSerializable { public const UInt64 typeId = 0x8ec30e2451f1cffeUL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15442,7 +15442,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc71cf776034a3e67UL)] - public class Result_getCallerId : ICapnpSerializable + public class Result_GetCallerId : ICapnpSerializable { public const UInt64 typeId = 0xc71cf776034a3e67UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -15913,7 +15913,7 @@ namespace Capnproto_test.Capnp.Test } AnotherBadFieldName = reader.AnotherBadFieldName; - BadlyNamedUnion = CapnpSerializable.Create(reader.BadlyNamedUnion); + BadlyNamedUnion = CapnpSerializable.Create(reader.BadlyNamedUnion); applyDefaults(); } @@ -15991,7 +15991,7 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion BadlyNamedUnion + public Capnproto_test.Capnp.Test.TestNameAnnotation.badlyNamedUnion BadlyNamedUnion { get; set; @@ -16012,7 +16012,7 @@ namespace Capnproto_test.Capnp.Test public bool BadFieldName => which == WHICH.BadFieldName ? ctx.ReadDataBool(0UL, false) : default; public sbyte Bar => which == WHICH.Bar ? ctx.ReadDataSByte(0UL, (sbyte)0) : default; public Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum AnotherBadFieldName => (Capnproto_test.Capnp.Test.TestNameAnnotation.BadlyNamedEnum)ctx.ReadDataUShort(32UL, (ushort)0); - public @badlyNamedUnion.READER BadlyNamedUnion => new @badlyNamedUnion.READER(ctx); + public badlyNamedUnion.READER BadlyNamedUnion => new badlyNamedUnion.READER(ctx); } public class WRITER : SerializerState @@ -16046,14 +16046,14 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(32UL, (ushort)value, (ushort)0); } - public @badlyNamedUnion.WRITER BadlyNamedUnion + public badlyNamedUnion.WRITER BadlyNamedUnion { - get => Rewrap<@badlyNamedUnion.WRITER>(); + get => Rewrap(); } } [TypeId(0x89d9d1626b34017cUL)] - public class @badlyNamedUnion : ICapnpSerializable + public class badlyNamedUnion : ICapnpSerializable { public const UInt64 typeId = 0x89d9d1626b34017cUL; public enum WHICH : ushort @@ -16069,7 +16069,7 @@ namespace Capnproto_test.Capnp.Test switch (reader.which) { case WHICH.BadlyNamedGroup: - BadlyNamedGroup = CapnpSerializable.Create(reader.BadlyNamedGroup); + BadlyNamedGroup = CapnpSerializable.Create(reader.BadlyNamedGroup); break; case WHICH.Baz: Baz = CapnpSerializable.Create(reader.Baz); @@ -16124,9 +16124,9 @@ namespace Capnproto_test.Capnp.Test { } - public Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion.@badlyNamedGroup BadlyNamedGroup + public Capnproto_test.Capnp.Test.TestNameAnnotation.badlyNamedUnion.badlyNamedGroup BadlyNamedGroup { - get => _which == WHICH.BadlyNamedGroup ? (Capnproto_test.Capnp.Test.TestNameAnnotation.@badlyNamedUnion.@badlyNamedGroup)_content : null; + get => _which == WHICH.BadlyNamedGroup ? (Capnproto_test.Capnp.Test.TestNameAnnotation.badlyNamedUnion.badlyNamedGroup)_content : null; set { _which = WHICH.BadlyNamedGroup; @@ -16156,7 +16156,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator DeserializerState(READER reader) => reader.ctx; public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public WHICH which => (WHICH)ctx.ReadDataUShort(48U, (ushort)0); - public @badlyNamedGroup.READER BadlyNamedGroup => which == WHICH.BadlyNamedGroup ? new @badlyNamedGroup.READER(ctx) : default; + public badlyNamedGroup.READER BadlyNamedGroup => which == WHICH.BadlyNamedGroup ? new badlyNamedGroup.READER(ctx) : default; public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER Baz => which == WHICH.Baz ? ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.READER.create) : default; } @@ -16172,9 +16172,9 @@ namespace Capnproto_test.Capnp.Test set => this.WriteData(48U, (ushort)value, (ushort)0); } - public @badlyNamedGroup.WRITER BadlyNamedGroup + public badlyNamedGroup.WRITER BadlyNamedGroup { - get => which == WHICH.BadlyNamedGroup ? Rewrap<@badlyNamedGroup.WRITER>() : default; + get => which == WHICH.BadlyNamedGroup ? Rewrap() : default; } public Capnproto_test.Capnp.Test.TestNameAnnotation.NestedStruct.WRITER Baz @@ -16185,7 +16185,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xc3594bce5b24b722UL)] - public class @badlyNamedGroup : ICapnpSerializable + public class badlyNamedGroup : ICapnpSerializable { public const UInt64 typeId = 0xc3594bce5b24b722UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16324,19 +16324,19 @@ namespace Capnproto_test.Capnp.Test [TypeId(0xd112a69d31ed918bUL), Proxy(typeof(TestNameAnnotationInterface_Proxy)), Skeleton(typeof(TestNameAnnotationInterface_Skeleton))] public interface ITestNameAnnotationInterface : IDisposable { - Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default); + Task BadlyNamedMethod(byte BadlyNamedParam, CancellationToken cancellationToken_ = default); } public class TestNameAnnotationInterface_Proxy : Proxy, ITestNameAnnotationInterface { - public async Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default) + public async Task BadlyNamedMethod(byte BadlyNamedParam, CancellationToken cancellationToken_ = default) { - var in_ = SerializerState.CreateForRpc(); - var arg_ = new Capnproto_test.Capnp.Test.TestNameAnnotationInterface.Params_badlyNamedMethod() - {BadlyNamedParam = badlyNamedParam}; - arg_.serialize(in_); + var in_ = SerializerState.CreateForRpc(); + var arg_ = new Capnproto_test.Capnp.Test.TestNameAnnotationInterface.Params_BadlyNamedMethod() + {BadlyNamedParam = BadlyNamedParam}; + arg_?.serialize(in_); var d_ = await Call(15065286897585459595UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; - var r_ = CapnpSerializable.Create(d_); + var r_ = CapnpSerializable.Create(d_); return; } } @@ -16351,9 +16351,9 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 15065286897585459595UL; async Task BadlyNamedMethod(DeserializerState d_, CancellationToken cancellationToken_) { - var in_ = CapnpSerializable.Create(d_); + var in_ = CapnpSerializable.Create(d_); await Impl.BadlyNamedMethod(in_.BadlyNamedParam, cancellationToken_); - var s_ = SerializerState.CreateForRpc(); + var s_ = SerializerState.CreateForRpc(); return s_; } } @@ -16361,7 +16361,7 @@ namespace Capnproto_test.Capnp.Test public static class TestNameAnnotationInterface { [TypeId(0xc12efc3b075adfe9UL)] - public class Params_badlyNamedMethod : ICapnpSerializable + public class Params_BadlyNamedMethod : ICapnpSerializable { public const UInt64 typeId = 0xc12efc3b075adfe9UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) @@ -16421,7 +16421,7 @@ namespace Capnproto_test.Capnp.Test } [TypeId(0xdcc3cdb4b28f6c86UL)] - public class Result_badlyNamedMethod : ICapnpSerializable + public class Result_BadlyNamedMethod : ICapnpSerializable { public const UInt64 typeId = 0xdcc3cdb4b28f6c86UL; void ICapnpSerializable.Deserialize(DeserializerState arg_) diff --git a/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs b/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs index 8096b8e..8537a48 100644 --- a/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs +++ b/CapnpC.CSharp.Generator.Tests/FeatureSteps/CodeGeneratorSteps.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.CodeAnalysis; +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Diagnostics; using System.IO; @@ -15,6 +16,8 @@ namespace CapnpC.CSharp.Generator.Tests string _inputSchemaFileName; string _inputSchema; string _referenceOutputContent; + bool _nullableGenEnable; + bool _nullableSupportEnable; GenerationResult _result; @@ -56,6 +59,7 @@ namespace CapnpC.CSharp.Generator.Tests public void GivenIHaveABinaryCodeGeneratorRequest(string binaryRequestFileName) { _inputStream = LoadResource(binaryRequestFileName); + _nullableGenEnable = false; // Assume false by default, may be enabled later } [Given(@"my reference output is ""(.*)""")] @@ -71,9 +75,14 @@ namespace CapnpC.CSharp.Generator.Tests [When(@"I invoke capnpc-csharp")] public void WhenIInvokeCapnpc_Csharp() { + Console.WriteLine($"Generate nullable reference types? {_nullableGenEnable}"); + using (_inputStream) { - _result = CapnpCompilation.GenerateFromStream(_inputStream); + _result = CapnpCompilation.GenerateFromStream(_inputStream, new CodeGen.GeneratorOptions() + { + NullableEnableDefault = _nullableGenEnable + }); } } @@ -113,13 +122,6 @@ namespace CapnpC.CSharp.Generator.Tests Assert.IsNotNull(_result.Exception, "Expected an exception"); } - [Then(@"the invocation must succeed and the generated code must compile")] - public void ThenTheInvocationMustSucceedAndTheGeneratedCodeMustCompile() - { - Assert.IsTrue(_result.IsSuccess, "Tool invocation was not successful"); - Assert.IsTrue(Util.InlineAssemblyCompiler.TryCompileCapnp(_result.GeneratedFiles[0].GeneratedContent), "Compilation was not successful"); - } - [Given(@"capnp\.exe is installed on my system")] public void GivenCapnp_ExeIsInstalledOnMySystem() { @@ -185,5 +187,69 @@ namespace CapnpC.CSharp.Generator.Tests { Assert.IsTrue(_result.Messages.Count >= 2); } + + [Given(@"I enable generation of nullable reference types according to (.*)")] + public void GivenIEnableGenerationOfNullableReferenceTypesAccordingTo(bool enable) + { + _nullableGenEnable = enable; + } + + [Given(@"I enable the compiler support of nullable reference types according to (.*)")] + public void GivenIEnableTheCompilerSupportOfNullableReferenceTypesAccordingTo(bool enable) + { + _nullableSupportEnable = enable; + } + + [Then(@"the invocation must succeed and attempting to compile the generated code gives (.*)")] + public void ThenTheInvocationMustSucceedAndAttemptingToCompileTheGeneratedCodeGives(string result) + { + Console.WriteLine($"Compiler supports nullable reference types? {_nullableSupportEnable}"); + + Assert.IsTrue(_result.IsSuccess, "Tool invocation was not successful"); + var summary = Util.InlineAssemblyCompiler.TryCompileCapnp( + _nullableSupportEnable ? NullableContextOptions.Enable : NullableContextOptions.Disable, + _result.GeneratedFiles[0].GeneratedContent); + + try + { + switch (result) + { + case "success": + Assert.AreEqual( + Util.InlineAssemblyCompiler.CompileSummary.Success, + summary, + "Compilation was expected to succeed"); + break; + + case "warnings": + Assert.AreEqual( + Util.InlineAssemblyCompiler.CompileSummary.SuccessWithWarnings, + summary, + "Compilation was expected to produce warnings"); + break; + + case "errors": + Assert.AreEqual( + Util.InlineAssemblyCompiler.CompileSummary.Error, + summary, + "Compilation was expected to fail"); + break; + + default: + Assert.Fail("Test case bug: unknown outcome specified"); + break; + + } + } + catch (AssertFailedException) + { + string generated = _result.GeneratedFiles.Single().GeneratedContent; + string path = Path.ChangeExtension(Path.GetTempFileName(), ".capnp.cs"); + File.WriteAllText(path, generated); + Console.WriteLine($"Generated code was saved to {path}"); + + throw; + } + } } } diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/NullableDisable.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/NullableDisable.capnp new file mode 100644 index 0000000..c859c9d --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/NullableDisable.capnp @@ -0,0 +1,9 @@ +@0xbbfd48ae4b99d016; + +using CSharp = import "/csharp.capnp"; + +$CSharp.nullableEnable(false); + +struct SomeStruct { + strings @0 : List(Text); +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/NullableDisable2.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/NullableDisable2.capnp new file mode 100644 index 0000000..7e2a074 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/NullableDisable2.capnp @@ -0,0 +1,10 @@ +@0xbbfd48ae4b99d016; + +using CSharp = import "/csharp.capnp"; + +$CSharp.nullableEnable(false); +$CSharp.emitNullableDirective(true); + +struct SomeStruct { + strings @0 : List(Text); +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/NullableEnable.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/NullableEnable.capnp new file mode 100644 index 0000000..9e5833a --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/NullableEnable.capnp @@ -0,0 +1,9 @@ +@0xbbfd48ae4b99d016; + +using CSharp = import "/csharp.capnp"; + +$CSharp.nullableEnable(true); + +struct SomeStruct { + strings @0 : List(Text); +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/NullableEnable2.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/NullableEnable2.capnp new file mode 100644 index 0000000..bff12ed --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/NullableEnable2.capnp @@ -0,0 +1,10 @@ +@0xbbfd48ae4b99d016; + +using CSharp = import "/csharp.capnp"; + +$CSharp.nullableEnable(true); +$CSharp.emitNullableDirective(true); + +struct SomeStruct { + strings @0 : List(Text); +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest13.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest13.capnp new file mode 100644 index 0000000..36db615 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest13.capnp @@ -0,0 +1,8 @@ +@0xbbfd48ae4b99d013; + +using CSharp = import "/csharp.capnp"; + +$CSharp.namespace("Foo.Bar.Baz"); + +struct SomeStruct { +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest14.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest14.capnp new file mode 100644 index 0000000..4472e01 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest14.capnp @@ -0,0 +1,10 @@ +@0xbbfd48ae4b99d014; + +using Cxx = import "/capnp/c++.capnp"; +using CSharp = import "/csharp.capnp"; + +$CSharp.namespace("Foo.Bar.Baz"); +$Cxx.namespace("X::Y::Z"); + +struct SomeStruct { +} diff --git a/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest15.capnp b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest15.capnp new file mode 100644 index 0000000..3968870 --- /dev/null +++ b/CapnpC.CSharp.Generator.Tests/No Resources/UnitTest15.capnp @@ -0,0 +1,25 @@ +@0xbbfd48ae4b99d013; + +using CSharp = import "/csharp.capnp"; + +struct SomeStruct $CSharp.name("CsStruct") { + someField @0 : Int32 $CSharp.name("CsField"); + + someUnion : union $CSharp.name("CsUnion") { + u0 @1 : Int32; + u1 @2 : Int32; + } + + someGroup : group $CSharp.name("CsGroup") { + g0 @3 : Int32; + g1 @4 : Int32; + } +} + +enum SomeEnum $CSharp.name("CsEnum") { + someEnumerant @0 $CSharp.name("CsEnumerant"); +} + +interface SomeInterface $CSharp.name("CsInterface") { + someMethod @0 () -> (someResult :Bool $CSharp.name("CsResult") ) $CSharp.name("CsMethod"); +} diff --git a/CapnpC.CSharp.Generator.Tests/Util/InlineAssemblyCompiler.cs b/CapnpC.CSharp.Generator.Tests/Util/InlineAssemblyCompiler.cs index 3194f0f..2ab94cb 100644 --- a/CapnpC.CSharp.Generator.Tests/Util/InlineAssemblyCompiler.cs +++ b/CapnpC.CSharp.Generator.Tests/Util/InlineAssemblyCompiler.cs @@ -1,25 +1,27 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using System; -using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; -using System.Text; namespace CapnpC.CSharp.Generator.Tests.Util { class InlineAssemblyCompiler { - public static bool TryCompileCapnp(string code) + public enum CompileSummary { - return TryCompileCapnp(new[] {code}); + Success, + SuccessWithWarnings, + Error } - public static bool TryCompileCapnp(string[] code) + public static CompileSummary TryCompileCapnp(NullableContextOptions nullableContextOptions, params string[] code) { var options = new CSharpCompilationOptions( OutputKind.DynamicallyLinkedLibrary, - optimizationLevel: OptimizationLevel.Debug); + optimizationLevel: OptimizationLevel.Debug, + nullableContextOptions: nullableContextOptions); string assemblyRoot = Path.GetDirectoryName(typeof(object).Assembly.Location); @@ -29,9 +31,13 @@ namespace CapnpC.CSharp.Generator.Tests.Util "Capnp.Net.Runtime", "bin", "Debug", - "netcoreapp2.1", + "netcoreapp3.0", "Capnp.Net.Runtime.dll")); + var parseOptions = CSharpParseOptions.Default; + if (nullableContextOptions == NullableContextOptions.Disable) + parseOptions = parseOptions.WithLanguageVersion(LanguageVersion.CSharp7_1); + var compilation = CSharpCompilation.Create( "CompilationTestAssembly", options: options, @@ -42,7 +48,7 @@ namespace CapnpC.CSharp.Generator.Tests.Util MetadataReference.CreateFromFile(Path.Combine(assemblyRoot, "System.Runtime.dll")), MetadataReference.CreateFromFile(Path.Combine(assemblyRoot, "System.Private.CoreLib.dll")), MetadataReference.CreateFromFile(capnpRuntimePath) }, - syntaxTrees: Array.ConvertAll(code, new Converter(c => CSharpSyntaxTree.ParseText(c)))); + syntaxTrees: Array.ConvertAll(code, new Converter(c => CSharpSyntaxTree.ParseText(c, parseOptions)))); using (var stream = new MemoryStream()) { @@ -61,7 +67,17 @@ namespace CapnpC.CSharp.Generator.Tests.Util } } - return emitResult.Success; + if (emitResult.Success) + { + if (emitResult.Diagnostics.Any(diag => diag.Severity == DiagnosticSeverity.Warning)) + return CompileSummary.SuccessWithWarnings; + else + return CompileSummary.Success; + } + else + { + return CompileSummary.Error; + } } } } diff --git a/CapnpC.CSharp.Generator/CapnpCompilation.cs b/CapnpC.CSharp.Generator/CapnpCompilation.cs index 9e9f8d0..2bbf913 100644 --- a/CapnpC.CSharp.Generator/CapnpCompilation.cs +++ b/CapnpC.CSharp.Generator/CapnpCompilation.cs @@ -27,10 +27,11 @@ namespace CapnpC.CSharp.Generator /// /// Generates C# code from given input stream /// - /// input stream containing the binary code generation request, which the frontend capnpc emits + /// Input stream containing the binary code generation request, which the frontend capnpc emits + /// Configuration options for code generator. If null, default options will be used. /// generation result /// if is null - public static GenerationResult GenerateFromStream(Stream input) + public static GenerationResult GenerateFromStream(Stream input, CodeGen.GeneratorOptions options) { if (input == null) throw new ArgumentNullException(nameof(input)); @@ -41,7 +42,7 @@ namespace CapnpC.CSharp.Generator var dec = DeserializerState.CreateRoot(segments); var reader = Schema.CodeGeneratorRequest.Reader.Create(dec); var model = Model.SchemaModel.Create(reader); - var codeGen = new CodeGen.CodeGenerator(model, new CodeGen.GeneratorOptions()); + var codeGen = new CodeGen.CodeGenerator(model, options ?? new CodeGen.GeneratorOptions()); return new GenerationResult(codeGen.Generate()); } catch (Exception exception) @@ -50,6 +51,14 @@ namespace CapnpC.CSharp.Generator } } + /// + /// Generates C# code from given input stream + /// + /// input stream containing the binary code generation request, which the frontend capnpc emits + /// generation result + /// if is null + public static GenerationResult GenerateFromStream(Stream input) => GenerateFromStream(input, null); + /// /// Invokes "capnp.exe -o-" with given additional arguments and redirects the output to the C# generator backend. /// diff --git a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs index e3c5db6..3b8f809 100644 --- a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs +++ b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs @@ -14,6 +14,7 @@ internal class CodeGenerator { readonly SchemaModel _model; + readonly GeneratorOptions _options; readonly GenNames _names; readonly CommonSnippetGen _commonGen; readonly DomainClassSnippetGen _domClassGen; @@ -24,6 +25,7 @@ public CodeGenerator(SchemaModel model, GeneratorOptions options) { _model = model; + _options = options; _names = new GenNames(options); _commonGen = new CommonSnippetGen(_names); _domClassGen = new DomainClassSnippetGen(_names); @@ -61,7 +63,7 @@ { var topDecl = ClassDeclaration(_names.MakeTypeName(def).Identifier) .AddModifiers(Public) - .AddBaseListTypes(SimpleBaseType(Type())); + .AddBaseListTypes(SimpleBaseType(_names.Type(Nullability.NonNullable))); if (def.GenericParameters.Count > 0) { @@ -184,9 +186,25 @@ internal string Transform(GenFile file) { + _names.NullableEnable = file.NullableEnable ?? _options.NullableEnableDefault; + NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace; var ns = NamespaceDeclaration(topNamespace); + + if (file.EmitNullableDirective) + { + ns = ns.WithLeadingTrivia( + Trivia( + NullableDirectiveTrivia( + Token(_names.NullableEnable ? SyntaxKind.EnableKeyword : SyntaxKind.DisableKeyword), + true))) + .WithTrailingTrivia( + Trivia( + NullableDirectiveTrivia( + Token(SyntaxKind.RestoreKeyword), + true))); + } foreach (var def in file.NestedTypes) { @@ -204,7 +222,15 @@ UsingDirective(ParseName("Capnp")), UsingDirective(ParseName("Capnp.Rpc")), UsingDirective(ParseName("System")), - UsingDirective(ParseName("System.Collections.Generic")), + UsingDirective(ParseName("System.Collections.Generic"))); + + if (_names.NullableEnable) + { + cu = cu.AddUsings( + UsingDirective(ParseName("System.Diagnostics.CodeAnalysis"))); + } + + cu = cu.AddUsings( UsingDirective(ParseName("System.Threading")), UsingDirective(ParseName("System.Threading.Tasks"))); diff --git a/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs index c214809..72de969 100644 --- a/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/CommonSnippetGen.cs @@ -22,7 +22,7 @@ namespace CapnpC.CSharp.Generator.CodeGen { var whichEnum = EnumDeclaration(_names.UnionDiscriminatorEnum.ToString()) .AddModifiers(Public) - .AddBaseListTypes(SimpleBaseType(Type())); + .AddBaseListTypes(SimpleBaseType(_names.Type(Nullability.NonNullable))); var discFields = def.Fields.Where(f => f.DiscValue.HasValue); @@ -49,14 +49,14 @@ namespace CapnpC.CSharp.Generator.CodeGen public EnumDeclarationSyntax MakeEnum(TypeDefinition def) { - var decl = EnumDeclaration(def.Name) + var decl = EnumDeclaration(_names.GetCodeIdentifier(def)) .WithAttributeLists(MakeTypeIdAttributeLists(def.Id)) .AddModifiers(Public) - .AddBaseListTypes(SimpleBaseType(Type())); + .AddBaseListTypes(SimpleBaseType(_names.Type(Nullability.NonNullable))); foreach (var enumerant in def.Enumerants.OrderBy(e => e.CodeOrder)) { - var mdecl = EnumMemberDeclaration(enumerant.Literal); + var mdecl = EnumMemberDeclaration(enumerant.CsLiteral ?? enumerant.Literal); if (enumerant.Ordinal.HasValue) { diff --git a/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs index a255b84..17af353 100644 --- a/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/DomainClassSnippetGen.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; using static CapnpC.CSharp.Generator.CodeGen.SyntaxHelpers; +using Microsoft.CodeAnalysis; namespace CapnpC.CSharp.Generator.CodeGen { @@ -20,7 +21,7 @@ namespace CapnpC.CSharp.Generator.CodeGen MemberDeclarationSyntax MakeUnionField(Field field) { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClassNullable); + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClass, Nullability.NullableRefAndValue); switch (field.Type.Tag) { @@ -75,7 +76,8 @@ namespace CapnpC.CSharp.Generator.CodeGen return null; } - var prop = PropertyDeclaration(_names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClass), + var prop = PropertyDeclaration( + _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.DomainClass, Nullability.NullableRef), _names.GetCodeIdentifier(field).Identifier) .AddModifiers(Public).AddAccessorListAccessors( AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) @@ -111,7 +113,7 @@ namespace CapnpC.CSharp.Generator.CodeGen MemberDeclarationSyntax MakeUnionContentField() { return FieldDeclaration( - VariableDeclaration(SyntaxHelpers.Type()) + VariableDeclaration(_names.Type(Nullability.NullableRef)) .WithVariables( SingletonSeparatedList( VariableDeclarator(_names.UnionContentField.Identifier)))) @@ -163,7 +165,7 @@ namespace CapnpC.CSharp.Generator.CodeGen case TypeTag.Enum: return MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - _names.MakeTypeSyntax(value.Type, scope, TypeUsage.NotRelevant), + _names.MakeTypeSyntax(value.Type, scope, TypeUsage.NotRelevant, Nullability.NonNullable), IdentifierName(value.GetEnumerant().Literal)); case TypeTag.F32: @@ -262,7 +264,7 @@ namespace CapnpC.CSharp.Generator.CodeGen value.Decode(); return ObjectCreationExpression( - _names.MakeTypeSyntax(value.Type, scope, TypeUsage.DomainClass)) + _names.MakeTypeSyntax(value.Type, scope, TypeUsage.DomainClass, Nullability.NonNullable)) .WithArgumentList(ArgumentList()) .WithInitializer( InitializerExpression( @@ -282,7 +284,7 @@ namespace CapnpC.CSharp.Generator.CodeGen value.Decode(); return ArrayCreationExpression(ArrayType( - _names.MakeTypeSyntax(value.Type.ElementType, scope, TypeUsage.DomainClass)) + _names.MakeTypeSyntax(value.Type.ElementType, scope, TypeUsage.DomainClass, Nullability.NullableRef)) .WithRankSpecifiers( SingletonList( ArrayRankSpecifier( @@ -344,7 +346,7 @@ namespace CapnpC.CSharp.Generator.CodeGen case TypeTag.Enum: return CastExpression( - _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant), + _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant, Nullability.NonNullable), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))); case TypeTag.F32: @@ -451,13 +453,18 @@ namespace CapnpC.CSharp.Generator.CodeGen Argument(domain), Argument( ParenthesizedLambdaExpression( + ParameterList( + SeparatedList( + new SyntaxNodeOrToken[] + { + Parameter(Identifier(s)), + Token(SyntaxKind.CommaToken), + Parameter(Identifier(v)) + })), MakeComplexSerializeParticle( type.ElementType, IdentifierName(s), - IdentifierName(v))) - .AddParameterListParameters( - Parameter(Identifier(s)), - Parameter(Identifier(v))))); + IdentifierName(v))))); default: return InvocationExpression( @@ -488,6 +495,11 @@ namespace CapnpC.CSharp.Generator.CodeGen } } + ExpressionSyntax ConditionalSuppressNullableWarning(ExpressionSyntax expression, bool suppress) + { + return suppress ? _names.SuppressNullableWarning(expression) : expression; + } + StatementSyntax MakeSerializeMethodFieldAssignment(Field field) { var writerProp = MemberAccessExpression( @@ -519,7 +531,7 @@ namespace CapnpC.CSharp.Generator.CodeGen writerProp, MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - _names.GetCodeIdentifier(field).IdentifierName, + _names.SuppressNullableWarning(_names.GetCodeIdentifier(field).IdentifierName), IdentifierName(nameof(Nullable.Value))))); } else @@ -538,10 +550,11 @@ namespace CapnpC.CSharp.Generator.CodeGen InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - MemberAccessExpression( + ConditionalSuppressNullableWarning(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, _names.WriterParameter.IdentifierName, _names.GetCodeIdentifier(field).IdentifierName), + field.DiscValue.HasValue), IdentifierName(nameof(Capnp.DynamicSerializerState.SetObject)))) .AddArgumentListArguments( Argument(_names.GetCodeIdentifier(field).IdentifierName))); @@ -568,7 +581,7 @@ namespace CapnpC.CSharp.Generator.CodeGen return ExpressionStatement( MakeComplexSerializeParticle( field.Type, - writerProp, + field.DiscValue.HasValue ? _names.SuppressNullableWarning(writerProp) : writerProp, _names.GetCodeIdentifier(field).IdentifierName)); case TypeTag.Void: @@ -599,20 +612,20 @@ namespace CapnpC.CSharp.Generator.CodeGen ExpressionSyntax MakeInnerStructListConversion(ExpressionSyntax context, TypeSyntax elementType) { - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) - .AddArgumentListArguments(Argument( - SimpleLambdaExpression(Parameter(Identifier("_")), - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName(nameof(Capnp.CapnpSerializable)), - GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments(elementType))) - .AddArgumentListArguments(Argument(IdentifierName("_")))))); + return ConditionalAccessExpression( + context, + InvocationExpression( + MemberBindingExpression( + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) + .AddArgumentListArguments(Argument( + SimpleLambdaExpression(Parameter(Identifier("_")), + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName(nameof(Capnp.CapnpSerializable)), + GenericName(nameof(Capnp.CapnpSerializable.Create)) + .AddTypeArgumentListArguments(MakeNonNullableType(elementType)))) + .AddArgumentListArguments(Argument(IdentifierName("_"))))))); } ExpressionSyntax MakeStructListConversion(ExpressionSyntax context, TypeSyntax elementType, int rank) @@ -624,28 +637,28 @@ namespace CapnpC.CSharp.Generator.CodeGen string lambdaVarName = $"_{rank}"; - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) - .AddArgumentListArguments(Argument( - SimpleLambdaExpression( - Parameter(Identifier(lambdaVarName)), - MakeStructListConversion(IdentifierName(lambdaVarName), elementType, rank - 1)))); + return ConditionalAccessExpression( + context, + InvocationExpression( + MemberBindingExpression( + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) + .AddArgumentListArguments(Argument( + SimpleLambdaExpression( + Parameter(Identifier(lambdaVarName)), + MakeStructListConversion(IdentifierName(lambdaVarName), elementType, rank - 1))))); } ExpressionSyntax MakeAnyListConversion(ExpressionSyntax context) { - return InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - context, - IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) - .AddArgumentListArguments(Argument( - SimpleLambdaExpression( - Parameter(Identifier("_")), - CastExpression(Type(), IdentifierName("_"))))); + return ConditionalAccessExpression( + context, + InvocationExpression( + MemberBindingExpression( + IdentifierName(nameof(Capnp.ReadOnlyListExtensions.ToReadOnlyList)))) + .AddArgumentListArguments(Argument( + SimpleLambdaExpression( + Parameter(Identifier("_")), + CastExpression(_names.Type(Nullability.NonNullable), IdentifierName("_")))))); } ExpressionSyntax MakeDeserializeMethodRightHandSide(Field field) @@ -662,10 +675,11 @@ namespace CapnpC.CSharp.Generator.CodeGen IdentifierName(nameof(Capnp.CapnpSerializable)), GenericName(nameof(Capnp.CapnpSerializable.Create)) .AddTypeArgumentListArguments( - _names.MakeTypeSyntax( + MakeNonNullableType(_names.MakeTypeSyntax( field.Type, field.DeclaringType, - TypeUsage.DomainClass)))) + TypeUsage.DomainClass, + Nullability.NonNullable))))) .AddArgumentListArguments(Argument(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, _names.ReaderParameter.IdentifierName, @@ -684,7 +698,7 @@ namespace CapnpC.CSharp.Generator.CodeGen SyntaxKind.SimpleMemberAccessExpression, _names.ReaderParameter.IdentifierName, _names.GetCodeIdentifier(field).IdentifierName), - _names.MakeTypeSyntax(elementType, field.DeclaringType, TypeUsage.DomainClass), + _names.MakeTypeSyntax(elementType, field.DeclaringType, TypeUsage.DomainClass, Nullability.NullableRef), rank); case TypeTag.ListPointer: @@ -716,18 +730,6 @@ namespace CapnpC.CSharp.Generator.CodeGen if (unionField.Type.Tag != TypeTag.Void) { - ExpressionSyntax right = _names.GetCodeIdentifier(unionField).IdentifierName; - - var syntax = _names.MakeTypeSyntax(unionField.Type, unionField.DeclaringType, TypeUsage.DomainClassNullable); - - if (syntax is NullableTypeSyntax) - { - right = MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - right, - IdentifierName(nameof(Nullable.Value))); - } - section = section.AddStatements(MakeSerializeMethodFieldAssignment(unionField)); } @@ -849,7 +851,7 @@ namespace CapnpC.CSharp.Generator.CodeGen ExplicitInterfaceSpecifier(IdentifierName(nameof(Capnp.ICapnpSerializable)))) .AddParameterListParameters( Parameter(_names.AnonymousParameter.Identifier) - .WithType(Type())) + .WithType(_names.Type(Nullability.NonNullable))) .AddBodyStatements( ExpressionStatement( InvocationExpression(_names.SerializeMethod.IdentifierName) @@ -933,7 +935,7 @@ namespace CapnpC.CSharp.Generator.CodeGen ExplicitInterfaceSpecifier(IdentifierName(nameof(Capnp.ICapnpSerializable)))) .AddParameterListParameters( Parameter(_names.AnonymousParameter.Identifier) - .WithType(Type())) + .WithType(_names.Type(Nullability.NonNullable))) .AddBodyStatements(stmts.ToArray()); } @@ -944,7 +946,10 @@ namespace CapnpC.CSharp.Generator.CodeGen if (def.UnionInfo != null) { yield return MakeUnionDiscriminatorField(); - yield return MakeUnionContentField(); + if (def.Fields.Any(f => f.DiscValue.HasValue && f.Type.Tag != TypeTag.Void)) + { + yield return MakeUnionContentField(); + } yield return MakeUnionDiscriminatorProperty(def); } diff --git a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs index 42c5938..b16ff99 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs @@ -22,11 +22,17 @@ namespace CapnpC.CSharp.Generator.CodeGen { NotRelevant, DomainClass, - DomainClassNullable, Reader, Writer } + enum Nullability + { + NonNullable, + NullableRefAndValue, + NullableRef + } + class GenNames { readonly Dictionary _fieldNameMap = new Dictionary(); @@ -66,6 +72,7 @@ namespace CapnpC.CSharp.Generator.CodeGen public string PipeliningExtensionsClassFormat { get; } public string ProxyClassFormat { get; } public string SkeletonClassFormat { get; } + public bool NullableEnable { get; set; } public GenNames(GeneratorOptions options) { TopNamespace = new Name(options.TopNamespaceName).IdentifierName; @@ -107,61 +114,54 @@ namespace CapnpC.CSharp.Generator.CodeGen public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) { - if (def.Tag == TypeTag.Group) + string name; + + switch (usage) { - return new Name(SyntaxHelpers.MakeAllLower(def.Name)); + case NameUsage.Default: + if (def.Tag == TypeTag.Interface) + goto case NameUsage.Interface; + + switch (def.SpecialName) + { + case SpecialName.NothingSpecial: + name = GetCodeIdentifier(def); + break; + + case SpecialName.MethodParamsStruct: + name = MakeParamsStructName(def.UsingMethod); + break; + + case SpecialName.MethodResultStruct: + name = MakeResultStructName(def.UsingMethod); + break; + + default: + throw new NotImplementedException(); + } + break; + + case NameUsage.Namespace: + name = GetCodeIdentifier(def); + break; + + case NameUsage.Interface: + name = "I" + GetCodeIdentifier(def); + break; + + case NameUsage.Proxy: + name = string.Format(ProxyClassFormat, GetCodeIdentifier(def)); + break; + + case NameUsage.Skeleton: + name = string.Format(SkeletonClassFormat, GetCodeIdentifier(def)); + break; + + default: + throw new NotImplementedException(); } - else - { - string name; - switch (usage) - { - case NameUsage.Default: - if (def.Tag == TypeTag.Interface) - goto case NameUsage.Interface; - - switch (def.SpecialName) - { - case SpecialName.NothingSpecial: - name = def.Name; - break; - - case SpecialName.MethodParamsStruct: - name = MakeParamsStructName(def.UsingMethod); - break; - - case SpecialName.MethodResultStruct: - name = MakeResultStructName(def.UsingMethod); - break; - - default: - throw new NotImplementedException(); - } - break; - - case NameUsage.Namespace: - name = def.Name; - break; - - case NameUsage.Interface: - name = "I" + def.Name; - break; - - case NameUsage.Proxy: - name = string.Format(ProxyClassFormat, def.Name); - break; - - case NameUsage.Skeleton: - name = string.Format(SkeletonClassFormat, def.Name); - break; - - default: - throw new NotImplementedException(); - } - - return new Name(name); - } + return new Name(name); } public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) @@ -184,7 +184,7 @@ namespace CapnpC.CSharp.Generator.CodeGen TypeSyntax ResolveGenericParameter(GenericParameter p, Model.Type boundType, TypeDefinition def) { var type = boundType.ResolveGenericParameter(p); - return MakeTypeSyntax(type, def, TypeUsage.DomainClass); + return MakeTypeSyntax(type, def, TypeUsage.DomainClass, Nullability.NonNullable); } public SimpleNameSyntax MakeGenericTypeName(TypeDefinition def, Model.Type boundType, NameUsage usage = NameUsage.Default) @@ -224,10 +224,10 @@ namespace CapnpC.CSharp.Generator.CodeGen NameSyntax ident = null; if (@namespace != null) { - ident = IdentifierName(SyntaxHelpers.MakeCamel(@namespace[0])); + ident = IdentifierName(SyntaxHelpers.MakeUpperCamel(@namespace[0])); foreach (string name in @namespace.Skip(1)) { - var temp = IdentifierName(SyntaxHelpers.MakeCamel(name)); + var temp = IdentifierName(SyntaxHelpers.MakeUpperCamel(name)); ident = QualifiedName(ident, temp); } } @@ -288,82 +288,82 @@ namespace CapnpC.CSharp.Generator.CodeGen case TypeTag.AnyPointer: case TypeTag.StructPointer: case TypeTag.ListPointer: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.CapabilityPointer: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.Data: - return SyntaxHelpers.Type>>(); + return Type>>(Nullability.NonNullable); case TypeTag.Enum: return GenericName("ListOfPrimitivesSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer, Nullability.NonNullable)); case TypeTag.Group: case TypeTag.Struct: return GenericName("ListOfStructsSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer, Nullability.NonNullable)); case TypeTag.Interface: return GenericName("ListOfCapsSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer, Nullability.NonNullable)); case TypeTag.List: return GenericName("ListOfPointersSerializer") - .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer)); + .AddTypeArgumentListArguments(MakeTypeSyntax(elementType, scope, TypeUsage.Writer, Nullability.NonNullable)); case TypeTag.Text: - return SyntaxHelpers.Type(); + return Type(Nullability.NonNullable); case TypeTag.Void: - return SyntaxHelpers.Type(); + return Type(Nullability.NonNullable); case TypeTag.Bool: - return SyntaxHelpers.Type(); + return Type(Nullability.NonNullable); case TypeTag.F32: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.F64: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.S8: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.U8: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.S16: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.U16: case TypeTag.AnyEnum: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.S32: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.U32: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.S64: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); case TypeTag.U64: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); default: throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); } } - TypeSyntax MaybeNullableValueType(TypeSyntax typeSyntax, TypeUsage usage) + TypeSyntax MaybeNullableValueType(TypeSyntax typeSyntax, Nullability nullability) { - switch (usage) + switch (nullability) { - case TypeUsage.DomainClassNullable: + case Nullability.NullableRefAndValue: return NullableType(typeSyntax); default: @@ -371,71 +371,80 @@ namespace CapnpC.CSharp.Generator.CodeGen } } - public TypeSyntax MakeTypeSyntax(Model.Type type, TypeDefinition scope, TypeUsage usage) + TypeSyntax MaybeNullableRefType(TypeSyntax typeSyntax, Nullability nullability) + { + if (!NullableEnable) + return typeSyntax; + + switch (nullability) + { + case Nullability.NullableRef: + case Nullability.NullableRefAndValue: + return NullableType(typeSyntax); + + default: + return typeSyntax; + } + } + + public TypeSyntax MakeTypeSyntax(Model.Type type, TypeDefinition scope, TypeUsage usage, Nullability nullability) { switch (type.Tag) { case TypeTag.AnyEnum: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.CapabilityPointer: if (type.Parameter != null) - { - return GetQName(type, scope); - } + return MaybeNullableRefType(GetQName(type, scope), nullability); else - { - return SyntaxHelpers.Type(); - } + return Type(nullability); case TypeTag.AnyPointer: case TypeTag.StructPointer: switch (usage) { case TypeUsage.Reader: - return SyntaxHelpers.Type(); + return Type(Nullability.NonNullable); case TypeUsage.Writer: - return SyntaxHelpers.Type(); + return Type(Nullability.NullableRef); + + case TypeUsage.DomainClass when type.Parameter == null: + return Type(nullability); + + case TypeUsage.DomainClass when nullability == Nullability.NonNullable: + return GetQName(type, scope); case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - if (type.Parameter != null) - { - return GetQName(type, scope); - } - else - { - return SyntaxHelpers.Type(); - } + return MakeNullableRefType(GetQName(type, scope)); default: throw new NotImplementedException(); } case TypeTag.Bool: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.Data: switch (usage) { case TypeUsage.Reader: case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return SyntaxHelpers.Type>(); + return Type>(nullability); case TypeUsage.Writer: - return SyntaxHelpers.Type>(); + return Type>(nullability); default: throw new NotImplementedException(); } case TypeTag.Enum: - return MaybeNullableValueType(GetQName(type, scope), usage); + return MaybeNullableValueType(GetQName(type, scope), nullability); case TypeTag.Interface: - return GetQName(type, scope); + return MaybeNullableRefType(GetQName(type, scope), nullability); case TypeTag.Struct: case TypeTag.Group: @@ -447,37 +456,38 @@ namespace CapnpC.CSharp.Generator.CodeGen case TypeUsage.Reader: return QualifiedName(GetQName(type, scope), ReaderStruct.IdentifierName); - case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: + case TypeUsage.DomainClass when nullability == Nullability.NonNullable: return GetQName(type, scope); + case TypeUsage.DomainClass: + return MakeNullableRefType(GetQName(type, scope)); + default: throw new NotImplementedException(); } case TypeTag.F32: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.F64: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.List when type.ElementType.Tag == TypeTag.Void && usage != TypeUsage.Writer: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.List: switch (usage) { case TypeUsage.Writer: - return MakeListSerializerSyntax(type.ElementType, scope); + return MaybeNullableRefType(MakeListSerializerSyntax(type.ElementType, scope), nullability); case TypeUsage.Reader: - return GenericName(Identifier("IReadOnlyList")) - .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.Reader)); + return MaybeNullableRefType(GenericName(Identifier("IReadOnlyList")) + .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.Reader, Nullability.NonNullable)), nullability); case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return GenericName(Identifier("IReadOnlyList")) - .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.DomainClass)); + return MaybeNullableRefType(GenericName(Identifier("IReadOnlyList")) + .AddTypeArgumentListArguments(MakeTypeSyntax(type.ElementType, scope, TypeUsage.DomainClass, Nullability.NullableRef)), nullability); default: throw new NotImplementedException(); @@ -487,45 +497,49 @@ namespace CapnpC.CSharp.Generator.CodeGen switch (usage) { case TypeUsage.Writer: - return SyntaxHelpers.Type(); + return Type(Nullability.NonNullable); case TypeUsage.Reader: - return SyntaxHelpers.Type>(); + return Type>(Nullability.NonNullable); + + case TypeUsage.DomainClass when nullability == Nullability.NonNullable: + return GenericName(Identifier("IReadOnlyList")) + .AddTypeArgumentListArguments(Type(Nullability.NullableRef)); case TypeUsage.DomainClass: - case TypeUsage.DomainClassNullable: - return SyntaxHelpers.Type>(); + return MakeNullableRefType(GenericName(Identifier("IReadOnlyList")) + .AddTypeArgumentListArguments(Type(Nullability.NullableRef))); default: throw new NotImplementedException(); } case TypeTag.S16: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.S32: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.S64: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.S8: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.Text: - return SyntaxHelpers.Type(); + return Type(nullability); case TypeTag.U16: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.U32: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.U64: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.U8: - return MaybeNullableValueType(SyntaxHelpers.Type(), usage); + return Type(nullability); case TypeTag.Void: return PredefinedType(Token(SyntaxKind.VoidKeyword)); @@ -537,19 +551,22 @@ namespace CapnpC.CSharp.Generator.CodeGen public string MakeParamsStructName(Method method) { - return string.Format(ParamsStructFormat, method.Name); + return string.Format(ParamsStructFormat, GetCodeIdentifier(method)); } public string MakeResultStructName(Method method) { - return string.Format(ResultStructFormat, method.Name); + return string.Format(ResultStructFormat, GetCodeIdentifier(method)); } public Name GetCodeIdentifier(Method method) { - return new Name(SyntaxHelpers.MakeCamel(method.Name)); + return new Name(method.CsName ?? IdentifierRenamer.ToNonKeyword(SyntaxHelpers.MakeUpperCamel(method.Name))); } + string GetCodeIdentifierUpperCamel(Field field) => field.CsName ?? SyntaxHelpers.MakeUpperCamel(field.Name); + string GetCodeIdentifierLowerCamel(Field field) => field.CsName ?? IdentifierRenamer.ToNonKeyword(SyntaxHelpers.MakeLowerCamel(field.Name)); + public Name GetCodeIdentifier(Field field) { if (_fieldNameMap.TryGetValue(field, out var name)) @@ -563,7 +580,7 @@ namespace CapnpC.CSharp.Generator.CodeGen { // Method parameters are internally represented with the same class "Field". // They do not have a declaring type. Anyway, they don't suffer from the field-name-equals-nested-type-name problem. - return new Name(SyntaxHelpers.MakeCamel(field.Name)); + return new Name(GetCodeIdentifierLowerCamel(field)); } var typeNames = new HashSet(def.NestedTypes.Select(t => MakeTypeName(t))); @@ -571,7 +588,7 @@ namespace CapnpC.CSharp.Generator.CodeGen foreach (var member in def.Fields) { - var memberName = new Name(SyntaxHelpers.MakeCamel(member.Name)); + var memberName = new Name(GetCodeIdentifierUpperCamel(member)); while (typeNames.Contains(memberName)) { @@ -584,6 +601,16 @@ namespace CapnpC.CSharp.Generator.CodeGen return _fieldNameMap[field]; } + public string GetCodeIdentifier(TypeDefinition def) + { + string id = def.CsName ?? def.Name; + if (def.Tag == TypeTag.Group) // special treatment for groups: Need to disambiguate between + { // the field name (use original name) and its type (make it start with a lower-case letter) + id = IdentifierRenamer.ToNonKeyword(SyntaxHelpers.MakeLowerCamel(id)); + } + return id; + } + public Name GetGenericTypeParameter(string name) { return new Name(string.Format(GenericTypeParameterFormat, name)); @@ -637,5 +664,28 @@ namespace CapnpC.CSharp.Generator.CodeGen method.Name, MakePipeliningSupportExtensionMethodName(path))); } + + public TypeSyntax MakeNullableRefType(TypeSyntax type) + { + return NullableEnable ? + NullableType(type) : + type; + + } + + public TypeSyntax Type(Nullability nullability) + { + return (NullableEnable && !typeof(T).IsValueType && nullability != Nullability.NonNullable) || + ( typeof(T).IsValueType && nullability == Nullability.NullableRefAndValue) ? + NullableType(SyntaxHelpers.NonNullableType()) : + SyntaxHelpers.NonNullableType(); + } + + public ExpressionSyntax SuppressNullableWarning(ExpressionSyntax expression) + { + return NullableEnable ? + PostfixUnaryExpression(SyntaxKind.SuppressNullableWarningExpression, expression) : + expression; + } } } diff --git a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs index 8357cee..3a3eccf 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs @@ -1,6 +1,6 @@ namespace CapnpC.CSharp.Generator.CodeGen { - class GeneratorOptions + public class GeneratorOptions { public string TopNamespaceName { get; set; } = "CapnpGen"; public string ReaderStructName { get; set; } = "READER"; @@ -37,5 +37,6 @@ public string TaskParameterName { get; set; } = "task"; public string EagerMethodName { get; set; } = "Eager"; public string TypeIdFieldName { get; set; } = "typeId"; + public bool NullableEnableDefault { get; set; } = false; } } diff --git a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs index 6344b85..c683f3b 100644 --- a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using System.Threading.Tasks; using System.Threading; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis; namespace CapnpC.CSharp.Generator.CodeGen { @@ -27,15 +28,19 @@ namespace CapnpC.CSharp.Generator.CodeGen case 0: return IdentifierName(nameof(Task)); + case 1 when method.Results[0].Type.Tag == TypeTag.Struct: + return GenericName(nameof(Task)).AddTypeArgumentListArguments( + _names.MakeTypeSyntax(method.Results[0].Type, method.DeclaringInterface, TypeUsage.DomainClass, Nullability.NonNullable)); + case 1: return GenericName(nameof(Task)).AddTypeArgumentListArguments( - _names.MakeTypeSyntax(method.Results[0].Type, method.DeclaringInterface, TypeUsage.DomainClass)); + _names.MakeTypeSyntax(method.Results[0].Type, method.DeclaringInterface, TypeUsage.DomainClass, Nullability.NullableRef)); default: return GenericName(nameof(Task)).AddTypeArgumentListArguments( TupleType(SeparatedList( method.Results.Select( - f => TupleElement(_names.MakeTypeSyntax(f.Type, method.DeclaringInterface, TypeUsage.DomainClass)))))); + f => TupleElement(_names.MakeTypeSyntax(f.Type, method.DeclaringInterface, TypeUsage.DomainClass, Nullability.NullableRef)))))); } } @@ -50,14 +55,14 @@ namespace CapnpC.CSharp.Generator.CodeGen if (arg0.Name == null) { list.Add(Parameter(_names.AnonymousParameter.Identifier) - .WithType(_names.MakeTypeSyntax(arg0.Type, method.DeclaringInterface, TypeUsage.DomainClass))); + .WithType(_names.MakeTypeSyntax(arg0.Type, method.DeclaringInterface, TypeUsage.DomainClass, Nullability.NullableRef))); } else { foreach (var arg in method.Params) { - list.Add(Parameter(Identifier(IdentifierRenamer.ToNonKeyword(arg.Name))) - .WithType(_names.MakeTypeSyntax(arg.Type, method.DeclaringInterface, TypeUsage.DomainClass))); + list.Add(Parameter(_names.GetCodeIdentifier(arg).Identifier) + .WithType(_names.MakeTypeSyntax(arg.Type, method.DeclaringInterface, TypeUsage.DomainClass, Nullability.NullableRef))); } } } @@ -124,7 +129,8 @@ namespace CapnpC.CSharp.Generator.CodeGen ifaceDecl = ifaceDecl.AddBaseListTypes( SimpleBaseType(_names.MakeTypeSyntax( superClass, type, - TypeUsage.NotRelevant))); + TypeUsage.DomainClass, + Nullability.NonNullable))); } } @@ -182,12 +188,15 @@ namespace CapnpC.CSharp.Generator.CodeGen IEnumerable MakeProxyCallInitializerAssignments(Method method) { - foreach (var methodParam in method.Params) + for (int i = 0; i < method.Params.Count; i++) { + var methodParam = method.Params[i]; + var field = method.ParamsStruct.Fields[i]; + yield return AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, - _names.GetCodeIdentifier(methodParam).IdentifierName, - IdentifierName(IdentifierRenamer.ToNonKeyword(methodParam.Name))); + _names.GetCodeIdentifier(field).IdentifierName, + _names.GetCodeIdentifier(methodParam).IdentifierName); } } @@ -226,17 +235,24 @@ namespace CapnpC.CSharp.Generator.CodeGen StatementSyntax MakeProxyCreateResult(Method method) { var resultType = method.ResultStruct; - var domainType = _names.MakeTypeSyntax(resultType, method.DeclaringInterface, TypeUsage.DomainClass); + var domainType = _names.MakeTypeSyntax(resultType, method.DeclaringInterface, TypeUsage.DomainClass, Nullability.NonNullable); - var createDomain = InvocationExpression( + ExpressionSyntax createDomain = InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName(nameof(Capnp.CapnpSerializable)), GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments(domainType))) + .AddTypeArgumentListArguments(MakeNonNullableType(domainType)))) .AddArgumentListArguments( Argument(_names.DeserializerLocal.IdentifierName)); + if (_names.NullableEnable) + { + createDomain = PostfixUnaryExpression( + SyntaxKind.SuppressNullableWarningExpression, + createDomain); + } + return LocalDeclarationStatement( VariableDeclaration( IdentifierName("var")) @@ -271,7 +287,7 @@ namespace CapnpC.CSharp.Generator.CodeGen var classDecl = ClassDeclaration(_names.MakeTypeName(type, NameUsage.Proxy).Identifier) .AddModifiers(Public) .AddBaseListTypes( - SimpleBaseType(Type()), + SimpleBaseType(_names.Type(Nullability.NonNullable)), SimpleBaseType(_names.MakeGenericTypeName(type, NameUsage.Interface))); if (type.GenericParameters.Count > 0) @@ -311,7 +327,7 @@ namespace CapnpC.CSharp.Generator.CodeGen _names.MakeTypeSyntax( method.ParamsStruct, method.ParamsStruct.Definition, - TypeUsage.Writer)))))))))))); + TypeUsage.Writer, Nullability.NonNullable)))))))))))); if (method.ParamsStruct.Definition.SpecialName == SpecialName.MethodParamsStruct) { @@ -328,7 +344,8 @@ namespace CapnpC.CSharp.Generator.CodeGen _names.MakeTypeSyntax( method.ParamsStruct, method.ParamsStruct.Definition, - TypeUsage.DomainClass)) + TypeUsage.DomainClass, + Nullability.NonNullable)) .WithArgumentList( ArgumentList()) .WithInitializer( @@ -340,13 +357,12 @@ namespace CapnpC.CSharp.Generator.CodeGen } bodyStmts.Add(ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - _names.AnonymousParameter.IdentifierName, - _names.SerializeMethod.IdentifierName)) - .AddArgumentListArguments( - Argument(_names.ParamsLocal.IdentifierName)))); + ConditionalAccessExpression( + _names.AnonymousParameter.IdentifierName, + InvocationExpression( + MemberBindingExpression(_names.SerializeMethod.IdentifierName)) + .AddArgumentListArguments( + Argument(_names.ParamsLocal.IdentifierName))))); var call = InvocationExpression(IdentifierName(nameof(Capnp.Rpc.BareProxy.Call))) .AddArgumentListArguments( @@ -361,7 +377,7 @@ namespace CapnpC.CSharp.Generator.CodeGen SyntaxKind.SimpleMemberAccessExpression, _names.ParamsLocal.IdentifierName, GenericName(nameof(Capnp.SerializerState.Rewrap)) - .AddTypeArgumentListArguments(Type()))) + .AddTypeArgumentListArguments(_names.Type(Nullability.NonNullable)))) .AddArgumentListArguments()), Argument( LiteralExpression(SyntaxKind.FalseLiteralExpression)), @@ -446,7 +462,7 @@ namespace CapnpC.CSharp.Generator.CodeGen GenericName(_names.GetCodeIdentifier(method).ToString()) .AddTypeArgumentListArguments( Enumerable.Repeat( - Type(), + _names.Type(Nullability.NonNullable), method.GenericParameters.Count).ToArray())); } else @@ -502,7 +518,7 @@ namespace CapnpC.CSharp.Generator.CodeGen _names.MakeTypeSyntax( method.ResultStruct, method.ResultStruct.Definition, - TypeUsage.Writer))))))))))); + TypeUsage.Writer, Nullability.NonNullable))))))))))); } @@ -523,7 +539,8 @@ namespace CapnpC.CSharp.Generator.CodeGen _names.MakeTypeSyntax( method.ResultStruct, method.ResultStruct.Definition, - TypeUsage.DomainClass)) + TypeUsage.DomainClass, + Nullability.NonNullable)) .WithInitializer( InitializerExpression(SyntaxKind.ObjectInitializerExpression) .AddExpressions( @@ -575,17 +592,24 @@ namespace CapnpC.CSharp.Generator.CodeGen if (method.Params.Count > 0) { var paramsType = method.ParamsStruct; - var domainType = _names.MakeTypeSyntax(paramsType, method.ParamsStruct.Definition, TypeUsage.DomainClass); + var domainType = _names.MakeTypeSyntax(paramsType, method.ParamsStruct.Definition, TypeUsage.DomainClass, Nullability.NonNullable); - var createDomain = InvocationExpression( + ExpressionSyntax createDomain = InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName(nameof(Capnp.CapnpSerializable)), GenericName(nameof(Capnp.CapnpSerializable.Create)) - .AddTypeArgumentListArguments(domainType))) + .AddTypeArgumentListArguments(MakeNonNullableType(domainType)))) .AddArgumentListArguments( Argument(_names.DeserializerLocal.IdentifierName)); + if (_names.NullableEnable) + { + createDomain = PostfixUnaryExpression( + SyntaxKind.SuppressNullableWarningExpression, + createDomain); + } + if (method.ParamsStruct.Definition.SpecialName == SpecialName.MethodParamsStruct) { yield return LocalDeclarationStatement( @@ -630,10 +654,19 @@ namespace CapnpC.CSharp.Generator.CodeGen } else { + // CodeAnalysis.CSharp 3.2.1 has a bug which prevents us from using AddParameterListParameters. :-( + + var paramList = new List(); + foreach (var arg in method.Results) + { + if (paramList.Count > 0) + paramList.Add(Token(SyntaxKind.CommaToken)); + paramList.Add(Parameter(Identifier(arg.Name))); + } lambdaArg = ParenthesizedLambdaExpression( - MakeMaybeTailCallLambdaBody(method)) - .AddParameterListParameters( - method.Results.Select(arg => Parameter(Identifier(arg.Name))).ToArray()); + ParameterList( + SeparatedList(paramList)), + MakeMaybeTailCallLambdaBody(method)); } } else @@ -662,13 +695,13 @@ namespace CapnpC.CSharp.Generator.CodeGen foreach (var method in def.Methods) { var methodDecl = MethodDeclaration( - Type>(), + _names.Type>(Nullability.NonNullable), _names.GetCodeIdentifier(method).Identifier) .AddParameterListParameters( Parameter(_names.DeserializerLocal.Identifier) - .WithType(Type()), + .WithType(_names.Type(Nullability.NonNullable)), Parameter(_names.CancellationTokenParameter.Identifier) - .WithType(Type())) + .WithType(_names.Type(Nullability.NonNullable))) .AddBodyStatements( MakeSkeletonMethodBody(method).ToArray()); @@ -709,7 +742,7 @@ namespace CapnpC.CSharp.Generator.CodeGen .AddArgumentListArguments( MakeSkeletonSetMethodTableArguments(type).ToArray()))), // InterfaceId - PropertyDeclaration(Type(), nameof(Capnp.Rpc.Skeleton.InterfaceId)) + PropertyDeclaration(_names.Type(Nullability.NonNullable), nameof(Capnp.Rpc.Skeleton.InterfaceId)) .AddModifiers(Public, Override) .WithExpressionBody( ArrowExpressionClause( @@ -790,7 +823,7 @@ namespace CapnpC.CSharp.Generator.CodeGen var accessPath = _names.MakeMemberAccessPathFieldName(method, path); var methodName = _names.MakePipeliningSupportExtensionMethodName(path); var capType = path[path.Count - 1].Type; - var capTypeSyntax = _names.MakeTypeSyntax(capType, null, TypeUsage.DomainClass); + var capTypeSyntax = _names.MakeTypeSyntax(capType, null, TypeUsage.DomainClass, Nullability.NonNullable); if (!_existingExtensionMethods.Add((capTypeSyntax.ToString(), methodName.ToString()))) { @@ -815,9 +848,7 @@ namespace CapnpC.CSharp.Generator.CodeGen .AddModifiers(Static, Readonly); - var methodDecl = MethodDeclaration( - capTypeSyntax, - methodName.Identifier) + var methodDecl = MethodDeclaration(capTypeSyntax, methodName.Identifier) .AddModifiers(Public, Static) .AddParameterListParameters( Parameter( diff --git a/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs index 869acf1..8a800ad 100644 --- a/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/ReaderSnippetGen.cs @@ -57,7 +57,7 @@ namespace CapnpC.CSharp.Generator.CodeGen ParameterList( SingletonSeparatedList( Parameter(_names.ReaderContextField.Identifier) - .WithType(Type())))) + .WithType(_names.Type(Nullability.NonNullable))))) .WithExpressionBody( ArrowExpressionClause( ObjectCreationExpression(_names.ReaderStruct.IdentifierName) @@ -78,7 +78,7 @@ namespace CapnpC.CSharp.Generator.CodeGen SingletonSeparatedList( Parameter(_names.ContextParameter.Identifier) .WithType( - Type())))) + _names.Type(Nullability.NonNullable))))) .WithExpressionBody( ArrowExpressionClause( ObjectCreationExpression(_names.ReaderStruct.IdentifierName) @@ -90,7 +90,7 @@ namespace CapnpC.CSharp.Generator.CodeGen { yield return FieldDeclaration( VariableDeclaration( - Type()) + _names.Type(Nullability.NonNullable)) .AddVariables(_names.ReaderContextField.VariableDeclarator)) .AddModifiers(Readonly); @@ -100,7 +100,7 @@ namespace CapnpC.CSharp.Generator.CodeGen ParameterList( SingletonSeparatedList( Parameter(_names.ContextParameter.Identifier) - .WithType(Type())))) + .WithType(_names.Type(Nullability.NonNullable))))) .WithBody( Block( SingletonList( @@ -122,7 +122,7 @@ namespace CapnpC.CSharp.Generator.CodeGen { yield return FieldDeclaration( VariableDeclaration( - Type()) + _names.Type(Nullability.NonNullable)) .AddVariables(_names.ReaderContextField.VariableDeclarator)) .AddModifiers(Readonly); @@ -131,7 +131,7 @@ namespace CapnpC.CSharp.Generator.CodeGen .WithParameterList( ParameterList( SingletonSeparatedList(Parameter(_names.GroupReaderContextArg.Identifier) - .WithType(Type())))) + .WithType(_names.Type(Nullability.NonNullable))))) .WithBody( Block( SingletonList( @@ -173,57 +173,7 @@ namespace CapnpC.CSharp.Generator.CodeGen .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); } - static Func MakeCastFunc(TypeSyntax type) => - x => CastExpression(type, x); - - static Func MakeListCastFunc(string castName, Field field) - { - // Insight: List may have complex default values (e.g. [true, false, false, true] as a - // valid default value for a list of bools. This does not yet fit the author's mindset. - - //if (field.DefaultValueIsExplicit) - //{ - // return x => InvocationExpression( - // MemberAccessExpression( - // SyntaxKind.SimpleMemberAccessExpression, - // x, - // IdentifierName(castName)) - // ) - // .AddArgumentListArguments( - // Argument(ValueOf(field.DefaultValue))); - //} - //else - - { - return x => InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - x, - IdentifierName(castName)) - ); - } - } - - static Func MakeListCastFuncWithCons( - string castName, ExpressionSyntax cons) - { - return x => InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - x, - IdentifierName(castName)) - ).AddArgumentListArguments(Argument(cons)); - } - - static Func MakeGenericListCastFunc(string castName, TypeSyntax genericArgument) - { - return x => InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - x, - GenericName(castName).AddTypeArgumentListArguments(genericArgument)) - ); - } + static Func MakeCastFunc(TypeSyntax type) => x => CastExpression(type, x); PropertyDeclarationSyntax MakeReadProperty(TypeSyntax type, string name, SimpleNameSyntax readName, object indexOrBitOffset, ExpressionSyntax secondArg, @@ -261,13 +211,19 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeReadPrimitiveProperty(Field field, string readName) { - return MakeReadProperty(Type(), _names.GetCodeIdentifier(field).ToString(), readName, field.BitOffset.Value, - ValueOf(field.DefaultValue.ScalarValue), null, field.DiscValue.HasValue); + return MakeReadProperty( + _names.Type(Nullability.NonNullable), + _names.GetCodeIdentifier(field).ToString(), + readName, + field.BitOffset.Value, + ValueOf(field.DefaultValue.ScalarValue), + null, + field.DiscValue.HasValue); } PropertyDeclarationSyntax MakeReadEnumProperty(Field field) { - var typeSyntax = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var typeSyntax = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, Nullability.NonNullable); return MakeReadProperty(typeSyntax, _names.GetCodeIdentifier(field).ToString(), nameof(Capnp.SerializerExtensions.ReadDataUShort), field.BitOffset.Value, @@ -278,9 +234,16 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeReadTextProperty(Field field) { - return MakeReadProperty(Type(), _names.GetCodeIdentifier(field).ToString(), - nameof(Capnp.DeserializerState.ReadText), (int)field.Offset, - ValueOf(field.DefaultValue.ScalarValue), null, field.DiscValue.HasValue); + bool cantBeNull = !field.DiscValue.HasValue && field.DefaultValue.ScalarValue != null; + + return MakeReadProperty( + _names.Type(cantBeNull ? Nullability.NonNullable : Nullability.NullableRef), + _names.GetCodeIdentifier(field).ToString(), + nameof(Capnp.DeserializerState.ReadText), + (int)field.Offset, + ValueOf(field.DefaultValue.ScalarValue), + null, + field.DiscValue.HasValue); } MemberAccessExpressionSyntax MakeReaderCreator(TypeSyntax qtype) @@ -293,7 +256,7 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeReadStructProperty(Field field) { - var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, Nullability.NonNullable); var creator = MakeReaderCreator(qtype); return MakeReadProperty(qtype, _names.GetCodeIdentifier(field).ToString(), @@ -316,18 +279,16 @@ namespace CapnpC.CSharp.Generator.CodeGen return MakeReaderProperty(type, _names.GetCodeIdentifier(field).ToString(), right, field.DiscValue.HasValue); } - void MakeReadListPropertyImpl(Model.Type elementType, TypeDefinition scope, ExpressionSyntax context, int depth, - out TypeSyntax listType, out ExpressionSyntax impl) + ExpressionSyntax MakeReadListPropertyImpl(Model.Type elementType, TypeDefinition scope, ExpressionSyntax context, int depth) { - var elementTypeSyntax = _names.MakeTypeSyntax(elementType, scope, TypeUsage.Reader); - listType = GenericName("IReadOnlyList").AddTypeArgumentListArguments(elementTypeSyntax); + var elementTypeSyntax = _names.MakeTypeSyntax(elementType, scope, TypeUsage.Reader, Nullability.NonNullable); if (elementType.Tag == TypeTag.Interface || elementType.Tag == TypeTag.CapabilityPointer) { if (depth == 0) { - impl = InvocationExpression(MemberAccessExpression( + return InvocationExpression(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, _names.ReaderContextField.IdentifierName, GenericName(nameof(Capnp.DeserializerState.ReadCapList)) @@ -336,15 +297,13 @@ namespace CapnpC.CSharp.Generator.CodeGen } else { - impl = InvocationExpression( + return InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, context, GenericName(nameof(Capnp.DeserializerState.RequireCapList)) .AddTypeArgumentListArguments(elementTypeSyntax) )); } - - return; } if (depth == 0) @@ -374,56 +333,44 @@ namespace CapnpC.CSharp.Generator.CodeGen case TypeTag.List: { - MakeReadListPropertyImpl( + var innerImpl = MakeReadListPropertyImpl( elementType.ElementType, scope, lambdaArg, - depth + 1, - out var innerListType, - out var innerImpl); + depth + 1); - listType = GenericName("IReadOnlyList").AddTypeArgumentListArguments(innerListType); - - impl = InvocationExpression( + return InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(nameof(Capnp.ListDeserializer.Cast)))) .AddArgumentListArguments( Argument(SimpleLambdaExpression(lambdaParam, innerImpl))); - - return; } case TypeTag.ListPointer: { - listType = Type>(); - context = InvocationExpression(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(nameof(Capnp.DeserializerState.RequireList)) )).AddArgumentListArguments(Argument(lambdaArg)); - impl = InvocationExpression( + return InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(nameof(Capnp.ReadOnlyListExtensions.LazyListSelect)))) .AddArgumentListArguments( Argument(SimpleLambdaExpression(lambdaParam, context))); - - return; } case TypeTag.Struct: { - impl = InvocationExpression( + return InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(nameof(Capnp.ListDeserializer.Cast)))) .AddArgumentListArguments( Argument(MakeReaderCreator(elementTypeSyntax))); - - return; } case TypeTag.Enum: @@ -432,32 +379,26 @@ namespace CapnpC.CSharp.Generator.CodeGen lambdaParam, CastExpression(elementTypeSyntax, lambdaArg)); - impl = InvocationExpression( + return InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(nameof(Capnp.ListDeserializer.CastEnums)))) .AddArgumentListArguments( Argument(cons)); - - return; } case TypeTag.AnyPointer: case TypeTag.StructPointer: { - listType = Type>(); - impl = context; - return; + return context; } case TypeTag.Void: { - listType = Type(); - impl = MemberAccessExpression( + return MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(nameof(Capnp.ListDeserializer.Count))); - return; } case TypeTag.Data: @@ -517,7 +458,7 @@ namespace CapnpC.CSharp.Generator.CodeGen throw new NotImplementedException("Unexpected type tag, don't know how to deal with this"); } - impl = InvocationExpression(MemberAccessExpression( + return InvocationExpression(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, context, IdentifierName(castFuncName))); @@ -527,13 +468,18 @@ namespace CapnpC.CSharp.Generator.CodeGen { var elementType = field.Type.ElementType; var context = ValueOf((int)field.Offset); - MakeReadListPropertyImpl(elementType, field.DeclaringType, context, 0, out var listType, out var impl); + var impl = MakeReadListPropertyImpl(elementType, field.DeclaringType, context, 0); + var listType = _names.MakeTypeSyntax( + field.Type, + field.DeclaringType, + TypeUsage.Reader, + field.DiscValue.HasValue ? Nullability.NullableRef : Nullability.NonNullable); return MakeReaderProperty(listType, _names.GetCodeIdentifier(field).ToString(), impl, field.DiscValue.HasValue); } PropertyDeclarationSyntax MakeReadAnyListProperty(Field field) { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, Nullability.NonNullable); return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), nameof(Capnp.DeserializerState.ReadList), @@ -542,18 +488,19 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeReadCapProperty(Field field) { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var nullableType = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, Nullability.NullableRef); + var nonNullableType = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, Nullability.NonNullable); var readName = GenericName(nameof(Capnp.DeserializerState.ReadCap)) - .AddTypeArgumentListArguments(type); + .AddTypeArgumentListArguments(nonNullableType); - return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), + return MakeReadProperty(nullableType, _names.GetCodeIdentifier(field).ToString(), readName, (int)field.Offset, null, null, field.DiscValue.HasValue); } PropertyDeclarationSyntax MakeReadAnyCapProperty(Field field) { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader); + var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, Nullability.NonNullable); return MakeReadProperty(type, _names.GetCodeIdentifier(field).ToString(), nameof(Capnp.DeserializerState.ReadCap), @@ -573,7 +520,8 @@ namespace CapnpC.CSharp.Generator.CodeGen IdentifierName(nameof(Capnp.ListDeserializer.CastByte)))); return MakeReaderProperty( - _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader), + _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Reader, + field.DiscValue.HasValue ? Nullability.NullableRefAndValue : Nullability.NonNullable), _names.GetCodeIdentifier(field).ToString(), impl, field.DiscValue.HasValue); } diff --git a/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs b/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs index 56f258e..be46e5d 100644 --- a/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs +++ b/CapnpC.CSharp.Generator/CodeGen/SyntaxHelpers.cs @@ -9,8 +9,8 @@ namespace CapnpC.CSharp.Generator.CodeGen { static class SyntaxHelpers { - public static string MakeCamel(string name) => $"{char.ToUpperInvariant(name[0])}{name.Substring(1)}"; - public static string MakeAllLower(string name) => $"@{name}"; + public static string MakeUpperCamel(string name) => $"{char.ToUpperInvariant(name[0])}{name.Substring(1)}"; + public static string MakeLowerCamel(string name) => $"{char.ToLowerInvariant(name[0])}{name.Substring(1)}"; public static readonly SyntaxToken Async = Token(SyntaxKind.AsyncKeyword); public static readonly SyntaxToken Public = Token(SyntaxKind.PublicKeyword); @@ -21,7 +21,7 @@ namespace CapnpC.CSharp.Generator.CodeGen public static readonly SyntaxToken Partial = Token(SyntaxKind.PartialKeyword); public static readonly SyntaxToken This = Token(SyntaxKind.ThisKeyword); - public static TypeSyntax Type(Type type) + public static TypeSyntax NonNullableType(Type type) { switch (0) { @@ -66,14 +66,14 @@ namespace CapnpC.CSharp.Generator.CodeGen case 0 when type.IsGenericType: return GenericName(type.Name.Substring(0, type.Name.IndexOf('`'))) - .AddTypeArgumentListArguments(type.GetGenericArguments().Select(Type).ToArray()); + .AddTypeArgumentListArguments(type.GetGenericArguments().Select(NonNullableType).ToArray()); default: return ParseTypeName(type.Name); } } - public static TypeSyntax Type() => Type(typeof(T)); + public static TypeSyntax NonNullableType() => NonNullableType(typeof(T)); public static ExpressionSyntax ValueOf(object value) { @@ -83,16 +83,16 @@ namespace CapnpC.CSharp.Generator.CodeGen return LiteralExpression(x ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression); case sbyte x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + return CastExpression(NonNullableType(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); case byte x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + return CastExpression(NonNullableType(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); case short x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + return CastExpression(NonNullableType(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); case ushort x: - return CastExpression(Type(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); + return CastExpression(NonNullableType(), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x))); case int x: return LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(x)); @@ -122,5 +122,14 @@ namespace CapnpC.CSharp.Generator.CodeGen throw new NotImplementedException(); } } + + public static TypeSyntax MakeNonNullableType(TypeSyntax type) + { + if (type is NullableTypeSyntax nts) + { + type = nts.ElementType; + } + return type; + } } } diff --git a/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs index 262b8eb..7423adb 100644 --- a/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/WriterSnippetGen.cs @@ -115,12 +115,21 @@ namespace CapnpC.CSharp.Generator.CodeGen .AddArgumentListArguments( Argument(ValueOf(index))); - ExpressionSyntax MakeLinkSyntax(object index) => - InvocationExpression( + ExpressionSyntax MakeLinkSyntax(object index, bool suppressNullableWarning) + { + ExpressionSyntax value = IdentifierName("value"); + + if (suppressNullableWarning) + { + value = _names.SuppressNullableWarning(value); + } + + return InvocationExpression( IdentifierName(SerializerStateWorder.LinkName)) .AddArgumentListArguments( Argument(ValueOf(index)), - Argument(IdentifierName("value"))); + Argument(value)); + } ExpressionSyntax MakeLinkObjectSyntax(object index) => InvocationExpression( @@ -129,22 +138,46 @@ namespace CapnpC.CSharp.Generator.CodeGen Argument(ValueOf(index)), Argument(IdentifierName("value"))); + PropertyDeclarationSyntax MakeWriterRefTypeProperty( + TypeSyntax type, + string name, + ExpressionSyntax getter, + ExpressionSyntax setter, + bool cast, + bool cond) + { + if (cond) + { + type = _names.MakeNullableRefType(type); + } + + var prop = MakeWriterProperty(type, name, getter, setter, cast, cond); + + if (cond && _names.NullableEnable) + { + prop = prop.AddAttributeLists( + AttributeList( + SingletonSeparatedList( + Attribute( + IdentifierName("DisallowNull"))))); + } + return prop; + } + PropertyDeclarationSyntax MakePointerProperty(TypeSyntax type, string name, object index, bool cast, bool cond) { ExpressionSyntax getter = MakePointerSyntax(type, index); - ExpressionSyntax setter = MakeLinkSyntax(index); + ExpressionSyntax setter = MakeLinkSyntax(index, cond); - return MakeWriterProperty(type, name, getter, setter, cast, cond); + return MakeWriterRefTypeProperty(type, name, getter, setter, cast, cond); } - PropertyDeclarationSyntax MakePointerAsStructProperty( - TypeSyntax type, string name, object index, - bool cast, bool cond) + PropertyDeclarationSyntax MakePointerAsStructProperty(TypeSyntax type, string name, object index, bool cast, bool cond) { ExpressionSyntax getter = MakeTypedPointerSyntax(index, type); - ExpressionSyntax setter = MakeLinkSyntax(index); + ExpressionSyntax setter = MakeLinkSyntax(index, cond); - return MakeWriterProperty(type, name, getter, setter, cast, cond); + return MakeWriterRefTypeProperty(type, name, getter, setter, cast, cond); } PropertyDeclarationSyntax MakeProperty( @@ -195,7 +228,10 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakePrimitiveProperty(Field field, string readName) { - return MakeProperty(Type(), null, _names.GetCodeIdentifier(field).ToString(), + return MakeProperty( + _names.Type(Nullability.NonNullable), + null, + _names.GetCodeIdentifier(field).ToString(), readName, nameof(Capnp.SerializerExtensions.WriteData), field.BitOffset.Value, @@ -207,7 +243,9 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeEnumProperty(Field field, string readName) { - return MakeProperty(_names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant), Type(), + return MakeProperty( + _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.NotRelevant, Nullability.NonNullable), + _names.Type(Nullability.NonNullable), _names.GetCodeIdentifier(field).ToString(), readName, nameof(Capnp.SerializerExtensions.WriteData), @@ -220,7 +258,9 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeTextProperty(Field field) { - return MakeProperty(Type(), null, + return MakeProperty( + _names.Type(Nullability.NullableRef), + null, _names.GetCodeIdentifier(field).ToString(), nameof(Capnp.SerializerState.ReadText), nameof(Capnp.SerializerState.WriteText), @@ -233,7 +273,7 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeStructProperty(Field field) { - var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); + var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer, Nullability.NonNullable); return MakePointerAsStructProperty(qtype, _names.GetCodeIdentifier(field).ToString(), (int)field.Offset, false, field.DiscValue.HasValue); @@ -241,7 +281,7 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeGroupProperty(Field field) { - var type = QualifiedName( + TypeSyntax type = QualifiedName( _names.MakeTypeName(field.Type.Definition).IdentifierName, _names.WriterStruct.IdentifierName); @@ -249,12 +289,17 @@ namespace CapnpC.CSharp.Generator.CodeGen GenericName(nameof(Capnp.SerializerState.Rewrap)) .AddTypeArgumentListArguments(type)); + if (field.DiscValue.HasValue) + { + type = _names.MakeNullableRefType(type); + } + return MakeWriterProperty(type, _names.GetCodeIdentifier(field).ToString(), getter, null, false, field.DiscValue.HasValue); } PropertyDeclarationSyntax MakeListProperty(Field field) { - var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); + var qtype = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer, Nullability.NonNullable); return MakePointerProperty(qtype, _names.GetCodeIdentifier(field).ToString(), (int)field.Offset, false, field.DiscValue.HasValue); @@ -269,20 +314,21 @@ namespace CapnpC.CSharp.Generator.CodeGen PropertyDeclarationSyntax MakeCapProperty(Field field) { - var type = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer); + var nonNullableType = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer, Nullability.NonNullable); + var nullableType = _names.MakeTypeSyntax(field.Type, field.DeclaringType, TypeUsage.Writer, Nullability.NullableRef); int index = (int)field.Offset; string name = _names.GetCodeIdentifier(field).ToString(); - ExpressionSyntax getter = MakeReadCapSyntax(type, index); + ExpressionSyntax getter = MakeReadCapSyntax(nonNullableType, index); ExpressionSyntax setter = MakeLinkObjectSyntax(index); - return MakeWriterProperty(type, name, getter, setter, false, field.DiscValue.HasValue); + return MakeWriterProperty(nullableType, name, getter, setter, false, field.DiscValue.HasValue); } PropertyDeclarationSyntax MakeWriterUnionSelector(TypeDefinition def) { return MakeProperty( _names.UnionDiscriminatorEnum.IdentifierName, - Type(), + _names.Type(Nullability.NonNullable), _names.UnionDiscriminatorProp.ToString(), nameof(Capnp.SerializerExtensions.ReadDataUShort), nameof(Capnp.SerializerExtensions.WriteData), diff --git a/CapnpC.CSharp.Generator/Model/Enumerant.cs b/CapnpC.CSharp.Generator/Model/Enumerant.cs index 4ba17f6..51eac1b 100644 --- a/CapnpC.CSharp.Generator/Model/Enumerant.cs +++ b/CapnpC.CSharp.Generator/Model/Enumerant.cs @@ -8,6 +8,7 @@ get => _literal; set => _literal = IdentifierRenamer.ToNonKeyword(value); } + public string CsLiteral { get; set; } public ushort? Ordinal { get; set; } public int CodeOrder { get; set; } } diff --git a/CapnpC.CSharp.Generator/Model/Field.cs b/CapnpC.CSharp.Generator/Model/Field.cs index 017112c..114652b 100644 --- a/CapnpC.CSharp.Generator/Model/Field.cs +++ b/CapnpC.CSharp.Generator/Model/Field.cs @@ -5,6 +5,7 @@ public TypeDefinition DeclaringType { get; set; } public Field Parent { get; set; } public string Name { get; set; } + public string CsName { get; set; } public Type Type { get; set; } public Value DefaultValue { get; set; } public bool DefaultValueIsExplicit { get; set; } diff --git a/CapnpC.CSharp.Generator/Model/GenFile.cs b/CapnpC.CSharp.Generator/Model/GenFile.cs index 217a760..098c8a6 100644 --- a/CapnpC.CSharp.Generator/Model/GenFile.cs +++ b/CapnpC.CSharp.Generator/Model/GenFile.cs @@ -11,6 +11,8 @@ namespace CapnpC.CSharp.Generator.Model public string Name { get; set; } public string[] Namespace { get; set; } + public bool? NullableEnable { get; set; } + public bool EmitNullableDirective { get; set; } public IEnumerable NestedTypes { get => this.GetNestedTypes(); } public ICollection NestedDefinitions { get; } = new List(); diff --git a/CapnpC.CSharp.Generator/Model/Method.cs b/CapnpC.CSharp.Generator/Model/Method.cs index f7f2109..cfa65ff 100644 --- a/CapnpC.CSharp.Generator/Model/Method.cs +++ b/CapnpC.CSharp.Generator/Model/Method.cs @@ -8,6 +8,7 @@ namespace CapnpC.CSharp.Generator.Model public TypeDefinition DeclaringInterface { get; set; } public int Id { get; set; } public string Name { get; set; } + public string CsName { get; set; } public List Params { get; } = new List(); public List Results { get; } = new List(); public Type ParamsStruct { get; set; } @@ -21,6 +22,7 @@ namespace CapnpC.CSharp.Generator.Model DeclaringInterface = DeclaringInterface, Id = Id, Name = Name, + CsName = CsName, ParamsStruct = ParamsStruct, ResultStruct = ResultStruct }; diff --git a/CapnpC.CSharp.Generator/Model/SchemaModel.cs b/CapnpC.CSharp.Generator/Model/SchemaModel.cs index f0b9c88..8c0e9d6 100644 --- a/CapnpC.CSharp.Generator/Model/SchemaModel.cs +++ b/CapnpC.CSharp.Generator/Model/SchemaModel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text; +using static CapnpC.CSharp.Generator.Model.SupportedAnnotations; namespace CapnpC.CSharp.Generator.Model { @@ -92,6 +92,8 @@ namespace CapnpC.CSharp.Generator.Model state.parent = null; file.Namespace = GetNamespaceAnnotation(node); file.Name = name; + file.NullableEnable = GetNullableEnable(node); + file.EmitNullableDirective = GetEmitNullableDirective(node) ?? false; return ProcessNodePass1(id, name, state) as GenFile; } @@ -145,6 +147,7 @@ namespace CapnpC.CSharp.Generator.Model Trace.Assert(state.parent != null, $"The {node.GetTypeTag().ToString()} node {node.StrId()} was expected to have a parent."); var typeDef = _typeDefMgr.CreateTypeDef(id, node.GetTypeTag(), state.parent); typeDef.Name = name; + typeDef.CsName = GetCsName(node); state.parent = typeDef; def = typeDef; } @@ -175,18 +178,6 @@ namespace CapnpC.CSharp.Generator.Model return def; } - string[] GetNamespaceAnnotation(Schema.Node.Reader fileNode) - { - foreach (var annotation in fileNode.Annotations) - { - if (annotation.Id == 0xb9c6f99ebf805f2c) // Cxx namespace - { - return annotation.Value.Text.Split(new string[1] { "::" }, default); - } - } - return null; - } - // 2nd pass: Generate types based on definitions struct Pass2State @@ -492,6 +483,7 @@ namespace CapnpC.CSharp.Generator.Model { DeclaringType = declaringType, Name = fieldReader.Name, + CsName = GetCsName(fieldReader), CodeOrder = fieldReader.CodeOrder }; @@ -505,6 +497,8 @@ namespace CapnpC.CSharp.Generator.Model case 0 when fieldReader.IsGroup: var def = ProcessTypeDef(fieldReader.Group_TypeId, state, TypeTag.Group); field.Type = Types.FromDefinition(def); + def.CsName = field.CsName; // Type definitions for unions are artificially generated. + // Transfer the C# name of the using field. break; case 0 when fieldReader.IsSlot: @@ -549,7 +543,8 @@ namespace CapnpC.CSharp.Generator.Model { DeclaringInterface = def, Id = def.Methods.Count, - Name = methodReader.Name + Name = methodReader.Name, + CsName = GetCsName(methodReader) }; foreach (var implicitParameterReader in methodReader.ImplicitParameters) { @@ -664,6 +659,7 @@ namespace CapnpC.CSharp.Generator.Model { TypeDefinition = def, Literal = fieldReader.Name, + CsLiteral = GetCsName(fieldReader), CodeOrder = fieldReader.CodeOrder }; @@ -745,9 +741,6 @@ namespace CapnpC.CSharp.Generator.Model public static class SchemaExtensions { - public static string GetName(this Schema.Node.Reader node) - => node.DisplayName.Substring((int)node.DisplayNamePrefixLength); - public static string StrId(this Schema.Node.Reader node) => $"0x{node.Id:X}"; diff --git a/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs b/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs new file mode 100644 index 0000000..5951f16 --- /dev/null +++ b/CapnpC.CSharp.Generator/Model/SupportedAnnotations.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CapnpC.CSharp.Generator.Model +{ + static class SupportedAnnotations + { + static class AnnotationIds + { + public static class Cxx + { + public const ulong Namespace = 0xb9c6f99ebf805f2c; + } + + public static class Cs + { + public const ulong Namespace = 0xeb0d831668c6eda0; + public const ulong NullableEnable = 0xeb0d831668c6eda1; + public const ulong Name = 0xeb0d831668c6eda2; + public const ulong EmitNullableDirective = 0xeb0d831668c6eda3; + } + } + + public static string[] GetNamespaceAnnotation(Schema.Node.Reader fileNode) + { + foreach (var annotation in fileNode.Annotations) + { + if (annotation.Id == AnnotationIds.Cs.Namespace) + { + return annotation.Value.Text.Split(new string[1] { "." }, default); + } + + if (annotation.Id == AnnotationIds.Cxx.Namespace) + { + return annotation.Value.Text.Split(new string[1] { "::" }, default); + } + } + return null; + } + + public static string GetCsName(Schema.Field.Reader node) + { + foreach (var annotation in node.Annotations) + { + if (annotation.Id == AnnotationIds.Cs.Name) + { + return annotation.Value.Text; + } + } + return null; + } + + public static string GetCsName(Schema.Node.Reader node) + { + foreach (var annotation in node.Annotations) + { + if (annotation.Id == AnnotationIds.Cs.Name) + { + return annotation.Value.Text; + } + } + return null; + } + + public static string GetCsName(Schema.Method.Reader node) + { + foreach (var annotation in node.Annotations) + { + if (annotation.Id == AnnotationIds.Cs.Name) + { + return annotation.Value.Text; + } + } + return null; + } + + public static bool? GetNullableEnable(Schema.Node.Reader node) + { + foreach (var annotation in node.Annotations) + { + if (annotation.Id == AnnotationIds.Cs.NullableEnable && annotation.Value.IsBool) + { + return annotation.Value.Bool; + } + } + return null; + } + + public static bool? GetEmitNullableDirective(Schema.Node.Reader node) + { + foreach (var annotation in node.Annotations) + { + if (annotation.Id == AnnotationIds.Cs.EmitNullableDirective && annotation.Value.IsBool) + { + return annotation.Value.Bool; + } + } + return null; + } + } +} diff --git a/CapnpC.CSharp.Generator/Model/TypeDefinition.cs b/CapnpC.CSharp.Generator/Model/TypeDefinition.cs index 61e8e64..dd901f7 100644 --- a/CapnpC.CSharp.Generator/Model/TypeDefinition.cs +++ b/CapnpC.CSharp.Generator/Model/TypeDefinition.cs @@ -37,6 +37,7 @@ namespace CapnpC.CSharp.Generator.Model public Method UsingMethod { get; set; } public string Name { get; set; } + public string CsName { get; set; } public SpecialName SpecialName { get; set; } public DiscriminationInfo UnionInfo { get; set; } public List Fields { get; } = new List(); diff --git a/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj b/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj index 8fc6607..4069eee 100644 --- a/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj +++ b/CapnpC.CSharp.MsBuild.Generation.Tests/CapnpC.CSharp.MsBuild.Generation.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.0 false diff --git a/MsBuildGenerationTest/MsBuildGenerationTest.csproj b/MsBuildGenerationTest/MsBuildGenerationTest.csproj index 3c7c246..773569e 100644 --- a/MsBuildGenerationTest/MsBuildGenerationTest.csproj +++ b/MsBuildGenerationTest/MsBuildGenerationTest.csproj @@ -2,8 +2,9 @@ Exe - netcoreapp2.2 - 1.2-local + netcoreapp3.0 + 8.0 + Enable Debug;Release $(Version)* diff --git a/MsBuildGenerationTest/Program.cs b/MsBuildGenerationTest/Program.cs index bbbb50b..d5cfced 100644 --- a/MsBuildGenerationTest/Program.cs +++ b/MsBuildGenerationTest/Program.cs @@ -9,13 +9,24 @@ namespace MsBuildGenerationTest // Instantiate some generated classes ensures that they are really present. // Note that this code is not supposed to test runtime behavior, we have plenty of other test cases for that purpose. + void use(object y) + { + } + var vatId = new Capnp.Rpc.Twoparty.VatId(); + use(vatId); var msg = new Capnp.Rpc.Message(); + use(msg); var node = new Capnp.Schema.Node(); + use(node); var x = Capnproto_test.Capnp.Test.TestEnum.garply; + use(x); var imp = new CapnpGen.TestImport(); + use(imp); var imp2 = new CapnpGen.TestImport2(); + use(imp2); var book = new CapnpGen.AddressBook(); + use(book); } } } diff --git a/MsBuildGenerationTest/capnp/rpc.capnp b/MsBuildGenerationTest/capnp/rpc.capnp index 86e86ea..2e24b62 100644 --- a/MsBuildGenerationTest/capnp/rpc.capnp +++ b/MsBuildGenerationTest/capnp/rpc.capnp @@ -110,7 +110,7 @@ # it for free. using Cxx = import "/capnp/c++.capnp"; -$Cxx.namespace("capnp::rpc"); +$Cxx.namespace("test::rpc"); # ======================================================================================== # The Four Tables diff --git a/appveyor.yml b/appveyor.yml index a42263e..b8c4883 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -55,14 +55,14 @@ test_script: - cmd: | nbgv get-version -v NuGetPackageVersion >> version.txt set /P VERSION=< version.txt - vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp2.1\CapnpC.CSharp.Generator.Tests.dll + vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp3.0\CapnpC.CSharp.Generator.Tests.dll choco install capnproto --source="https://chocolatey.org/api/v2" --force -y cd %APPVEYOR_BUILD_FOLDER%\capnpc-csharp dotnet tool install --global --add-source ./nupkg capnpc-csharp --version %VERSION% cd %APPVEYOR_BUILD_FOLDER%\install-test compile-test cd %APPVEYOR_BUILD_FOLDER% - vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp2.1\CapnpC.CSharp.Generator.Tests.dll + vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.Generator.Tests\bin\Release\netcoreapp3.0\CapnpC.CSharp.Generator.Tests.dll dotnet tool uninstall --global capnpc-csharp cd %APPVEYOR_BUILD_FOLDER%\install-test notinstalled-test @@ -73,7 +73,7 @@ test_script: choco uninstall capnpc-csharp-win-x86 -y notinstalled-test cd %APPVEYOR_BUILD_FOLDER% - vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp2.1\CapnpC.CSharp.MsBuild.Generation.Tests.dll + vstest.console /logger:Appveyor /inIsolation CapnpC.CSharp.MsBuild.Generation.Tests\bin\Release\netcoreapp3.0\CapnpC.CSharp.MsBuild.Generation.Tests.dll msbuild -t:restore ./MsBuildGenerationTest/MsBuildGenerationTest.csproj /p:Configuration="Debug" /p:PackageReferenceVersion="%VERSION%" msbuild ./MsBuildGenerationTest/MsBuildGenerationTest.sln /p:Configuration="Debug" /p:PackageReferenceVersion="%VERSION%" vstest.console /logger:Appveyor /inIsolation Capnp.Net.Runtime.Tests\bin\Debug\net471\Capnp.Net.Runtime.Tests.Std20.dll diff --git a/include/csharp.capnp b/include/csharp.capnp new file mode 100644 index 0000000..19aabd2 --- /dev/null +++ b/include/csharp.capnp @@ -0,0 +1,14 @@ +@0xeb0d831668c6edab; +$namespace("Capnp.Annotations"); + +annotation namespace @0xeb0d831668c6eda0 (file) : Text; +# C# namespace for code generation + +annotation nullableEnable @0xeb0d831668c6eda1 (file) : Bool; +# Whether to generate C# nullable reference types + +annotation emitNullableDirective @0xeb0d831668c6eda3 (file) : Bool; +# Whether to surround the generated with with #nullable enable/disable ... #nullable restore + +annotation name @0xeb0d831668c6eda2 (field, enumerant, struct, enum, interface, method, param, group, union) : Text; +# C# member name for code generation