From b427ef7262ae6c98358c247a19464cd2011b8688 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Sun, 19 Nov 2023 08:25:17 -0800 Subject: [PATCH] Update latest-codegen to be net8.0 --- README.md | 6 +- .../CSharp/CSharpOutputBuilder.Visit.cs | 4 +- .../PInvokeGenerator.VisitDecl.cs | 2 +- .../PInvokeGenerator.VisitStmt.cs | 8 +- sources/ClangSharpPInvokeGenerator/Program.cs | 4 +- .../CSharpLatestUnix/StructDeclarationTest.cs | 125 ++----------- .../CSharpLatestUnix/UnionDeclarationTest.cs | 104 +---------- .../StructDeclarationTest.cs | 125 ++----------- .../UnionDeclarationTest.cs | 104 +---------- .../XmlLatestUnix/StructDeclarationTest.cs | 166 +----------------- .../XmlLatestUnix/UnionDeclarationTest.cs | 143 +-------------- .../XmlLatestWindows/StructDeclarationTest.cs | 166 +----------------- .../XmlLatestWindows/UnionDeclarationTest.cs | 143 +-------------- 13 files changed, 67 insertions(+), 1033 deletions(-) diff --git a/README.md b/README.md index 6e3fe5c0..224e3632 100644 --- a/README.md +++ b/README.md @@ -201,9 +201,9 @@ Options: # Codegen Options compatible-codegen Bindings should be generated with .NET Standard 2.0 compatibility. Setting this disables preview code generation. - default-codegen Bindings should be generated for the current LTS version of .NET/C#. This is currently .NET 6/C# 10. - latest-codegen Bindings should be generated for the current STS version of .NET/C#. This is currently .NET 7/C# 11. - preview-codegen Bindings should be generated for the preview version of .NET/C#. This is currently .NET 8/C# 12. + default-codegen Bindings should be generated for the previous LTS version of .NET/C#. This is currently .NET 6/C# 10. + latest-codegen Bindings should be generated for the current LTS/STS version of .NET/C#. This is currently .NET 8/C# 12. + preview-codegen Bindings should be generated for the preview version of .NET/C#. This is currently .NET 9/C# 13. # File Options diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs index 24263826..c798c5a0 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs @@ -89,7 +89,7 @@ internal partial class CSharpOutputBuilder WriteIndented("ReadOnlySpan data = "); - if (_config.GeneratePreviewCode) + if (_config.GenerateLatestCode) { WriteLine('['); } @@ -124,7 +124,7 @@ internal partial class CSharpOutputBuilder WriteNewline(); DecreaseIndentation(); - if (_config.GeneratePreviewCode) + if (_config.GenerateLatestCode) { WriteIndented(']'); } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index e76f2732..125de914 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -2903,7 +2903,7 @@ public partial class PInvokeGenerator AddDiagnostic(DiagnosticLevel.Info, $"{escapedName} (constant array field) has a size of 0", constantOrIncompleteArray); } - if (!_config.GeneratePreviewCode || (totalSize <= 1) || isUnsafeElementType) + if (!_config.GenerateLatestCode || (totalSize <= 1) || isUnsafeElementType) { totalSizeString = null; } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index 9bd793f1..7c8ee972 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -1503,7 +1503,7 @@ public partial class PInvokeGenerator outputBuilder.WriteIndented("ReadOnlySpan data = "); - if (_config.GeneratePreviewCode) + if (_config.GenerateLatestCode) { outputBuilder.WriteLine("["); } @@ -1519,7 +1519,7 @@ public partial class PInvokeGenerator outputBuilder.WriteNewline(); outputBuilder.DecreaseIndentation(); - if (_config.GeneratePreviewCode) + if (_config.GenerateLatestCode) { outputBuilder.WriteIndented(']'); } @@ -2553,7 +2553,7 @@ public partial class PInvokeGenerator case CX_CLK_UTF32: { - if (_config.GeneratePreviewCode) + if (_config.GenerateLatestCode) { outputBuilder.Write('['); } @@ -2574,7 +2574,7 @@ public partial class PInvokeGenerator outputBuilder.Write("0x00000000"); - if (_config.GeneratePreviewCode) + if (_config.GenerateLatestCode) { outputBuilder.Write(']'); } diff --git a/sources/ClangSharpPInvokeGenerator/Program.cs b/sources/ClangSharpPInvokeGenerator/Program.cs index 1a625dc8..6b355de1 100644 --- a/sources/ClangSharpPInvokeGenerator/Program.cs +++ b/sources/ClangSharpPInvokeGenerator/Program.cs @@ -174,7 +174,9 @@ public static class Program new TwoColumnHelpRow("generate-unmanaged-constants", "Unmanaged constants should be generated using static ref readonly properties. This is currently experimental."), new TwoColumnHelpRow("generate-vtbl-index-attribute", "[VtblIndex(#)] attribute should be generated to document the underlying VTBL index for a helper method."), - // Logging Options + new TwoColumnHelpRow("", ""), + new TwoColumnHelpRow("# Logging Options", ""), + new TwoColumnHelpRow("", ""), new TwoColumnHelpRow("log-exclusions", "A list of excluded declaration types should be generated. This will also log if the exclusion was due to an exact or partial match."), new TwoColumnHelpRow("log-potential-typedef-remappings", "A list of potential typedef remappings should be generated. This can help identify missing remappings."), diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs index ab899ce0..179b83fb 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/StructDeclarationTest.cs @@ -591,9 +591,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -607,23 +605,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -645,9 +630,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -661,55 +644,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyStruct[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0_0_0_0; - public MyStruct e1_0_0_0; - - public MyStruct e0_0_1_0; - public MyStruct e1_0_1_0; - - public MyStruct e0_0_2_0; - public MyStruct e1_0_2_0; - - public MyStruct e0_0_0_1; - public MyStruct e1_0_0_1; - - public MyStruct e0_0_1_1; - public MyStruct e1_0_1_1; - - public MyStruct e0_0_2_1; - public MyStruct e1_0_2_1; - - public MyStruct e0_0_0_2; - public MyStruct e1_0_0_2; - - public MyStruct e0_0_1_2; - public MyStruct e1_0_1_2; - - public MyStruct e0_0_2_2; - public MyStruct e1_0_2_2; - - public MyStruct e0_0_0_3; - public MyStruct e1_0_0_3; - - public MyStruct e0_0_1_3; - public MyStruct e1_0_1_3; - - public MyStruct e0_0_2_3; - public MyStruct e1_0_2_3; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} @@ -733,9 +671,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -749,23 +685,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -787,9 +710,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -804,23 +725,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -1136,6 +1044,7 @@ struct MyStruct var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1274,24 +1183,10 @@ namespace ClangSharp.Test public {expectedManagedType} value2; }} + [InlineArray(4)] public partial struct _buffer2_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - public MyUnion e3; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs index 2a5fbf26..8976884a 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/UnionDeclarationTest.cs @@ -350,8 +350,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -370,23 +369,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -408,8 +394,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -428,55 +413,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyUnion[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0_0_0_0; - public MyUnion e1_0_0_0; - - public MyUnion e0_0_1_0; - public MyUnion e1_0_1_0; - - public MyUnion e0_0_2_0; - public MyUnion e1_0_2_0; - - public MyUnion e0_0_0_1; - public MyUnion e1_0_0_1; - - public MyUnion e0_0_1_1; - public MyUnion e1_0_1_1; - - public MyUnion e0_0_2_1; - public MyUnion e1_0_2_1; - - public MyUnion e0_0_0_2; - public MyUnion e1_0_0_2; - - public MyUnion e0_0_1_2; - public MyUnion e1_0_1_2; - - public MyUnion e0_0_2_2; - public MyUnion e1_0_2_2; - - public MyUnion e0_0_0_3; - public MyUnion e1_0_0_3; - - public MyUnion e0_0_1_3; - public MyUnion e1_0_1_3; - - public MyUnion e0_0_2_3; - public MyUnion e1_0_2_3; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} @@ -500,8 +440,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -520,23 +459,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -558,8 +484,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -579,23 +504,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs index 17a62b5f..381c0f4d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/StructDeclarationTest.cs @@ -599,9 +599,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -615,23 +613,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -653,9 +638,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -669,55 +652,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyStruct[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0_0_0_0; - public MyStruct e1_0_0_0; - - public MyStruct e0_0_1_0; - public MyStruct e1_0_1_0; - - public MyStruct e0_0_2_0; - public MyStruct e1_0_2_0; - - public MyStruct e0_0_0_1; - public MyStruct e1_0_0_1; - - public MyStruct e0_0_1_1; - public MyStruct e1_0_1_1; - - public MyStruct e0_0_2_1; - public MyStruct e1_0_2_1; - - public MyStruct e0_0_0_2; - public MyStruct e1_0_0_2; - - public MyStruct e0_0_1_2; - public MyStruct e1_0_1_2; - - public MyStruct e0_0_2_2; - public MyStruct e1_0_2_2; - - public MyStruct e0_0_0_3; - public MyStruct e1_0_0_3; - - public MyStruct e0_0_1_3; - public MyStruct e1_0_1_3; - - public MyStruct e0_0_2_3; - public MyStruct e1_0_2_3; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} @@ -741,9 +679,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -757,23 +693,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -795,9 +718,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -812,23 +733,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyStruct[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - [UnscopedRef] - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -1144,6 +1052,7 @@ struct MyStruct var expectedOutputContents = $@"using System; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1282,24 +1191,10 @@ namespace ClangSharp.Test public {expectedManagedType} value2; }} + [InlineArray(4)] public partial struct _buffer2_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - public MyUnion e3; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs index 14338655..736cbed5 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/UnionDeclarationTest.cs @@ -356,8 +356,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -376,23 +375,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -414,8 +400,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -434,55 +419,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyUnion[2][1][3][4]"")] public _c_e__FixedBuffer c; + [InlineArray(2 * 1 * 3 * 4)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0_0_0_0; - public MyUnion e1_0_0_0; - - public MyUnion e0_0_1_0; - public MyUnion e1_0_1_0; - - public MyUnion e0_0_2_0; - public MyUnion e1_0_2_0; - - public MyUnion e0_0_0_1; - public MyUnion e1_0_0_1; - - public MyUnion e0_0_1_1; - public MyUnion e1_0_1_1; - - public MyUnion e0_0_2_1; - public MyUnion e1_0_2_1; - - public MyUnion e0_0_0_2; - public MyUnion e1_0_0_2; - - public MyUnion e0_0_1_2; - public MyUnion e1_0_1_2; - - public MyUnion e0_0_2_2; - public MyUnion e1_0_2_2; - - public MyUnion e0_0_0_3; - public MyUnion e1_0_0_3; - - public MyUnion e0_0_1_3; - public MyUnion e1_0_1_3; - - public MyUnion e0_0_2_3; - public MyUnion e1_0_2_3; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} @@ -506,8 +446,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -526,23 +465,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} @@ -564,8 +490,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; -using System.Diagnostics.CodeAnalysis; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -585,23 +510,10 @@ namespace ClangSharp.Test [NativeTypeName(""MyUnion[3]"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - [UnscopedRef] - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - [UnscopedRef] - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs index 6fbe2884..5e523142 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/StructDeclarationTest.cs @@ -541,28 +541,10 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -598,91 +580,10 @@ struct MyOtherStruct MyStruct + InlineArray(2 * 1 * 3 * 4) MyStruct - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - @@ -720,28 +621,10 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -777,28 +660,10 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -1189,31 +1054,10 @@ struct MyStruct + InlineArray(4) MyUnion - - MyUnion - - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 4); - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs index ce508bf7..2a04f051 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/UnionDeclarationTest.cs @@ -308,28 +308,10 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -365,91 +347,10 @@ union MyOtherUnion MyUnion + InlineArray(2 * 1 * 3 * 4) MyUnion - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - @@ -487,28 +388,10 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -544,28 +427,10 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs index 7ceab0a9..dfcf8a15 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/StructDeclarationTest.cs @@ -553,28 +553,10 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -610,91 +592,10 @@ struct MyOtherStruct MyStruct + InlineArray(2 * 1 * 3 * 4) MyStruct - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - @@ -732,28 +633,10 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -789,28 +672,10 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -1201,31 +1066,10 @@ struct MyStruct + InlineArray(4) MyUnion - - MyUnion - - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 4); - diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs index 74376381..e1116cb6 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/UnionDeclarationTest.cs @@ -314,28 +314,10 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -371,91 +353,10 @@ union MyOtherUnion MyUnion + InlineArray(2 * 1 * 3 * 4) MyUnion - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); - @@ -493,28 +394,10 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - @@ -550,28 +433,10 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); -