Merge pull request #358 from kant2002/kant/fix-unwrap

Do not remove parethensis
This commit is contained in:
Tanner Gooding 2022-07-15 08:37:48 -07:00 коммит произвёл GitHub
Родитель ba726269fe b5fb74d053
Коммит 08851fe819
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 117 добавлений и 5 удалений

Просмотреть файл

@ -1612,7 +1612,7 @@ namespace ClangSharp
if (!memberExpr.IsImplicitAccess || isForDerivedType)
{
var memberExprBase = memberExpr.Base.IgnoreParens.IgnoreImplicit;
var memberExprBase = memberExpr.Base.IgnoreImplicit;
if (isForDerivedType)
{

Просмотреть файл

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

Просмотреть файл

@ -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 = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""context_t"" access=""public"" unsafe=""true"">
<field name=""buf"" access=""public"">
<type native=""unsigned char *"">byte*</type>
</field>
<field name=""size"" access=""public"">
<type>int</type>
</field>
</struct>
<class name=""Methods"" access=""public"" static=""true"">
<function name=""buf_close"" access=""public"" static=""true"" unsafe=""true"">
<type>int</type>
<param name=""pcontext"">
<type>void*</type>
</param>
<code>((context_t*)(<value>pcontext</value>))-&gt;buf = null;
return 0;</code>
</function>
</class>
</namespace>
</bindings>
";
return ValidateBindingsAsync(inputContents, expectedOutputContents);
}
}
}

Просмотреть файл

@ -937,5 +937,7 @@ namespace ClangSharp.Test
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute);
}
protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents);
}
}

Просмотреть файл

@ -937,5 +937,7 @@ namespace ClangSharp.Test
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute);
}
protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents);
}
}

Просмотреть файл

@ -847,5 +847,7 @@ namespace ClangSharp.Test
return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute);
}
protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents);
}
}

Просмотреть файл

@ -847,5 +847,7 @@ namespace ClangSharp.Test
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateVtblIndexAttribute);
}
protected override Task ValidateBindingsAsync(string inputContents, string expectedOutputContents) => ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents);
}
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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