Fix remapping for union field names (#191)
* Fix remapping for union field names * Remove dead logic
This commit is contained in:
Родитель
c10a6dba88
Коммит
da66f976f1
|
@ -1067,7 +1067,7 @@ namespace ClangSharp
|
|||
return remappedName;
|
||||
}
|
||||
|
||||
if ((namedDecl is FieldDecl fieldDecl) && name.StartsWith("__AnonymousField_"))
|
||||
if ((namedDecl is FieldDecl fieldDecl) && name.StartsWith("__AnonymousFieldDecl_"))
|
||||
{
|
||||
remappedName = "Anonymous";
|
||||
|
||||
|
|
|
@ -1508,6 +1508,61 @@ bool MyFunction(const MyStruct& lhs, const MyStruct& rhs)
|
|||
await ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AccessUnionMemberTest()
|
||||
{
|
||||
var inputContents = @"union MyUnion
|
||||
{
|
||||
struct { int a; };
|
||||
};
|
||||
|
||||
void MyFunction()
|
||||
{
|
||||
MyUnion myUnion;
|
||||
myUnion.a = 10;
|
||||
}
|
||||
";
|
||||
|
||||
var expectedOutputContents = @"using System.Runtime.InteropServices;
|
||||
|
||||
namespace ClangSharp.Test
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public partial struct MyUnion
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
[NativeTypeName(""MyUnion::(anonymous struct at ClangUnsavedFile.h:3:5)"")]
|
||||
public _Anonymous_e__Struct Anonymous;
|
||||
|
||||
public ref int a
|
||||
{
|
||||
get
|
||||
{
|
||||
return ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Anonymous.a, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public partial struct _Anonymous_e__Struct
|
||||
{
|
||||
public int a;
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class Methods
|
||||
{
|
||||
public static void MyFunction()
|
||||
{
|
||||
MyUnion myUnion = new MyUnion();
|
||||
|
||||
myUnion.Anonymous.a = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
await ValidateGeneratedBindingsAsync(inputContents, expectedOutputContents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReturnStructTest()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче