diff --git a/README.md b/README.md index 5d402113..df4ca5f2 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ See [LICENSE.md](LICENSE.md) in the repository root for more information. ### Building Managed -ClangSharp requires the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) and can be built simply with `dotnet build -c Release`. +ClangSharp requires the [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) and can be built simply with `dotnet build -c Release`. You can reproduce what the CI environment does by running `./scripts/cibuild.cmd` on Windows or `./scripts.cibuild.sh` on Unix. This will download the required .NET SDK locally and use that to build the repo; it will also run through all available actions in the appropriate order. @@ -133,7 +133,7 @@ This program will take a given set of C or C++ header files and generate C# bind The simplest and recommended setup is to install the generator as a .NET tool and then use response files: ``` -dotnet tool install --global ClangSharpPInvokeGenerator --version 20.1.2 +dotnet tool install --global ClangSharpPInvokeGenerator ClangSharpPInvokeGenerator @generate.rsp ``` @@ -202,9 +202,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 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. + default-codegen Bindings should be generated for the previous LTS version of .NET/C#. This is currently .NET 8/C# 12. + latest-codegen Bindings should be generated for the current LTS/STS version of .NET/C#. This is currently .NET 10/C# 14. + preview-codegen Bindings should be generated for the preview version of .NET/C#. This is currently .NET 10/C# 14. # File Options diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs index 0a33d680..8a369cb9 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs @@ -66,6 +66,21 @@ readonly get } } + public bool IsReadOnly + { + readonly get + { + return (Flags & FunctionOrDelegateFlags.IsReadOnly) != 0; + } + + set + { + Flags = value + ? Flags | FunctionOrDelegateFlags.IsReadOnly + : Flags & ~FunctionOrDelegateFlags.IsReadOnly; + } + } + public bool HasFnPtrCodeGen { readonly get diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs index 522d5c79..7ffda523 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs @@ -89,7 +89,7 @@ public void WriteIid(string name, Guid value) WriteIndented("ReadOnlySpan data = "); - if (_generator.Config.GenerateLatestCode) + if (!_generator.Config.GenerateCompatibleCode) { WriteLine('['); } @@ -124,7 +124,7 @@ public void WriteIid(string name, Guid value) WriteNewline(); DecreaseIndentation(); - if (_generator.Config.GenerateLatestCode) + if (!_generator.Config.GenerateCompatibleCode) { WriteIndented(']'); } diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index 8380a582..5060f29d 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -517,6 +517,11 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM Write("new "); } + if (desc.IsReadOnly) + { + Write("readonly "); + } + if (desc.IsUnsafe) { if (!desc.IsCtxCxxRecord) @@ -808,7 +813,7 @@ public void BeginStruct(in StructDesc desc) Write(".Interface"); } - if ((desc.Uuid is not null) && _generator.Config.GenerateGuidMember && _generator.Config.GenerateLatestCode) + if ((desc.Uuid is not null) && _generator.Config.GenerateGuidMember && !_generator.Config.GenerateCompatibleCode) { Write(desc.HasVtbl ? ", " : " : "); Write("INativeGuid"); diff --git a/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs b/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs index aeb0eab6..3f4d5396 100644 --- a/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs +++ b/sources/ClangSharp.PInvokeGenerator/FunctionOrDelegateFlags.cs @@ -21,4 +21,5 @@ internal enum FunctionOrDelegateFlags NeedsReturnFixup = 1 << 13, IsCxxConstructor = 1 << 14, IsManualImport = 1 << 15, + IsReadOnly = 1 << 16, } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 084cd4c0..271e6583 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -607,6 +607,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) IsCxx = cxxMethodDecl is not null, IsStatic = isDllImport || (cxxMethodDecl is null) || cxxMethodDecl.IsStatic, NeedsNewKeyword = NeedsNewKeyword(escapedName, functionDecl.Parameters), + IsReadOnly = (cxxMethodDecl is not null) && cxxMethodDecl.IsConst, IsUnsafe = IsUnsafe(functionDecl), IsCtxCxxRecord = cxxRecordDecl is not null, IsCxxRecordCtxUnsafe = cxxRecordDecl is not null && IsUnsafe(cxxRecordDecl), @@ -944,7 +945,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) ParentName = GetRemappedCursorName(parent), Offset = null, NeedsNewKeyword = false, - NeedsUnscopedRef = _config.GenerateLatestCode && !fieldDecl.IsBitField, + NeedsUnscopedRef = !_config.GenerateCompatibleCode && !fieldDecl.IsBitField, Location = fieldDecl.Location, HasBody = true, WriteCustomAttrs = static context => { @@ -1110,7 +1111,7 @@ private void VisitIndirectFieldDecl(IndirectFieldDecl indirectFieldDecl) code.Write(arraySize); code.Write(')'); } - else if (!_config.GenerateLatestCode || arraySize == 1) + else if (_config.GenerateCompatibleCode || arraySize == 1) { code.Write(".AsSpan("); @@ -1657,9 +1658,23 @@ private void VisitRecordDecl(RecordDecl recordDecl) _outputBuilder.BeginValue(in valueDesc); var code = _outputBuilder.BeginCSharpCode(); - code.Write("(Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in "); + + code.Write("(Guid*)Unsafe.AsPointer("); + + if (!_config.GenerateLatestCode) + { + code.Write("ref Unsafe.AsRef("); + } + + code.Write("in "); code.Write(usableUuidName); - code.Write("))"); + code.Write(')'); + + if (!_config.GenerateLatestCode) + { + code.Write(')'); + } + _outputBuilder.EndCSharpCode(code); _outputBuilder.EndValue(in valueDesc); @@ -2213,6 +2228,7 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod HasFnPtrCodeGen = !_config.ExcludeFnptrCodegen, IsCtxCxxRecord = true, IsCxxRecordCtxUnsafe = IsUnsafe(cxxRecordDecl), + IsReadOnly = cxxMethodDecl.IsConst, IsUnsafe = true, NeedsReturnFixup = needsReturnFixup, ReturnType = returnTypeName, @@ -2335,7 +2351,27 @@ void OutputVtblHelperMethod(CXXRecordDecl cxxRecordDecl, CXXMethodDecl cxxMethod { body.Write('('); body.Write(escapedCXXRecordDeclName); - body.Write("*)Unsafe.AsPointer(ref this)"); + body.Write("*)Unsafe.AsPointer("); + + if (cxxMethodDecl.IsConst) + { + if (!_config.GenerateLatestCode) + { + body.Write("ref Unsafe.AsRef("); + } + + body.Write("in this"); + + if (!_config.GenerateLatestCode) + { + body.Write(')'); + } + } + else + { + body.Write("ref this"); + } + body.Write(')'); } body.EndMarker("param"); @@ -2974,7 +3010,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co AddDiagnostic(DiagnosticLevel.Info, $"{escapedName} (constant array field) has a size of 0", constantOrIncompleteArray); } - if (!_config.GenerateLatestCode || (totalSize <= 1) || isUnsafeElementType) + if (_config.GenerateCompatibleCode || (totalSize <= 1) || isUnsafeElementType) { totalSizeString = null; } @@ -3100,7 +3136,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co } else if (totalSizeString is null) { - _outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: _config.GenerateLatestCode); + _outputBuilder.BeginIndexer(AccessSpecifier.Public, isUnsafe: false, needsUnscopedRef: !_config.GenerateCompatibleCode); _outputBuilder.WriteIndexer($"ref {arrayTypeName}"); _outputBuilder.BeginIndexerParameters(); var param = new ParameterDesc { @@ -3146,7 +3182,7 @@ void VisitConstantOrIncompleteArrayFieldDecl(RecordDecl recordDecl, FieldDecl co ReturnType = $"Span<{arrayTypeName}>", Location = constantOrIncompleteArray.Location, HasBody = true, - NeedsUnscopedRef = _config.GenerateLatestCode, + NeedsUnscopedRef = !_config.GenerateCompatibleCode, }; var isUnsafe = false; @@ -3463,7 +3499,7 @@ private void VisitVarDecl(VarDecl varDecl) case CX_SLK_UTF32: { - typeName = (_config.GenerateLatestCode && flags.HasFlag(ValueFlags.Constant)) ? "ReadOnlySpan" : "uint[]"; + typeName = (!_config.GenerateCompatibleCode && flags.HasFlag(ValueFlags.Constant)) ? "ReadOnlySpan" : "uint[]"; break; } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index e5334899..25ed853c 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -247,7 +247,7 @@ private void VisitCallExpr(CallExpr callExpr) { var args = callExpr.Args; - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { outputBuilder.AddUsingDirective("System.Runtime.InteropServices"); outputBuilder.Write("NativeMemory.Copy"); @@ -306,13 +306,13 @@ private void VisitCallExpr(CallExpr callExpr) break; } - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { args = [args[0], args[2], args[1]]; } } - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { outputBuilder.AddUsingDirective("System.Runtime.InteropServices"); outputBuilder.Write("NativeMemory.Fill"); @@ -409,7 +409,27 @@ void VisitArgs(CallExpr callExpr, IReadOnlyList? args = null) outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); outputBuilder.Write('('); outputBuilder.Write(referenceTypeName); - outputBuilder.Write(")Unsafe.AsPointer(ref this)"); + outputBuilder.Write(")Unsafe.AsPointer("); + + if (referenceType.IsLocalConstQualified) + { + if (!_config.GenerateLatestCode) + { + outputBuilder.Write("ref Unsafe.AsRef("); + } + + outputBuilder.Write("in this"); + + if (!_config.GenerateLatestCode) + { + outputBuilder.Write(')'); + } + } + else + { + outputBuilder.Write("ref this"); + } + outputBuilder.Write(')'); needsComma = true; continue; @@ -432,7 +452,27 @@ void VisitArgs(CallExpr callExpr, IReadOnlyList? args = null) else if (IsStmtAsWritten(arg, out _) && (functionName == "memcpy")) { outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); - outputBuilder.Write("Unsafe.AsPointer(ref this)"); + outputBuilder.Write("Unsafe.AsPointer("); + + if (functionProtoType.ParamTypes[i].IsLocalConstQualified) + { + if (!_config.GenerateLatestCode) + { + outputBuilder.Write("ref Unsafe.AsRef("); + } + + outputBuilder.Write("in this"); + + if (!_config.GenerateLatestCode) + { + outputBuilder.Write(')'); + } + } + else + { + outputBuilder.Write("ref this"); + } + outputBuilder.Write(')'); needsComma = true; continue; @@ -1756,7 +1796,7 @@ void HandleUnmanagedConstant(CSharpOutputBuilder outputBuilder, InitListExpr ini outputBuilder.WriteIndented("ReadOnlySpan data = "); - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.WriteLine("["); } @@ -1772,7 +1812,7 @@ void HandleUnmanagedConstant(CSharpOutputBuilder outputBuilder, InitListExpr ini outputBuilder.WriteNewline(); outputBuilder.DecreaseIndentation(); - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.WriteIndented(']'); } @@ -2190,7 +2230,27 @@ private void VisitReturnStmt(ReturnStmt returnStmt) outputBuilder.AddUsingDirective("System.Runtime.CompilerServices"); outputBuilder.Write('('); outputBuilder.Write(referenceTypeName); - outputBuilder.Write(")Unsafe.AsPointer(ref this)"); + outputBuilder.Write(")Unsafe.AsPointer("); + + if (referenceType.IsLocalConstQualified) + { + if (!_config.GenerateLatestCode) + { + outputBuilder.Write("ref Unsafe.AsRef("); + } + + outputBuilder.Write("in this"); + + if (!_config.GenerateLatestCode) + { + outputBuilder.Write(')'); + } + } + else + { + outputBuilder.Write("ref this"); + } + outputBuilder.Write(')'); StopCSharpCode(); return; @@ -2793,7 +2853,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral) case CX_SLK_Ordinary: case CX_SLK_UTF8: { - if (Config.GenerateLatestCode) + if (!Config.GenerateCompatibleCode) { outputBuilder.Write('"'); outputBuilder.Write(EscapeString(stringLiteral.String)); @@ -2851,7 +2911,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral) case CX_SLK_UTF32: { - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.Write('['); } @@ -2872,7 +2932,7 @@ private void VisitStringLiteral(StringLiteral stringLiteral) outputBuilder.Write("0x00000000"); - if (_config.GenerateLatestCode) + if (!_config.GenerateCompatibleCode) { outputBuilder.Write(']'); } diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 1826f279..147788d7 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -3274,7 +3274,7 @@ private static int GetAnonymousRecordIndex(RecordDecl recordDecl, RecordDecl par index++; } } - else if ((parentIndex != 0) && (index > parentIndex)) + else if ((parentIndex > 0) && (index > parentIndex)) { if (recordDecl.IsUnion == parentRecordDecl.AnonymousRecords[parentIndex].IsUnion) { @@ -5588,7 +5588,7 @@ internal bool IsSupportedFixedSizedBufferType(string typeName) case "ulong": { // We want to prefer InlineArray in modern code, as it is safer and supports more features - return !Config.GenerateLatestCode; + return Config.GenerateCompatibleCode; } default: diff --git a/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs index 4b9ca7a2..6a4a6f4a 100644 --- a/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/XML/XmlOutputBuilder.VisitDecl.cs @@ -142,6 +142,11 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM _ = _sb.Append(" static=\"true\""); } + if (desc.IsReadOnly) + { + _ = _sb.Append(" readonly=\"true\""); + } + if (desc.IsUnsafe) { _ = _sb.Append(" unsafe=\"true\""); diff --git a/sources/ClangSharpPInvokeGenerator/Program.cs b/sources/ClangSharpPInvokeGenerator/Program.cs index 8e10ac88..04af033e 100644 --- a/sources/ClangSharpPInvokeGenerator/Program.cs +++ b/sources/ClangSharpPInvokeGenerator/Program.cs @@ -109,9 +109,9 @@ internal static class Program new TwoColumnHelpRow("", ""), new TwoColumnHelpRow("compatible-codegen", "Bindings should be generated with .NET Standard 2.0 compatibility. Setting this disables preview code generation."), - new TwoColumnHelpRow("default-codegen", "Bindings should be generated for the current LTS version of .NET/C#. This is currently .NET 6/C# 10."), - new TwoColumnHelpRow("latest-codegen", "Bindings should be generated for the current STS version of .NET/C#. This is currently .NET 7/C# 11."), - new TwoColumnHelpRow("preview-codegen", "Bindings should be generated for the preview version of .NET/C#. This is currently .NET 8/C# 12."), + new TwoColumnHelpRow("default-codegen", "Bindings should be generated for the current LTS version of .NET/C#. This is currently .NET 8/C# 12."), + new TwoColumnHelpRow("latest-codegen", "Bindings should be generated for the current STS version of .NET/C#. This is currently .NET 10/C# 14."), + new TwoColumnHelpRow("preview-codegen", "Bindings should be generated for the preview version of .NET/C#. This is currently .NET 10/C# 14."), new TwoColumnHelpRow("", ""), new TwoColumnHelpRow("# File Options", ""), diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs index a375ba77..0f287186 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/FunctionDeclarationBodyImportTest.cs @@ -1428,7 +1428,8 @@ void MyFunction() } "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1439,11 +1440,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs index a15705ab..45bfaec5 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/StructDeclarationTest.cs @@ -19,17 +19,39 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[]"")] - public fixed {expectedManagedType} x[1]; + public _x_e__FixedBuffer x; + + public partial struct _x_e__FixedBuffer + {{ + public {expectedManagedType} e0; + + [UnscopedRef] + public ref {expectedManagedType} this[int index] + {{ + get + {{ + return ref Unsafe.Add(ref e0, index); + }} + }} + + [UnscopedRef] + public Span<{expectedManagedType}> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length); + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -55,7 +77,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -80,7 +102,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -109,7 +131,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -318,7 +340,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -538,7 +560,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -568,14 +590,14 @@ public static partial class Methods } } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -591,8 +613,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -606,27 +627,16 @@ public partial struct MyOtherStruct [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; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -642,8 +652,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -657,59 +666,16 @@ public partial struct MyOtherStruct [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; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -727,8 +693,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -742,27 +707,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -778,8 +732,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -794,27 +747,16 @@ public partial struct MyOtherStruct [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; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -853,7 +795,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -864,17 +806,25 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -885,17 +835,25 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -908,17 +866,25 @@ struct MyStruct }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -968,7 +934,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1022,7 +988,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1077,7 +1043,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1123,6 +1089,8 @@ struct MyStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1134,7 +1102,7 @@ public partial struct MyUnion public {expectedManagedType} value; }} - public unsafe partial struct MyStruct + public partial struct MyStruct {{ public {expectedManagedType} x; @@ -1143,71 +1111,79 @@ public unsafe partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref {expectedManagedType} z {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._w_e__Struct w {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; }} }} + [UnscopedRef] public ref {expectedManagedType} value1 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.value1, 1)); + return ref Anonymous.Anonymous1.value1; }} }} + [UnscopedRef] public ref {expectedManagedType} value {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous.value, 1)); + return ref Anonymous.Anonymous1.Anonymous.value; }} }} + [UnscopedRef] public ref {expectedManagedType} value2 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2.value2, 1)); + return ref Anonymous.Anonymous2.value2; }} }} + [UnscopedRef] public ref MyUnion u {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer1 {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; }} }} + [UnscopedRef] public Span buffer2 {{ get {{ - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; }} }} - public unsafe partial struct _Anonymous_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} z; @@ -1223,7 +1199,7 @@ public unsafe partial struct _Anonymous_e__Struct public MyUnion u; [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer1[4]; + public _buffer1_e__FixedBuffer buffer1; [NativeTypeName(""MyUnion[4]"")] public _buffer2_e__FixedBuffer buffer2; @@ -1253,29 +1229,23 @@ public partial struct _Anonymous2_e__Union public {expectedManagedType} value2; }} + [InlineArray(4)] + public partial struct _buffer1_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} + + [InlineArray(4)] public partial struct _buffer2_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - public MyUnion e3; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1299,7 +1269,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1312,19 +1282,21 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -1400,7 +1372,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1445,7 +1417,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1497,7 +1469,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1534,7 +1506,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1548,7 +1520,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() @@ -1607,7 +1579,7 @@ public unsafe partial struct MyStruct1 }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1628,7 +1600,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1652,7 +1624,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1668,7 +1640,7 @@ public partial struct MyStruct "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1685,7 +1657,7 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1700,11 +1672,12 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1720,7 +1693,7 @@ public partial struct _Anonymous_e__Struct ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1748,7 +1721,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1765,7 +1738,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1796,7 +1769,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1827,7 +1800,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1862,7 +1835,7 @@ public void MyMethod() } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1917,7 +1890,7 @@ public partial struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1930,7 +1903,7 @@ struct MyStruct }; "; - const string ExpectedOutputContents = @"using System; + const string ExpectedOutputContents = @"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1941,20 +1914,10 @@ public partial struct MyStruct [NativeTypeName(""size_t[2]"")] public _FixedBuffer_e__FixedBuffer FixedBuffer; + [InlineArray(2)] public partial struct _FixedBuffer_e__FixedBuffer { public nuint e0; - public nuint e1; - - public ref nuint this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); } } } @@ -1963,7 +1926,7 @@ public ref nuint this[int index] var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1993,7 +1956,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -2002,10 +1965,11 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; - var expectedOutputContents = @"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace ClangSharp.Test { @@ -2017,11 +1981,12 @@ public partial struct _MyStruct [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; + [UnscopedRef] public ref int First { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; } } @@ -2035,26 +2000,16 @@ public partial struct _MyArray_e__Struct public int Second; } + [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { public _MyArray_e__Struct e0; - public _MyArray_e__Struct e1; - - public ref _MyArray_e__Struct this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span<_MyArray_e__Struct> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); } } } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2067,7 +2022,7 @@ struct { int Value2; }; }; }; } MyStruct;"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -2076,19 +2031,21 @@ public partial struct _MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int Value1 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } + [UnscopedRef] public ref int Value2 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous3.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } @@ -2120,6 +2077,6 @@ public partial struct _Anonymous3_e__Struct } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs index 6319eafe..19eb4459 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/UnionDeclarationTest.cs @@ -39,7 +39,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -70,7 +70,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -105,7 +105,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -327,14 +327,14 @@ readonly get }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -350,7 +350,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -369,27 +369,16 @@ public partial struct MyOtherUnion [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; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -405,7 +394,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -424,59 +413,16 @@ public partial struct MyOtherUnion [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; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -494,7 +440,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -513,27 +459,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -549,7 +484,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -569,27 +504,16 @@ public partial struct MyOtherUnion [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; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -632,7 +556,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -643,21 +567,28 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -668,21 +599,28 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -695,21 +633,28 @@ union MyUnion }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -762,7 +707,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -789,6 +734,8 @@ union MyUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -799,7 +746,7 @@ public partial struct MyStruct }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] public {expectedManagedType} r; @@ -814,32 +761,35 @@ public unsafe partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref {expectedManagedType} a {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; }} }} + [UnscopedRef] public ref MyStruct s {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; }} }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _Anonymous_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] public {expectedManagedType} a; @@ -849,13 +799,19 @@ public unsafe partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer[4]; + public _buffer_e__FixedBuffer buffer; + + [InlineArray(4)] + public partial struct _buffer_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -879,7 +835,8 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -896,19 +853,21 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -990,7 +949,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } @@ -1047,7 +1006,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1110,7 +1069,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1157,7 +1116,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1174,7 +1133,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1200,7 +1159,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1229,7 +1188,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1248,7 +1207,7 @@ public partial struct MyUnion "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1265,7 +1224,8 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1285,11 +1245,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1307,7 +1268,7 @@ public partial struct _Anonymous_e__Union ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1341,7 +1302,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1361,7 +1322,7 @@ public partial struct MyUnion } "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1398,7 +1359,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1435,7 +1396,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1461,7 +1422,8 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() }}; }} MY_UNION;"; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1477,27 +1439,30 @@ public partial struct _MY_UNION [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref nint First {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.A, 1)); + return ref Anonymous.Anonymous.A; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.B, 1)); + return ref Anonymous.Anonymous.B; }} }} @@ -1534,25 +1499,15 @@ public partial struct _B_e__Struct }} }} + [InlineArray(2)] public partial struct _AsArray_e__FixedBuffer {{ public nint e0; - public nint e1; - - public ref nint this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); }} }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs index 611048ea..3ec691d8 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultUnix/VarDeclarationTest.cs @@ -22,7 +22,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -39,7 +39,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -67,7 +67,7 @@ public static partial class Methods "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -88,7 +88,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -106,14 +106,14 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -127,12 +127,12 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""#define MyMacro1 \""Test\0\\\r\n\t\""\"""")] - public static ReadOnlySpan MyMacro1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyMacro1 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -149,7 +149,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -158,23 +158,25 @@ protected override Task WideStringLiteralConstTestImpl() const wchar_t* MyConst2 = L""Test\0\\\r\n\t\""""; const wchar_t* const MyConst3 = L""Test\0\\\r\n\t\"""";"; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System; + +namespace ClangSharp.Test {{ public static partial class Methods {{ [NativeTypeName(""const wchar_t[11]"")] - public static readonly uint[] MyConst1 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }}; + public static ReadOnlySpan MyConst1 => [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000]; [NativeTypeName(""const wchar_t *"")] - public static uint[] MyConst2 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }}; + public static uint[] MyConst2 = [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000]; [NativeTypeName(""const wchar_t *const"")] - public static readonly uint[] MyConst3 = new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }}; + public static ReadOnlySpan MyConst3 => [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000]; }} }} "; - return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -190,18 +192,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -242,18 +244,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -274,7 +276,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -291,7 +293,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -310,7 +312,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -327,7 +329,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -344,7 +346,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -373,7 +375,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -393,6 +395,6 @@ public static partial class Methods "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs index ce5e2d6d..410f1f44 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/FunctionDeclarationBodyImportTest.cs @@ -1428,7 +1428,8 @@ void MyFunction() } "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1439,11 +1440,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs index 79efd657..3c646741 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/StructDeclarationTest.cs @@ -19,17 +19,39 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[]"")] - public fixed {expectedManagedType} x[1]; + public _x_e__FixedBuffer x; + + public partial struct _x_e__FixedBuffer + {{ + public {expectedManagedType} e0; + + [UnscopedRef] + public ref {expectedManagedType} this[int index] + {{ + get + {{ + return ref Unsafe.Add(ref e0, index); + }} + }} + + [UnscopedRef] + public Span<{expectedManagedType}> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length); + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -55,7 +77,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -80,7 +102,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -109,7 +131,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -322,7 +344,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -546,7 +568,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -576,14 +598,14 @@ public static partial class Methods } } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -599,8 +621,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -614,27 +635,16 @@ public partial struct MyOtherStruct [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; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -650,8 +660,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -665,59 +674,16 @@ public partial struct MyOtherStruct [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; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -735,8 +701,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -750,27 +715,16 @@ public partial struct MyOtherStruct [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyStruct e0; - public MyStruct e1; - public MyStruct e2; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -786,8 +740,7 @@ struct MyOtherStruct }}; "; - var expectedOutputContents = $@"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; namespace ClangSharp.Test {{ @@ -802,27 +755,16 @@ public partial struct MyOtherStruct [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; - - public ref MyStruct this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -861,7 +803,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -872,17 +814,25 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -893,17 +843,25 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -916,17 +874,25 @@ struct MyStruct }}; "; - var expectedOutputContents = $@"namespace ClangSharp.Test + var expectedOutputContents = $@"using System.Runtime.CompilerServices; + +namespace ClangSharp.Test {{ - public unsafe partial struct MyStruct + public partial struct MyStruct {{ [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -976,7 +942,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1030,7 +996,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1085,7 +1051,7 @@ public partial struct MyStruct2 } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1131,6 +1097,8 @@ struct MyStruct "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1142,7 +1110,7 @@ public partial struct MyUnion public {expectedManagedType} value; }} - public unsafe partial struct MyStruct + public partial struct MyStruct {{ public {expectedManagedType} x; @@ -1151,71 +1119,79 @@ public unsafe partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref {expectedManagedType} z {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._w_e__Struct w {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; }} }} + [UnscopedRef] public ref {expectedManagedType} value1 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.value1, 1)); + return ref Anonymous.Anonymous1.value1; }} }} + [UnscopedRef] public ref {expectedManagedType} value {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous.value, 1)); + return ref Anonymous.Anonymous1.Anonymous.value; }} }} + [UnscopedRef] public ref {expectedManagedType} value2 {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous2.value2, 1)); + return ref Anonymous.Anonymous2.value2; }} }} + [UnscopedRef] public ref MyUnion u {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer1 {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; }} }} + [UnscopedRef] public Span buffer2 {{ get {{ - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; }} }} - public unsafe partial struct _Anonymous_e__Struct + public partial struct _Anonymous_e__Struct {{ public {expectedManagedType} z; @@ -1231,7 +1207,7 @@ public unsafe partial struct _Anonymous_e__Struct public MyUnion u; [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer1[4]; + public _buffer1_e__FixedBuffer buffer1; [NativeTypeName(""MyUnion[4]"")] public _buffer2_e__FixedBuffer buffer2; @@ -1261,29 +1237,23 @@ public partial struct _Anonymous2_e__Union public {expectedManagedType} value2; }} + [InlineArray(4)] + public partial struct _buffer1_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} + + [InlineArray(4)] public partial struct _buffer2_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - public MyUnion e3; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 4); }} }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1307,7 +1277,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1320,19 +1290,21 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -1408,7 +1380,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1453,7 +1425,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1505,7 +1477,7 @@ public partial struct MyNestedStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1542,7 +1514,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1556,7 +1528,7 @@ public partial struct MyStruct }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() @@ -1615,7 +1587,7 @@ public unsafe partial struct MyStruct1 }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1636,7 +1608,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1660,7 +1632,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1676,7 +1648,7 @@ public partial struct MyStruct "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1693,7 +1665,7 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -1708,11 +1680,12 @@ public partial struct MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1728,7 +1701,7 @@ public partial struct _Anonymous_e__Struct ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1756,7 +1729,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1773,7 +1746,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1804,7 +1777,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1835,7 +1808,7 @@ public partial struct MyStruct }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1870,7 +1843,7 @@ public void MyMethod() } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1925,7 +1898,7 @@ public partial struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1936,7 +1909,7 @@ protected override Task WithPackingTestImpl() }; "; - const string ExpectedOutputContents = @"using System; + const string ExpectedOutputContents = @"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -1947,20 +1920,10 @@ public partial struct MyStruct [NativeTypeName(""size_t[2]"")] public _FixedBuffer_e__FixedBuffer FixedBuffer; + [InlineArray(2)] public partial struct _FixedBuffer_e__FixedBuffer { public nuint e0; - public nuint e1; - - public ref nuint this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); } } } @@ -1969,7 +1932,7 @@ public ref nuint this[int index] var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1999,7 +1962,7 @@ public partial struct MyStruct } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -2008,10 +1971,11 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; - var expectedOutputContents = @"using System; -using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; namespace ClangSharp.Test { @@ -2023,11 +1987,12 @@ public partial struct _MyStruct [NativeTypeName(""struct (anonymous struct at ClangUnsavedFile.h:4:5)[2]"")] public _MyArray_e__FixedBuffer MyArray; + [UnscopedRef] public ref int First { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; } } @@ -2041,26 +2006,16 @@ public partial struct _MyArray_e__Struct public int Second; } + [InlineArray(2)] public partial struct _MyArray_e__FixedBuffer { public _MyArray_e__Struct e0; - public _MyArray_e__Struct e1; - - public ref _MyArray_e__Struct this[int index] - { - get - { - return ref AsSpan()[index]; - } - } - - public Span<_MyArray_e__Struct> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 2); } } } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2073,7 +2028,7 @@ struct { int Value2; }; }; }; } MyStruct;"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; namespace ClangSharp.Test { @@ -2082,19 +2037,21 @@ public partial struct _MyStruct [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L3_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int Value1 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; } } + [UnscopedRef] public ref int Value2 { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous3.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; } } @@ -2126,6 +2083,6 @@ public partial struct _Anonymous3_e__Struct } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs index 4a7c46fe..76398156 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/UnionDeclarationTest.cs @@ -39,7 +39,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -70,7 +70,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -105,7 +105,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -333,14 +333,14 @@ readonly get }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -356,7 +356,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -375,27 +375,16 @@ public partial struct MyOtherUnion [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; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -411,7 +400,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -430,59 +419,16 @@ public partial struct MyOtherUnion [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; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0_0_0_0, 24); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -500,7 +446,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -519,27 +465,16 @@ public partial struct MyOtherUnion [NativeTypeName(""MyBuffer"")] public _c_e__FixedBuffer c; + [InlineArray(3)] public partial struct _c_e__FixedBuffer {{ public MyUnion e0; - public MyUnion e1; - public MyUnion e2; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -555,7 +490,7 @@ union MyOtherUnion }}; "; - var expectedOutputContents = $@"using System; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -575,27 +510,16 @@ public partial struct MyOtherUnion [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; - - public ref MyUnion this[int index] - {{ - get - {{ - return ref AsSpan()[index]; - }} - }} - - public Span AsSpan() => MemoryMarshal.CreateSpan(ref e0, 3); }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -638,7 +562,7 @@ public ref {expectedManagedType} this[int index] }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -649,21 +573,28 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[3]"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -674,21 +605,28 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""{nativeType}[2][1][3][4]"")] - public fixed {expectedManagedType} c[2 * 1 * 3 * 4]; + public _c_e__FixedBuffer c; + + [InlineArray(2 * 1 * 3 * 4)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0_0_0_0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -701,21 +639,28 @@ union MyUnion }}; "; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] [NativeTypeName(""MyBuffer"")] - public fixed {expectedManagedType} c[3]; + public _c_e__FixedBuffer c; + + [InlineArray(3)] + public partial struct _c_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -768,7 +713,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -795,6 +740,8 @@ union MyUnion "; var expectedOutputContents = $@"using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace ClangSharp.Test @@ -805,7 +752,7 @@ public partial struct MyStruct }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct MyUnion + public partial struct MyUnion {{ [FieldOffset(0)] public {expectedManagedType} r; @@ -820,32 +767,35 @@ public unsafe partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L{line}_C{column}"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref {expectedManagedType} a {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; }} }} + [UnscopedRef] public ref MyStruct s {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; }} }} + [UnscopedRef] public Span<{expectedManagedType}> buffer {{ get {{ - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; }} }} [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _Anonymous_e__Union + public partial struct _Anonymous_e__Union {{ [FieldOffset(0)] public {expectedManagedType} a; @@ -855,13 +805,19 @@ public unsafe partial struct _Anonymous_e__Union [FieldOffset(0)] [NativeTypeName(""{nativeType}[4]"")] - public fixed {expectedManagedType} buffer[4]; + public _buffer_e__FixedBuffer buffer; + + [InlineArray(4)] + public partial struct _buffer_e__FixedBuffer + {{ + public {expectedManagedType} e0; + }} }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -885,7 +841,8 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() }; "; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -902,19 +859,21 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L6_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref int z { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; } } + [UnscopedRef] public ref int w { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; } } @@ -996,7 +955,7 @@ readonly get } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } @@ -1053,7 +1012,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1116,7 +1075,7 @@ public partial struct MyNestedUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1163,7 +1122,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1180,7 +1139,7 @@ public partial struct MyUnion }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1206,7 +1165,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1235,7 +1194,7 @@ public unsafe partial struct example_s }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1254,7 +1213,7 @@ public partial struct MyUnion "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1271,7 +1230,8 @@ protected override Task RemapNestedAnonymousTestImpl() }; };"; - var expectedOutputContents = @"using System.Runtime.InteropServices; + var expectedOutputContents = @"using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace ClangSharp.Test { @@ -1291,11 +1251,12 @@ public partial struct MyUnion [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L7_C5"")] public _Anonymous_e__Union Anonymous; + [UnscopedRef] public ref double a { get { - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; } } @@ -1313,7 +1274,7 @@ public partial struct _Anonymous_e__Union ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1347,7 +1308,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1367,7 +1328,7 @@ public partial struct MyUnion } "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1404,7 +1365,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1441,7 +1402,7 @@ public partial struct MyUnion }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1467,42 +1428,47 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() }}; }} MY_UNION;"; - var expectedOutputContents = $@"using System.Runtime.InteropServices; + var expectedOutputContents = $@"using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ClangSharp.Test {{ [StructLayout(LayoutKind.Explicit)] - public unsafe partial struct _MY_UNION + public partial struct _MY_UNION {{ [FieldOffset(0)] [NativeTypeName(""long[2]"")] - public fixed int AsArray[2]; + public _AsArray_e__FixedBuffer AsArray; [FieldOffset(0)] [NativeTypeName(""__AnonymousRecord_ClangUnsavedFile_L4_C5"")] public _Anonymous_e__Struct Anonymous; + [UnscopedRef] public ref int First {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct A {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.A, 1)); + return ref Anonymous.Anonymous.A; }} }} + [UnscopedRef] public ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct B {{ get {{ - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.B, 1)); + return ref Anonymous.Anonymous.B; }} }} @@ -1538,10 +1504,16 @@ public partial struct _B_e__Struct }} }} }} + + [InlineArray(2)] + public partial struct _AsArray_e__FixedBuffer + {{ + public int e0; + }} }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs index bc82da08..63d7d276 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpDefaultWindows/VarDeclarationTest.cs @@ -22,7 +22,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -39,7 +39,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -67,7 +67,7 @@ public static partial class Methods "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -88,7 +88,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -106,14 +106,14 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -127,12 +127,12 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""#define MyMacro1 \""Test\0\\\r\n\t\""\"""")] - public static ReadOnlySpan MyMacro1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyMacro1 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -149,7 +149,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -174,7 +174,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -190,18 +190,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -226,7 +226,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralStaticConstTestImpl() @@ -242,18 +242,18 @@ namespace ClangSharp.Test public static partial class Methods {{ [NativeTypeName(""const char[11]"")] - public static ReadOnlySpan MyConst1 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst1 => ""Test\0\\\r\n\t\""""u8; [NativeTypeName(""const char *"")] - public static byte[] MyConst2 = new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static byte[] MyConst2 = ""Test\0\\\r\n\t\""""u8.ToArray(); [NativeTypeName(""const char *const"")] - public static ReadOnlySpan MyConst3 => new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }}; + public static ReadOnlySpan MyConst3 => ""Test\0\\\r\n\t\""""u8; }} }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -274,7 +274,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -291,7 +291,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -310,7 +310,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -327,7 +327,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -344,7 +344,7 @@ public static unsafe partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -373,7 +373,7 @@ public static partial class Methods }} "; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -393,6 +393,6 @@ public static partial class Methods "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs index f54f80ff..d4d7654f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/FunctionDeclarationBodyImportTest.cs @@ -1618,7 +1618,7 @@ void MyFunction() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs index 636a6b0e..a137a9f1 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/StructDeclarationTest.cs @@ -22,16 +22,37 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@" - + {expectedManagedType} + + + {expectedManagedType} + + + ref {expectedManagedType} + + int + + + return ref Unsafe.Add(ref e0, index); + + + + Span<{expectedManagedType}> + + int + + MemoryMarshal.CreateSpan(ref e0, length); + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -62,7 +83,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -92,7 +113,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -123,7 +144,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -294,7 +315,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -476,7 +497,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -505,14 +526,14 @@ typedef struct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -541,35 +562,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -598,98 +601,17 @@ 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); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -720,35 +642,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -777,35 +681,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -851,7 +737,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -865,16 +751,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -888,16 +780,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -913,16 +811,22 @@ struct MyStruct var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -967,7 +871,7 @@ struct DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyStruct2 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1028,7 +932,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1089,7 +993,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1127,7 +1031,7 @@ struct MyStruct {expectedManagedType} - + {expectedManagedType} @@ -1140,34 +1044,34 @@ struct MyStruct ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref _Anonymous_e__Struct._w_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; ref MyUnion - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; Span<MyUnion> - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; - + {expectedManagedType} @@ -1188,32 +1092,17 @@ struct MyStruct {expectedManagedType} - + + InlineArray(4) - MyUnion - - - MyUnion - - - MyUnion + {expectedManagedType} - + + + InlineArray(4) + MyUnion - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 4); - @@ -1221,7 +1110,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1261,13 +1150,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; @@ -1329,7 +1218,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1382,7 +1271,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1435,7 +1324,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1481,7 +1370,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1495,7 +1384,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() { @@ -1549,7 +1438,7 @@ struct MyStruct2 { "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1574,7 +1463,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1601,7 +1490,7 @@ struct example_s { "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1617,7 +1506,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1653,7 +1542,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1670,7 +1559,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1703,7 +1592,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1720,7 +1609,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1753,7 +1642,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1786,7 +1675,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1821,7 +1710,7 @@ struct MyStruct1B : MyStruct1A "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1882,7 +1771,7 @@ struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1903,25 +1792,10 @@ struct MyStruct nuint + InlineArray(2) nuint - - nuint - - - ref nuint - - int - - - return ref AsSpan()[index]; - - - - Span<nuint> - MemoryMarshal.CreateSpan(ref e0, 2); - @@ -1931,7 +1805,7 @@ struct MyStruct var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedXmlLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1962,7 +1836,7 @@ protected override Task SourceLocationAttributeTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedXmlLatestUnixBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -1971,7 +1845,8 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" @@ -1986,7 +1861,7 @@ struct { int Second; } MyArray[2]; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; @@ -2000,32 +1875,17 @@ struct { int Second; } MyArray[2]; + InlineArray(2) _MyArray_e__Struct - - _MyArray_e__Struct - - - ref _MyArray_e__Struct - - int - - - return ref AsSpan()[index]; - - - - Span<_MyArray_e__Struct> - MemoryMarshal.CreateSpan(ref e0, 2); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2036,7 +1896,8 @@ struct { struct { struct { int Value1; }; struct { int Value2; }; }; }; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" @@ -2048,13 +1909,13 @@ struct { int Value2; }; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous3.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; @@ -2085,6 +1946,6 @@ struct { int Value2; }; "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs index 803d5397..51afb019 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/UnionDeclarationTest.cs @@ -38,7 +38,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -68,7 +68,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -99,7 +99,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -272,14 +272,14 @@ union MyUnion3 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -308,35 +308,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -365,98 +347,17 @@ 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); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -487,35 +388,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -544,35 +427,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -618,7 +483,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -632,16 +497,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -655,16 +526,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -680,16 +557,22 @@ union MyUnion var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -733,7 +616,7 @@ union DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyUnion2 "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -767,7 +650,7 @@ union MyUnion {expectedManagedType} - + {expectedManagedType} @@ -783,22 +666,22 @@ union MyUnion ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; ref MyStruct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; - + {expectedManagedType} @@ -808,13 +691,19 @@ union MyUnion {expectedManagedType} + + InlineArray(4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -854,13 +743,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; @@ -922,7 +811,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } @@ -976,7 +865,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1029,7 +918,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1075,7 +964,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1089,7 +978,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1114,7 +1003,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1141,7 +1030,7 @@ union example_s { "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1157,7 +1046,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1193,7 +1082,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1210,7 +1099,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1243,7 +1132,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1260,7 +1149,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1293,7 +1182,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1326,7 +1215,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1365,19 +1254,19 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() ref nint - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.A, 1)); + return ref Anonymous.Anonymous.A; ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.B, 1)); + return ref Anonymous.Anonymous.B; @@ -1407,31 +1296,16 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() + InlineArray(2) nint - - nint - - - ref nint - - int - - - return ref AsSpan()[index]; - - - - Span<nint> - MemoryMarshal.CreateSpan(ref e0, 2); - "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs index 26aa0acf..f321d031 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultUnix/VarDeclarationTest.cs @@ -28,7 +28,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -50,7 +50,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -81,7 +81,7 @@ protected override Task GuidMacroTestImpl() "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -110,7 +110,7 @@ protected override Task MacroTestImpl(string nativeValue, string expectedManaged "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -133,14 +133,14 @@ protected override Task MultilineMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -154,7 +154,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -162,7 +162,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -184,7 +184,7 @@ protected override Task Utf16StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -198,21 +198,21 @@ protected override Task WideStringLiteralConstTestImpl() - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] uint[] - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] @@ -220,7 +220,7 @@ protected override Task WideStringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -236,19 +236,19 @@ protected override Task StringLiteralConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -256,7 +256,7 @@ protected override Task StringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -270,21 +270,21 @@ protected override Task WideStringLiteralStaticConstTestImpl() - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] uint[] - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] - uint[] + ReadOnlySpan<uint> - new uint[] {{ 0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000 }} + [0x00000054, 0x00000065, 0x00000073, 0x00000074, 0x00000000, 0x0000005C, 0x0000000D, 0x0000000A, 0x00000009, 0x00000022, 0x00000000] @@ -292,7 +292,7 @@ protected override Task WideStringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralStaticConstTestImpl() @@ -308,19 +308,19 @@ protected override Task StringLiteralStaticConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -328,7 +328,7 @@ protected override Task StringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -365,7 +365,7 @@ protected override Task UncheckedConversionMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -391,7 +391,7 @@ protected override Task UncheckedFunctionLikeCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -417,7 +417,7 @@ protected override Task UncheckedConversionMacroTest2Impl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -441,7 +441,7 @@ protected override Task UncheckedPointerMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -467,7 +467,7 @@ protected override Task UncheckedReinterpretCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -501,7 +501,7 @@ protected override Task MultidimensionlArrayTestImpl() "; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -528,6 +528,6 @@ protected override Task ConditionalDefineConstTestImpl() "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs index 00348ce7..406a488f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/FunctionDeclarationBodyImportTest.cs @@ -1618,7 +1618,7 @@ void MyFunction() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs index 85b792f7..324ffced 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/StructDeclarationTest.cs @@ -22,16 +22,37 @@ protected override Task IncompleteArraySizeTestImpl(string nativeType, string ex var expectedOutputContents = $@" - + {expectedManagedType} + + + {expectedManagedType} + + + ref {expectedManagedType} + + int + + + return ref Unsafe.Add(ref e0, index); + + + + Span<{expectedManagedType}> + + int + + MemoryMarshal.CreateSpan(ref e0, length); + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestImpl(string nativeType, string expectedManagedType) @@ -62,7 +83,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -92,7 +113,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -123,7 +144,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -300,7 +321,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldWithNativeBitfieldAttributeTestImpl() @@ -488,7 +509,7 @@ struct MyStruct3 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute); } protected override Task DeclTypeTestImpl() @@ -517,14 +538,14 @@ typedef struct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef struct MyStruct MyStruct;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -553,35 +574,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -610,98 +613,17 @@ 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); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -732,35 +654,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -789,35 +693,17 @@ struct MyOtherStruct MyStruct + InlineArray(3) MyStruct - - MyStruct - - - MyStruct - - - ref MyStruct - - int - - - return ref AsSpan()[index]; - - - - Span<MyStruct> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -863,7 +749,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -877,16 +763,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -900,16 +792,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -925,16 +823,22 @@ struct MyStruct var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() @@ -979,7 +883,7 @@ struct DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyStruct2 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task InheritanceTestImpl() @@ -1040,7 +944,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task InheritanceWithNativeInheritanceAttributeTestImpl() @@ -1101,7 +1005,7 @@ struct MyStruct2 : MyStruct1A, MyStruct1B "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -1139,7 +1043,7 @@ struct MyStruct {expectedManagedType} - + {expectedManagedType} @@ -1152,34 +1056,34 @@ struct MyStruct ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref _Anonymous_e__Struct._w_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.w, 1)); + return ref Anonymous.w; ref MyUnion - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.u, 1)); + return ref Anonymous.u; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer1[0], 4); + return Anonymous.buffer1; Span<MyUnion> - return Anonymous.buffer2.AsSpan(); + return Anonymous.buffer2; - + {expectedManagedType} @@ -1200,32 +1104,17 @@ struct MyStruct {expectedManagedType} - + + InlineArray(4) - MyUnion - - - MyUnion - - - MyUnion + {expectedManagedType} - + + + InlineArray(4) + MyUnion - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 4); - @@ -1233,7 +1122,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -1273,13 +1162,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; @@ -1341,7 +1230,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedTestImpl(string nativeType, string expectedManagedType) @@ -1394,7 +1283,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1447,7 +1336,7 @@ struct MyNestedStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1493,7 +1382,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1507,7 +1396,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PackTestImpl() { @@ -1561,7 +1450,7 @@ struct MyStruct2 { "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(InputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(InputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1586,7 +1475,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1613,7 +1502,7 @@ struct example_s { "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1629,7 +1518,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyStruct"] = "MyStruct" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1665,7 +1554,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1682,7 +1571,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Struct" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1715,7 +1604,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1732,7 +1621,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1765,7 +1654,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1798,7 +1687,7 @@ struct MyStruct "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UsingDeclarationTestImpl() @@ -1833,7 +1722,7 @@ struct MyStruct1B : MyStruct1A "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WithAccessSpecifierTestImpl() @@ -1894,7 +1783,7 @@ struct MyStruct3 ["Field1"] = AccessSpecifier.Private, ["MyStruct3.Field2"] = AccessSpecifier.Internal, }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAccessSpecifiers: withAccessSpecifiers); } protected override Task WithPackingTestImpl() @@ -1913,25 +1802,10 @@ protected override Task WithPackingTestImpl() nuint + InlineArray(2) nuint - - nuint - - - ref nuint - - int - - - return ref AsSpan()[index]; - - - - Span<nuint> - MemoryMarshal.CreateSpan(ref e0, 2); - @@ -1941,7 +1815,7 @@ protected override Task WithPackingTestImpl() var withPackings = new Dictionary { ["MyStruct"] = "CustomPackValue" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, withPackings: withPackings); } protected override Task SourceLocationAttributeTestImpl() @@ -1972,7 +1846,7 @@ protected override Task SourceLocationAttributeTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(InputContents, ExpectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateSourceLocationAttribute); } protected override Task AnonStructAndAnonStructArrayImpl() @@ -1981,7 +1855,8 @@ protected override Task AnonStructAndAnonStructArrayImpl() { struct { int First; }; struct { int Second; } MyArray[2]; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" @@ -1996,7 +1871,7 @@ struct { int Second; } MyArray[2]; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; @@ -2010,32 +1885,17 @@ struct { int Second; } MyArray[2]; + InlineArray(2) _MyArray_e__Struct - - _MyArray_e__Struct - - - ref _MyArray_e__Struct - - int - - - return ref AsSpan()[index]; - - - - Span<_MyArray_e__Struct> - MemoryMarshal.CreateSpan(ref e0, 2); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task DeeplyNestedAnonStructsImpl() @@ -2046,7 +1906,8 @@ struct { struct { struct { int Value1; }; struct { int Value2; }; }; }; -} MyStruct;"; +} MyStruct; +"; var expectedOutputContents = @" @@ -2058,13 +1919,13 @@ struct { int Value2; }; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous2.Value1, 1)); + return ref Anonymous.Anonymous1.Anonymous2.Value1; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.Anonymous3.Value2, 1)); + return ref Anonymous.Anonymous1.Anonymous3.Value2; @@ -2095,6 +1956,6 @@ struct { int Value2; }; "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs index 933d956d..ee8d74a8 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/UnionDeclarationTest.cs @@ -38,7 +38,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicTestInCModeImpl(string nativeType, string expectedManagedType) @@ -68,7 +68,7 @@ protected override Task BasicTestInCModeImpl(string nativeType, string expectedM "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, commandLineArgs: []); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -99,7 +99,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BitfieldTestImpl() @@ -278,14 +278,14 @@ union MyUnion3 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ExcludeTestImpl() { var inputContents = "typedef union MyUnion MyUnion;"; var expectedOutputContents = string.Empty; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: ExcludeTestExcludedNames); } protected override Task FixedSizedBufferNonPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -314,35 +314,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -371,98 +353,17 @@ 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); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -493,35 +394,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferNonPrimitiveWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -550,35 +433,17 @@ union MyOtherUnion MyUnion + InlineArray(3) MyUnion - - MyUnion - - - MyUnion - - - ref MyUnion - - int - - - return ref AsSpan()[index]; - - - - Span<MyUnion> - MemoryMarshal.CreateSpan(ref e0, 3); - "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPointerTestImpl(string nativeType, string expectedManagedType) @@ -624,7 +489,7 @@ protected override Task FixedSizedBufferPointerTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, string expectedManagedType) @@ -638,16 +503,22 @@ protected override Task FixedSizedBufferPrimitiveTestImpl(string nativeType, str var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string nativeType, string expectedManagedType) @@ -661,16 +532,22 @@ protected override Task FixedSizedBufferPrimitiveMultidimensionalTestImpl(string var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(2 * 1 * 3 * 4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task FixedSizedBufferPrimitiveTypedefTestImpl(string nativeType, string expectedManagedType) @@ -686,16 +563,22 @@ union MyUnion var expectedOutputContents = $@" - + {expectedManagedType} + + InlineArray(3) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidTestImpl() { @@ -739,7 +622,7 @@ union DECLSPEC_UUID(""00000000-0000-0000-C000-000000000047"") MyUnion2 "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidTestExcludedNames); } protected override Task NestedAnonymousTestImpl(string nativeType, string expectedManagedType, int line, int column) @@ -773,7 +656,7 @@ union MyUnion {expectedManagedType} - + {expectedManagedType} @@ -789,22 +672,22 @@ union MyUnion ref {expectedManagedType} - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; ref MyStruct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.s, 1)); + return ref Anonymous.s; Span<{expectedManagedType}> - return MemoryMarshal.CreateSpan(ref Anonymous.buffer[0], 4); + return Anonymous.buffer; - + {expectedManagedType} @@ -814,13 +697,19 @@ union MyUnion {expectedManagedType} + + InlineArray(4) + + {expectedManagedType} + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedAnonymousWithBitfieldTestImpl() @@ -860,13 +749,13 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.z, 1)); + return ref Anonymous.z; ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous1.w, 1)); + return ref Anonymous.Anonymous1.w; @@ -928,7 +817,7 @@ protected override Task NestedAnonymousWithBitfieldTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } @@ -982,7 +871,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NestedWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1035,7 +924,7 @@ union MyNestedUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NewKeywordTestImpl() @@ -1081,7 +970,7 @@ protected override Task NewKeywordTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoDefinitionTestImpl() @@ -1095,7 +984,7 @@ protected override Task NoDefinitionTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfTestImpl() @@ -1120,7 +1009,7 @@ protected override Task PointerToSelfTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task PointerToSelfViaTypedefTestImpl() @@ -1147,7 +1036,7 @@ union example_s { "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task RemapTestImpl() @@ -1163,7 +1052,7 @@ protected override Task RemapTestImpl() "; var remappedNames = new Dictionary { ["_MyUnion"] = "MyUnion" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task RemapNestedAnonymousTestImpl() @@ -1199,7 +1088,7 @@ protected override Task RemapNestedAnonymousTestImpl() ref double - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1)); + return ref Anonymous.a; @@ -1216,7 +1105,7 @@ protected override Task RemapNestedAnonymousTestImpl() ["__AnonymousField_ClangUnsavedFile_L7_C5"] = "Anonymous", ["__AnonymousRecord_ClangUnsavedFile_L7_C5"] = "_Anonymous_e__Union" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, remappedNames: remappedNames); } protected override Task SkipNonDefinitionTestImpl(string nativeType, string expectedManagedType) @@ -1249,7 +1138,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionPointerTestImpl() @@ -1266,7 +1155,7 @@ protected override Task SkipNonDefinitionPointerTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task SkipNonDefinitionWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -1299,7 +1188,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task TypedefTestImpl(string nativeType, string expectedManagedType) @@ -1332,7 +1221,7 @@ union MyUnion "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UnionWithAnonStructWithAnonUnionImpl() @@ -1361,7 +1250,7 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() var expectedOutputContents = $@" - + int @@ -1371,19 +1260,19 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() ref int - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.First, 1)); + return ref Anonymous.First; ref _Anonymous_e__Struct._Anonymous_e__Union._A_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.A, 1)); + return ref Anonymous.Anonymous.A; ref _Anonymous_e__Struct._Anonymous_e__Union._B_e__Struct - return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.Anonymous.B, 1)); + return ref Anonymous.Anonymous.B; @@ -1412,11 +1301,17 @@ protected override Task UnionWithAnonStructWithAnonUnionImpl() + + InlineArray(2) + + int + + "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs index 32a1e7f7..cc815988 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlDefaultWindows/VarDeclarationTest.cs @@ -28,7 +28,7 @@ protected override Task BasicTestImpl(string nativeType, string expectedManagedT "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, string expectedManagedType) @@ -50,7 +50,7 @@ protected override Task BasicWithNativeTypeNameTestImpl(string nativeType, strin "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task GuidMacroTestImpl() @@ -81,7 +81,7 @@ protected override Task GuidMacroTestImpl() "; var remappedNames = new Dictionary { ["GUID"] = "Guid" }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: GuidMacroTestExcludedNames, remappedNames: remappedNames); } protected override Task MacroTestImpl(string nativeValue, string expectedManagedType, string expectedManagedValue) @@ -110,7 +110,7 @@ protected override Task MacroTestImpl(string nativeValue, string expectedManaged "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultilineMacroTestImpl() @@ -133,14 +133,14 @@ protected override Task MultilineMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task NoInitializerTestImpl(string nativeType) { var inputContents = $@"{nativeType} MyVariable;"; var expectedOutputContents = ""; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf8StringLiteralMacroTestImpl() @@ -154,7 +154,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -162,7 +162,7 @@ protected override Task Utf8StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task Utf16StringLiteralMacroTestImpl() @@ -184,7 +184,7 @@ protected override Task Utf16StringLiteralMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralConstTestImpl() @@ -220,7 +220,7 @@ protected override Task WideStringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralConstTestImpl() @@ -236,19 +236,19 @@ protected override Task StringLiteralConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -256,7 +256,7 @@ protected override Task StringLiteralConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task WideStringLiteralStaticConstTestImpl() @@ -292,7 +292,7 @@ protected override Task WideStringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task StringLiteralStaticConstTestImpl() @@ -308,19 +308,19 @@ protected override Task StringLiteralStaticConstTestImpl() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 byte[] - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8.ToArray() ReadOnlySpan<byte> - new byte[] {{ 0x54, 0x65, 0x73, 0x74, 0x00, 0x5C, 0x0D, 0x0A, 0x09, 0x22, 0x00 }} + ""Test\0\\\r\n\t\""""u8 @@ -328,7 +328,7 @@ protected override Task StringLiteralStaticConstTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTestImpl() @@ -365,7 +365,7 @@ protected override Task UncheckedConversionMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedFunctionLikeCastMacroTestImpl() @@ -391,7 +391,7 @@ protected override Task UncheckedFunctionLikeCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedConversionMacroTest2Impl() @@ -417,7 +417,7 @@ protected override Task UncheckedConversionMacroTest2Impl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, excludedNames: UncheckedConversionMacroTest2ExcludedNames); } protected override Task UncheckedPointerMacroTestImpl() @@ -441,7 +441,7 @@ protected override Task UncheckedPointerMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task UncheckedReinterpretCastMacroTestImpl() @@ -467,7 +467,7 @@ protected override Task UncheckedReinterpretCastMacroTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task MultidimensionlArrayTestImpl() @@ -501,7 +501,7 @@ protected override Task MultidimensionlArrayTestImpl() "; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } protected override Task ConditionalDefineConstTestImpl() @@ -528,6 +528,6 @@ protected override Task ConditionalDefineConstTestImpl() "; var diagnostics = new Diagnostic[] { new Diagnostic(DiagnosticLevel.Warning, "Function like macro definition records are not supported: 'TESTRESULT_FROM_WIN32'. Generated bindings may be incomplete.", "Line 2, Column 9 in ClangUnsavedFile.h") }; - return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); + return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, expectedDiagnostics: diagnostics); } }