diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs index 66b46710..f17c2396 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitStmt.cs @@ -1612,7 +1612,7 @@ namespace ClangSharp if (!memberExpr.IsImplicitAccess || isForDerivedType) { - var memberExprBase = memberExpr.Base.IgnoreParens.IgnoreImplicit; + var memberExprBase = memberExpr.Base.IgnoreImplicit; if (isForDerivedType) { diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationTest.cs index 70d8af93..29548200 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationTest.cs @@ -58,6 +58,46 @@ namespace ClangSharp.UnitTests [Test] public Task VirtualWithVtblIndexAttributeTest() => VirtualWithVtblIndexAttributeTestImpl(); + [Test] + public virtual Task MacrosExpansionTest() + { + var inputContents = @"typedef struct +{ + unsigned char *buf; + int size; +} context_t; + +int buf_close(void *pcontext) +{ + ((context_t*)pcontext)->buf=0; + return 0; +} +"; + + var expectedOutputContents = @"namespace ClangSharp.Test +{ + public unsafe partial struct context_t + { + [NativeTypeName(""unsigned char *"")] + public byte* buf; + + public int size; + } + + public static unsafe partial class Methods + { + public static int buf_close(void* pcontext) + { + ((context_t*)(pcontext))->buf = null; + return 0; + } + } +} +"; + + return ValidateBindingsAsync(inputContents, expectedOutputContents); + } + protected abstract Task ConstructorTestImpl(); protected abstract Task ConstructorWithInitializeTestImpl(); @@ -91,5 +131,7 @@ namespace ClangSharp.UnitTests protected abstract Task VirtualTestImpl(); protected abstract Task VirtualWithVtblIndexAttributeTestImpl(); + + protected abstract Task ValidateBindingsAsync(string inputContents, string expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationXmlTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationXmlTest.cs new file mode 100644 index 00000000..1629a16d --- /dev/null +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationXmlTest.cs @@ -0,0 +1,54 @@ +// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +using System.Threading.Tasks; +using NUnit.Framework; + +namespace ClangSharp.UnitTests +{ + public abstract class CXXMethodDeclarationXmlTest: CXXMethodDeclarationTest + { + [Test] + public override Task MacrosExpansionTest() + { + var inputContents = @"typedef struct +{ + unsigned char *buf; + int size; +} context_t; + +int buf_close(void *pcontext) +{ + ((context_t*)pcontext)->buf=0; + return 0; +} +"; + + var expectedOutputContents = @" + + + + + byte* + + + int + + + + + int + + void* + + ((context_t*)(pcontext))->buf = null; + return 0; + + + + +"; + + return ValidateBindingsAsync(inputContents, expectedOutputContents); + } + } +} diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs index e2610c8f..bf3a699f 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleUnix/CXXMethodDeclarationTest.cs @@ -937,5 +937,7 @@ namespace ClangSharp.Test return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs index 0111eda8..7df456b2 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/CXXMethodDeclarationTest.cs @@ -937,5 +937,7 @@ namespace ClangSharp.Test return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs index 0a6e841d..d0e094c9 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestUnix/CXXMethodDeclarationTest.cs @@ -847,5 +847,7 @@ namespace ClangSharp.Test return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs index ebe210db..9250aaec 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/CSharpLatestWindows/CXXMethodDeclarationTest.cs @@ -847,5 +847,7 @@ namespace ClangSharp.Test return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs index b20d24a8..82c9ff9b 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleUnix/CXXMethodDeclarationTest.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ClangSharp.UnitTests { - public sealed class XmlCompatibleUnix_CXXMethodDeclarationTest : CXXMethodDeclarationTest + public sealed class XmlCompatibleUnix_CXXMethodDeclarationTest : CXXMethodDeclarationXmlTest { protected override Task ConstructorTestImpl() { @@ -1113,5 +1113,7 @@ extern ""C"" void MyFunction();"; return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs index 42f4e185..15f76b42 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlCompatibleWindows/CXXMethodDeclarationTest.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ClangSharp.UnitTests { - public sealed class XmlCompatibleWindows_CXXMethodDeclarationTest : CXXMethodDeclarationTest + public sealed class XmlCompatibleWindows_CXXMethodDeclarationTest : CXXMethodDeclarationXmlTest { protected override Task ConstructorTestImpl() { @@ -1113,5 +1113,7 @@ extern ""C"" void MyFunction();"; return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs index 0b3474d3..488d73a7 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestUnix/CXXMethodDeclarationTest.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ClangSharp.UnitTests { - public sealed class XmlLatestUnix_CXXMethodDeclarationTest : CXXMethodDeclarationTest + public sealed class XmlLatestUnix_CXXMethodDeclarationTest : CXXMethodDeclarationXmlTest { protected override Task ConstructorTestImpl() { @@ -969,5 +969,7 @@ extern ""C"" void MyFunction();"; return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); } } diff --git a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs index c047d58e..2ef8878d 100644 --- a/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs +++ b/tests/ClangSharp.PInvokeGenerator.UnitTests/XmlLatestWindows/CXXMethodDeclarationTest.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ClangSharp.UnitTests { - public sealed class XmlLatestWindows_CXXMethodDeclarationTest : CXXMethodDeclarationTest + public sealed class XmlLatestWindows_CXXMethodDeclarationTest : CXXMethodDeclarationXmlTest { protected override Task ConstructorTestImpl() { @@ -969,5 +969,7 @@ extern ""C"" void MyFunction();"; return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute); } + + protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); } }