Add a generic-nativebitfield-attribute switch

This commit is contained in:
Tanner Gooding 2023-04-09 10:58:34 -07:00
Родитель a55dc86872
Коммит 8d8b998443
23 изменённых файлов: 3538 добавлений и 68 удалений

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

@ -0,0 +1,21 @@
// 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.Collections.Generic;
namespace ClangSharp.Abstractions;
public struct BitfieldDesc
{
public Type TypeBacking { get; set; }
public List<BitfieldRegion> Regions { get; set; }
}
public struct BitfieldRegion
{
public string Name { get; set; }
public long Offset { get; set; }
public long Length { get; set; }
}

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

@ -1753,8 +1753,8 @@ public partial class PInvokeGenerator
_testOutputBuilder.WriteBlockEnd(); _testOutputBuilder.WriteBlockEnd();
} }
var bitfieldTypes = GetBitfieldCount(recordDecl); var bitfieldDescs = GetBitfieldDescs(recordDecl);
var bitfieldIndex = (bitfieldTypes.Length == 1) ? -1 : 0; var bitfieldIndex = (bitfieldDescs.Length == 1) ? -1 : 0;
var bitfieldPreviousSize = 0L; var bitfieldPreviousSize = 0L;
var bitfieldRemainingBits = 0L; var bitfieldRemainingBits = 0L;
@ -1763,7 +1763,7 @@ public partial class PInvokeGenerator
{ {
if (fieldDecl.IsBitField) if (fieldDecl.IsBitField)
{ {
VisitBitfieldDecl(fieldDecl, bitfieldTypes, recordDecl, contextName: "", ref bitfieldIndex, ref bitfieldPreviousSize, ref bitfieldRemainingBits); VisitBitfieldDecl(fieldDecl, bitfieldDescs, recordDecl, contextName: "", ref bitfieldIndex, ref bitfieldPreviousSize, ref bitfieldRemainingBits);
} }
else else
{ {
@ -2351,7 +2351,7 @@ public partial class PInvokeGenerator
} }
} }
void VisitBitfieldDecl(FieldDecl fieldDecl, Type[] types, RecordDecl recordDecl, string contextName, ref int index, ref long previousSize, ref long remainingBits) void VisitBitfieldDecl(FieldDecl fieldDecl, BitfieldDesc[] bitfieldDescs, RecordDecl recordDecl, string contextName, ref int index, ref long previousSize, ref long remainingBits)
{ {
Debug.Assert(fieldDecl.IsBitField); Debug.Assert(fieldDecl.IsBitField);
@ -2384,7 +2384,8 @@ public partial class PInvokeGenerator
remainingBits = currentSize * 8; remainingBits = currentSize * 8;
previousSize = 0; previousSize = 0;
typeBacking = (index > 0) ? types[index - 1] : types[0]; var bitfieldDesc = (index > 0) ? bitfieldDescs[index - 1] : bitfieldDescs[0];
typeBacking = bitfieldDesc.TypeBacking;
typeNameBacking = GetRemappedTypeName(fieldDecl, context: null, typeBacking, out _); typeNameBacking = GetRemappedTypeName(fieldDecl, context: null, typeBacking, out _);
if (parent == recordDecl) if (parent == recordDecl)
@ -2396,6 +2397,26 @@ public partial class PInvokeGenerator
Offset = parent.IsUnion ? 0 : null, Offset = parent.IsUnion ? 0 : null,
NeedsNewKeyword = false, NeedsNewKeyword = false,
Location = fieldDecl.Location, Location = fieldDecl.Location,
WriteCustomAttrs = static context => {
(var bitfieldDesc, var generator) = ((BitfieldDesc, PInvokeGenerator))context;
if (!generator.Config.GenerateNativeBitfieldAttribute)
{
return;
}
var outputBuilder = generator._outputBuilder;
Debug.Assert(outputBuilder is not null);
foreach (var bitfieldRegion in bitfieldDesc.Regions)
{
outputBuilder.WriteCustomAttribute($"NativeBitfield(\"{bitfieldRegion.Name}\", offset: {bitfieldRegion.Offset}, length: {bitfieldRegion.Length})");
}
var namespaceName = generator.GetNamespace("NativeBitfieldAttribute");
generator.AddUsingDirective(outputBuilder, namespaceName);
},
CustomAttrGeneratorData = (bitfieldDesc, this),
}; };
_outputBuilder.BeginField(in fieldDesc); _outputBuilder.BeginField(in fieldDesc);
_outputBuilder.WriteRegularField(typeNameBacking, bitfieldName); _outputBuilder.WriteRegularField(typeNameBacking, bitfieldName);
@ -2416,7 +2437,7 @@ public partial class PInvokeGenerator
bitfieldName += index.ToString(); bitfieldName += index.ToString();
} }
typeBacking = (index > 0) ? types[index - 1] : types[0]; typeBacking = (index > 0) ? bitfieldDescs[index - 1].TypeBacking : bitfieldDescs[0].TypeBacking;
typeNameBacking = GetRemappedTypeName(fieldDecl, context: null, typeBacking, out _); typeNameBacking = GetRemappedTypeName(fieldDecl, context: null, typeBacking, out _);
} }

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

@ -7,7 +7,6 @@ using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ClangSharp.Abstractions; using ClangSharp.Abstractions;
@ -18,7 +17,6 @@ using static ClangSharp.Interop.CX_AttrKind;
using static ClangSharp.Interop.CX_BinaryOperatorKind; using static ClangSharp.Interop.CX_BinaryOperatorKind;
using static ClangSharp.Interop.CX_CXXAccessSpecifier; using static ClangSharp.Interop.CX_CXXAccessSpecifier;
using static ClangSharp.Interop.CX_StmtClass; using static ClangSharp.Interop.CX_StmtClass;
using static ClangSharp.Interop.CX_TypeClass;
using static ClangSharp.Interop.CX_UnaryExprOrTypeTrait; using static ClangSharp.Interop.CX_UnaryExprOrTypeTrait;
using static ClangSharp.Interop.CX_UnaryOperatorKind; using static ClangSharp.Interop.CX_UnaryOperatorKind;
using static ClangSharp.Interop.CXCallingConv; using static ClangSharp.Interop.CXCallingConv;
@ -327,6 +325,7 @@ public sealed partial class PInvokeGenerator : IDisposable
Debug.Assert(leaveStreamOpen is true); Debug.Assert(leaveStreamOpen is true);
} }
GenerateNativeBitfieldAttribute(this, stream, leaveStreamOpen);
GenerateNativeInheritanceAttribute(this, stream, leaveStreamOpen); GenerateNativeInheritanceAttribute(this, stream, leaveStreamOpen);
GenerateNativeTypeNameAttribute(this, stream, leaveStreamOpen); GenerateNativeTypeNameAttribute(this, stream, leaveStreamOpen);
GenerateSetsLastSystemErrorAttribute(this, stream, leaveStreamOpen); GenerateSetsLastSystemErrorAttribute(this, stream, leaveStreamOpen);
@ -373,10 +372,119 @@ public sealed partial class PInvokeGenerator : IDisposable
_uuidsToGenerate.Clear(); _uuidsToGenerate.Clear();
_visitedFiles.Clear(); _visitedFiles.Clear();
static void GenerateNativeBitfieldAttribute(PInvokeGenerator generator, Stream? stream, bool leaveStreamOpen)
{
var config = generator.Config;
if (!config.GenerateNativeBitfieldAttribute)
{
return;
}
if (stream is null)
{
var outputPath = Path.Combine(config.OutputLocation, "NativeBitfieldAttribute.cs");
stream = generator._outputStreamFactory(outputPath);
}
using var sw = new StreamWriter(stream, s_defaultStreamWriterEncoding, DefaultStreamWriterBufferSize, leaveStreamOpen);
sw.NewLine = "\n";
if (config.HeaderText != string.Empty)
{
sw.WriteLine(config.HeaderText);
}
var indentString = " ";
sw.WriteLine("using System;");
sw.WriteLine("using System.Diagnostics;");
sw.WriteLine();
sw.Write("namespace ");
sw.Write(generator.GetNamespace("NativeBitfieldAttribute"));
if (generator.Config.GenerateFileScopedNamespaces)
{
sw.WriteLine(';');
sw.WriteLine();
indentString = "";
}
else
{
sw.WriteLine();
sw.WriteLine('{');
}
sw.Write(indentString);
sw.WriteLine("/// <summary>Defines the layout of a bitfield as it was used in the native signature.</summary>");
sw.Write(indentString);
sw.WriteLine("[AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = true)]");
sw.Write(indentString);
sw.WriteLine("[Conditional(\"DEBUG\")]");
sw.Write(indentString);
sw.WriteLine("internal sealed partial class NativeBitfieldAttribute : Attribute");
sw.Write(indentString);
sw.WriteLine('{');
sw.Write(indentString);
sw.WriteLine(" private readonly string _name;");
sw.WriteLine(" private readonly int _offset;");
sw.WriteLine(" private readonly int _length;");
sw.WriteLine();
sw.Write(indentString);
sw.WriteLine(" /// <summary>Initializes a new instance of the <see cref=\"NativeBitfieldAttribute\" /> class.</summary>");
sw.Write(indentString);
sw.WriteLine(" /// <param name=\"name\">The name of the bitfield that was used in the native signature.</param>");
sw.WriteLine(" /// <param name=\"offset\">The offset of the bitfield that was used in the native signature.</param>");
sw.WriteLine(" /// <param name=\"length\">The length of the bitfield that was used in the native signature.</param>");
sw.Write(indentString);
sw.WriteLine(" public NativeTypeNameAttribute(string name, int offset, int length)");
sw.Write(indentString);
sw.WriteLine(" {");
sw.Write(indentString);
sw.WriteLine(" _name = name;");
sw.WriteLine(" _offset = offset;");
sw.WriteLine(" _length = length;");
sw.Write(indentString);
sw.WriteLine(" }");
sw.WriteLine();
sw.Write(indentString);
sw.WriteLine(" /// <summary>Gets the length of the bitfield that was used in the native signature.</summary>");
sw.Write(indentString);
sw.WriteLine(" public int Length => _length;");
sw.WriteLine();
sw.Write(indentString);
sw.WriteLine(" /// <summary>Gets the name of the bitfield that was used in the native signature.</summary>");
sw.Write(indentString);
sw.WriteLine(" public string Name => _name;");
sw.WriteLine();
sw.Write(indentString);
sw.WriteLine(" /// <summary>Gets the offset of the bitfield that was used in the native signature.</summary>");
sw.Write(indentString);
sw.WriteLine(" public int Offset => _offset;");
sw.Write(indentString);
sw.WriteLine('}');
if (!generator.Config.GenerateFileScopedNamespaces)
{
sw.WriteLine('}');
}
if (!leaveStreamOpen)
{
stream = null;
}
}
static void GenerateNativeInheritanceAttribute(PInvokeGenerator generator, Stream? stream, bool leaveStreamOpen) static void GenerateNativeInheritanceAttribute(PInvokeGenerator generator, Stream? stream, bool leaveStreamOpen)
{ {
var config = generator.Config; var config = generator.Config;
if (!config.GenerateNativeInheritanceAttribute)
{
return;
}
if (stream is null) if (stream is null)
{ {
var outputPath = Path.Combine(config.OutputLocation, "NativeInheritanceAttribute.cs"); var outputPath = Path.Combine(config.OutputLocation, "NativeInheritanceAttribute.cs");
@ -543,6 +651,11 @@ public sealed partial class PInvokeGenerator : IDisposable
{ {
var config = generator.Config; var config = generator.Config;
if (!config.GenerateSetsLastSystemErrorAttribute)
{
return;
}
if (stream is null) if (stream is null)
{ {
Debug.Assert(stream is null); Debug.Assert(stream is null);
@ -616,6 +729,11 @@ public sealed partial class PInvokeGenerator : IDisposable
{ {
var config = generator.Config; var config = generator.Config;
if (!config.GenerateVtblIndexAttribute)
{
return;
}
if (stream is null) if (stream is null)
{ {
Debug.Assert(stream is null); Debug.Assert(stream is null);
@ -1527,6 +1645,33 @@ public sealed partial class PInvokeGenerator : IDisposable
_diagnostics.Add(diagnostic); _diagnostics.Add(diagnostic);
} }
private void AddUsingDirective(IOutputBuilder? outputBuilder, string namespaceName)
{
if (outputBuilder is null)
{
return;
}
var needsUsing = false;
if (_currentNamespace is not null)
{
if (!_currentNamespace.StartsWith(namespaceName))
{
needsUsing = true;
}
else if ((_currentNamespace.Length > namespaceName.Length) && (_currentNamespace[namespaceName.Length] != '.'))
{
needsUsing = true;
}
}
if (needsUsing)
{
outputBuilder.EmitUsingDirective(namespaceName);
}
}
private void CloseOutputBuilder(Stream stream, IOutputBuilder outputBuilder, bool isMethodClass, bool leaveStreamOpen, bool emitNamespaceDeclaration) private void CloseOutputBuilder(Stream stream, IOutputBuilder outputBuilder, bool isMethodClass, bool leaveStreamOpen, bool emitNamespaceDeclaration)
{ {
if (stream is null) if (stream is null)
@ -2023,13 +2168,14 @@ public sealed partial class PInvokeGenerator : IDisposable
return $"_{name}_e__FixedBuffer"; return $"_{name}_e__FixedBuffer";
} }
private Type[] GetBitfieldCount(RecordDecl recordDecl) private BitfieldDesc[] GetBitfieldDescs(RecordDecl recordDecl)
{ {
var types = new List<Type>(recordDecl.Fields.Count); var bitfieldDescs = new List<BitfieldDesc>(recordDecl.Fields.Count);
var count = 0; var backingFieldIndex = -1;
var previousSize = 0L; var previousSize = 0L;
var remainingBits = 0L; var remainingBits = 0L;
var currentBits = 0L;
foreach (var fieldDecl in recordDecl.Fields) foreach (var fieldDecl in recordDecl.Fields)
{ {
@ -2044,8 +2190,9 @@ public sealed partial class PInvokeGenerator : IDisposable
if ((!_config.GenerateUnixTypes && (currentSize != previousSize)) || (fieldDecl.BitWidthValue > remainingBits)) if ((!_config.GenerateUnixTypes && (currentSize != previousSize)) || (fieldDecl.BitWidthValue > remainingBits))
{ {
count++; backingFieldIndex++;
remainingBits = currentSize * 8; currentBits = currentSize * 8;
remainingBits = currentBits;
previousSize = 0; previousSize = 0;
var type = fieldDecl.Type; var type = fieldDecl.Type;
@ -2055,27 +2202,53 @@ public sealed partial class PInvokeGenerator : IDisposable
type = enumType.Decl.IntegerType; type = enumType.Decl.IntegerType;
} }
types.Add(type); var bitfieldDesc = new BitfieldDesc {
TypeBacking = type,
Regions = new List<BitfieldRegion>() {
new BitfieldRegion {
Name = GetRemappedCursorName(fieldDecl),
Offset = 0,
Length = fieldDecl.BitWidthValue
},
}
};
bitfieldDescs.Add(bitfieldDesc);
} }
else if (_config.GenerateUnixTypes && (currentSize > previousSize)) else
{ {
remainingBits += (currentSize - previousSize) * 8; var bitfieldDesc = bitfieldDescs[^1];
var type = fieldDecl.Type; if (_config.GenerateUnixTypes && (currentSize > previousSize))
if (IsType<EnumType>(fieldDecl, type, out var enumType))
{ {
type = enumType.Decl.IntegerType; remainingBits += (currentSize - previousSize) * 8;
currentBits += (currentSize - previousSize) * 8;
var type = fieldDecl.Type;
if (IsType<EnumType>(fieldDecl, type, out var enumType))
{
type = enumType.Decl.IntegerType;
}
bitfieldDescs[^1] = new BitfieldDesc {
TypeBacking = type,
Regions = bitfieldDesc.Regions,
};
} }
types[^1] = type; var bitfieldRegion = new BitfieldRegion {
Name = GetRemappedCursorName(fieldDecl),
Offset = currentBits - remainingBits,
Length = fieldDecl.BitWidthValue
};
bitfieldDesc.Regions.Add(bitfieldRegion);
} }
remainingBits -= fieldDecl.BitWidthValue; remainingBits -= fieldDecl.BitWidthValue;
previousSize = Math.Max(previousSize, currentSize); previousSize = Math.Max(previousSize, currentSize);
} }
return types.ToArray(); return bitfieldDescs.ToArray();
} }
private CallingConvention GetCallingConvention(Cursor? cursor, Cursor? context, Type type) private CallingConvention GetCallingConvention(Cursor? cursor, Cursor? context, Type type)
@ -2688,24 +2861,7 @@ public sealed partial class PInvokeGenerator : IDisposable
} }
var namespaceName = GetNamespace(remappedName); var namespaceName = GetNamespace(remappedName);
var needsUsing = false; AddUsingDirective(outputBuilder, namespaceName);
if (_currentNamespace is not null)
{
if (!_currentNamespace.StartsWith(namespaceName))
{
needsUsing = true;
}
else if ((_currentNamespace.Length > namespaceName.Length) && (_currentNamespace[namespaceName.Length] != '.'))
{
needsUsing = true;
}
}
if (needsUsing)
{
outputBuilder?.EmitUsingDirective(namespaceName);
}
} }
return remappedName; return remappedName;

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

@ -228,6 +228,8 @@ public sealed class PInvokeGeneratorConfiguration
public bool GenerateMultipleFiles => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateMultipleFiles); public bool GenerateMultipleFiles => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateMultipleFiles);
public bool GenerateNativeBitfieldAttribute => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
public bool GenerateNativeInheritanceAttribute => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute); public bool GenerateNativeInheritanceAttribute => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute);
public bool GeneratePreviewCode => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GeneratePreviewCode); public bool GeneratePreviewCode => _options.HasFlag(PInvokeGeneratorConfigurationOptions.GeneratePreviewCode);

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

@ -78,4 +78,6 @@ public enum PInvokeGeneratorConfigurationOptions : ulong
GenerateGuidMember = 1UL << 33, GenerateGuidMember = 1UL << 33,
GenerateLatestCode = 1UL << 34, GenerateLatestCode = 1UL << 34,
GenerateNativeBitfieldAttribute = 1UL << 35,
} }

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

@ -26,7 +26,7 @@ public class Program
private static readonly RootCommand s_rootCommand; private static readonly RootCommand s_rootCommand;
private static readonly Option<bool> s_versionOption; private static readonly Option<bool> s_versionOption;
private static readonly Option<string[]> s_addtionalOption; private static readonly Option<string[]> s_additionalOption;
private static readonly Option<string[]> s_configOption; private static readonly Option<string[]> s_configOption;
private static readonly Option<string[]> s_defineMacros; private static readonly Option<string[]> s_defineMacros;
private static readonly Option<string[]> s_excludedNames; private static readonly Option<string[]> s_excludedNames;
@ -116,6 +116,7 @@ public class Program
new TwoColumnHelpRow("generate-helper-types", "Code files should be generated for various helper attributes and declared transparent structs."), new TwoColumnHelpRow("generate-helper-types", "Code files should be generated for various helper attributes and declared transparent structs."),
new TwoColumnHelpRow("generate-macro-bindings", "Bindings for macro-definitions should be generated. This currently only works with value like macros and not function-like ones."), new TwoColumnHelpRow("generate-macro-bindings", "Bindings for macro-definitions should be generated. This currently only works with value like macros and not function-like ones."),
new TwoColumnHelpRow("generate-marker-interfaces", "Bindings for marker interfaces representing native inheritance hierarchies should be generated."), new TwoColumnHelpRow("generate-marker-interfaces", "Bindings for marker interfaces representing native inheritance hierarchies should be generated."),
new TwoColumnHelpRow("generate-native-bitfield-attribute", "[NativeBitfield(\"\", offset: #, length: #)] attribute should be generated to document the encountered bitfield layout."),
new TwoColumnHelpRow("generate-native-inheritance-attribute", "[NativeInheritance(\"\")] attribute should be generated to document the encountered C++ base type."), new TwoColumnHelpRow("generate-native-inheritance-attribute", "[NativeInheritance(\"\")] attribute should be generated to document the encountered C++ base type."),
new TwoColumnHelpRow("generate-setslastsystemerror-attribute", "[SetsLastSystemError] attribute should be generated rather than using SetLastError = true."), new TwoColumnHelpRow("generate-setslastsystemerror-attribute", "[SetsLastSystemError] attribute should be generated rather than using SetLastError = true."),
new TwoColumnHelpRow("generate-template-bindings", "Bindings for template-definitions should be generated. This is currently experimental."), new TwoColumnHelpRow("generate-template-bindings", "Bindings for template-definitions should be generated. This is currently experimental."),
@ -131,7 +132,7 @@ public class Program
static Program() static Program()
{ {
s_addtionalOption = GetAdditionalOption(); s_additionalOption = GetAdditionalOption();
s_configOption = GetConfigOption(); s_configOption = GetConfigOption();
s_defineMacros = GetDefineMacroOption(); s_defineMacros = GetDefineMacroOption();
s_excludedNames = GetExcludeOption(); s_excludedNames = GetExcludeOption();
@ -170,7 +171,7 @@ public class Program
s_rootCommand = new RootCommand("ClangSharp P/Invoke Binding Generator") s_rootCommand = new RootCommand("ClangSharp P/Invoke Binding Generator")
{ {
s_addtionalOption, s_additionalOption,
s_configOption, s_configOption,
s_defineMacros, s_defineMacros,
s_excludedNames, s_excludedNames,
@ -241,7 +242,7 @@ public class Program
public static void Run(InvocationContext context) public static void Run(InvocationContext context)
{ {
var additionalArgs = context.ParseResult.GetValueForOption(s_addtionalOption) ?? Array.Empty<string>(); var additionalArgs = context.ParseResult.GetValueForOption(s_additionalOption) ?? Array.Empty<string>();
var configSwitches = context.ParseResult.GetValueForOption(s_configOption) ?? Array.Empty<string>(); var configSwitches = context.ParseResult.GetValueForOption(s_configOption) ?? Array.Empty<string>();
var defineMacros = context.ParseResult.GetValueForOption(s_defineMacros) ?? Array.Empty<string>(); var defineMacros = context.ParseResult.GetValueForOption(s_defineMacros) ?? Array.Empty<string>();
var excludedNames = context.ParseResult.GetValueForOption(s_excludedNames) ?? Array.Empty<string>(); var excludedNames = context.ParseResult.GetValueForOption(s_excludedNames) ?? Array.Empty<string>();
@ -563,6 +564,12 @@ public class Program
break; break;
} }
case "generate-native-bitfield-attribute":
{
configOptions |= PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute;
break;
}
case "generate-native-inheritance-attribute": case "generate-native-inheritance-attribute":
{ {
configOptions |= PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute; configOptions |= PInvokeGeneratorConfigurationOptions.GenerateNativeInheritanceAttribute;

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

@ -37,6 +37,9 @@ public abstract class StructDeclarationTest : PInvokeGeneratorTest
[Test] [Test]
public Task BitfieldTest() => BitfieldTestImpl(); public Task BitfieldTest() => BitfieldTestImpl();
[Test]
public Task BitfieldWithNativeBitfieldAttributeTest() => BitfieldWithNativeBitfieldAttributeTestImpl();
[Test] [Test]
public Task DeclTypeTest() => DeclTypeTestImpl(); public Task DeclTypeTest() => DeclTypeTestImpl();
@ -222,6 +225,8 @@ public abstract class StructDeclarationTest : PInvokeGeneratorTest
protected abstract Task BitfieldTestImpl(); protected abstract Task BitfieldTestImpl();
protected abstract Task BitfieldWithNativeBitfieldAttributeTestImpl();
protected abstract Task DeclTypeTestImpl(); protected abstract Task DeclTypeTestImpl();
protected abstract Task ExcludeTestImpl(); protected abstract Task ExcludeTestImpl();

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

@ -320,6 +320,226 @@ struct MyStruct3
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
[NativeBitfield(""o4_b22_1"", offset: 22, length: 1)]
[NativeBitfield(""o4_b23_1"", offset: 23, length: 1)]
[NativeBitfield(""o4_b24_1"", offset: 24, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeTypeName(""unsigned char : 1"")]
public byte o4_b22_1
{
get
{
return (byte)((_bitfield2 >> 22) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 22)) | (uint)((value & 0x1u) << 22);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b23_1
{
get
{
return (int)((_bitfield2 >> 23) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 23)) | (uint)((value & 0x1) << 23);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b24_1
{
get
{
return (int)((_bitfield2 >> 24) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 24)) | (uint)((value & 0x1) << 24);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -324,6 +324,230 @@ struct MyStruct3
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public byte _bitfield3;
[NativeTypeName(""unsigned char : 1"")]
public byte o8_b0_1
{
get
{
return (byte)(_bitfield3 & 0x1u);
}
set
{
_bitfield3 = (byte)((_bitfield3 & ~0x1u) | (value & 0x1u));
}
}
[NativeBitfield(""o12_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o12_b1_1"", offset: 1, length: 1)]
public int _bitfield4;
[NativeTypeName(""int : 1"")]
public int o12_b0_1
{
get
{
return _bitfield4 & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~0x1) | (value & 0x1);
}
}
[NativeTypeName(""int : 1"")]
public int o12_b1_1
{
get
{
return (_bitfield4 >> 1) & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~(0x1 << 1)) | ((value & 0x1) << 1);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -320,6 +320,226 @@ struct MyStruct3
return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
[NativeBitfield(""o4_b22_1"", offset: 22, length: 1)]
[NativeBitfield(""o4_b23_1"", offset: 23, length: 1)]
[NativeBitfield(""o4_b24_1"", offset: 24, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeTypeName(""unsigned char : 1"")]
public byte o4_b22_1
{
get
{
return (byte)((_bitfield2 >> 22) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 22)) | (uint)((value & 0x1u) << 22);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b23_1
{
get
{
return (int)((_bitfield2 >> 23) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 23)) | (uint)((value & 0x1) << 23);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b24_1
{
get
{
return (int)((_bitfield2 >> 24) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 24)) | (uint)((value & 0x1) << 24);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -324,6 +324,230 @@ struct MyStruct3
return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public byte _bitfield3;
[NativeTypeName(""unsigned char : 1"")]
public byte o8_b0_1
{
get
{
return (byte)(_bitfield3 & 0x1u);
}
set
{
_bitfield3 = (byte)((_bitfield3 & ~0x1u) | (value & 0x1u));
}
}
[NativeBitfield(""o12_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o12_b1_1"", offset: 1, length: 1)]
public int _bitfield4;
[NativeTypeName(""int : 1"")]
public int o12_b0_1
{
get
{
return _bitfield4 & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~0x1) | (value & 0x1);
}
}
[NativeTypeName(""int : 1"")]
public int o12_b1_1
{
get
{
return (_bitfield4 >> 1) & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~(0x1 << 1)) | ((value & 0x1) << 1);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -320,6 +320,226 @@ struct MyStruct3
return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
[NativeBitfield(""o4_b22_1"", offset: 22, length: 1)]
[NativeBitfield(""o4_b23_1"", offset: 23, length: 1)]
[NativeBitfield(""o4_b24_1"", offset: 24, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeTypeName(""unsigned char : 1"")]
public byte o4_b22_1
{
get
{
return (byte)((_bitfield2 >> 22) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 22)) | (uint)((value & 0x1u) << 22);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b23_1
{
get
{
return (int)((_bitfield2 >> 23) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 23)) | (uint)((value & 0x1) << 23);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b24_1
{
get
{
return (int)((_bitfield2 >> 24) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 24)) | (uint)((value & 0x1) << 24);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -324,6 +324,230 @@ struct MyStruct3
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public byte _bitfield3;
[NativeTypeName(""unsigned char : 1"")]
public byte o8_b0_1
{
get
{
return (byte)(_bitfield3 & 0x1u);
}
set
{
_bitfield3 = (byte)((_bitfield3 & ~0x1u) | (value & 0x1u));
}
}
[NativeBitfield(""o12_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o12_b1_1"", offset: 1, length: 1)]
public int _bitfield4;
[NativeTypeName(""int : 1"")]
public int o12_b0_1
{
get
{
return _bitfield4 & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~0x1) | (value & 0x1);
}
}
[NativeTypeName(""int : 1"")]
public int o12_b1_1
{
get
{
return (_bitfield4 >> 1) & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~(0x1 << 1)) | ((value & 0x1) << 1);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -320,6 +320,226 @@ struct MyStruct3
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
[NativeBitfield(""o4_b22_1"", offset: 22, length: 1)]
[NativeBitfield(""o4_b23_1"", offset: 23, length: 1)]
[NativeBitfield(""o4_b24_1"", offset: 24, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeTypeName(""unsigned char : 1"")]
public byte o4_b22_1
{
get
{
return (byte)((_bitfield2 >> 22) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 22)) | (uint)((value & 0x1u) << 22);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b23_1
{
get
{
return (int)((_bitfield2 >> 23) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 23)) | (uint)((value & 0x1) << 23);
}
}
[NativeTypeName(""int : 1"")]
public int o4_b24_1
{
get
{
return (int)((_bitfield2 >> 24) & 0x1u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x1u << 24)) | (uint)((value & 0x1) << 24);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpPreviewUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -324,6 +324,230 @@ struct MyStruct3
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"namespace ClangSharp.Test
{
public partial struct MyStruct1
{
[NativeBitfield(""o0_b0_24"", offset: 0, length: 24)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 24"")]
public uint o0_b0_24
{
get
{
return _bitfield1 & 0xFFFFFFu;
}
set
{
_bitfield1 = (_bitfield1 & ~0xFFFFFFu) | (value & 0xFFFFFFu);
}
}
[NativeBitfield(""o4_b0_16"", offset: 0, length: 16)]
[NativeBitfield(""o4_b16_3"", offset: 16, length: 3)]
[NativeBitfield(""o4_b19_3"", offset: 19, length: 3)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 16"")]
public uint o4_b0_16
{
get
{
return _bitfield2 & 0xFFFFu;
}
set
{
_bitfield2 = (_bitfield2 & ~0xFFFFu) | (value & 0xFFFFu);
}
}
[NativeTypeName(""unsigned int : 3"")]
public uint o4_b16_3
{
get
{
return (_bitfield2 >> 16) & 0x7u;
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 16)) | ((value & 0x7u) << 16);
}
}
[NativeTypeName(""int : 3"")]
public int o4_b19_3
{
get
{
return (int)((_bitfield2 >> 19) & 0x7u);
}
set
{
_bitfield2 = (_bitfield2 & ~(0x7u << 19)) | (uint)((value & 0x7) << 19);
}
}
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public byte _bitfield3;
[NativeTypeName(""unsigned char : 1"")]
public byte o8_b0_1
{
get
{
return (byte)(_bitfield3 & 0x1u);
}
set
{
_bitfield3 = (byte)((_bitfield3 & ~0x1u) | (value & 0x1u));
}
}
[NativeBitfield(""o12_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o12_b1_1"", offset: 1, length: 1)]
public int _bitfield4;
[NativeTypeName(""int : 1"")]
public int o12_b0_1
{
get
{
return _bitfield4 & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~0x1) | (value & 0x1);
}
}
[NativeTypeName(""int : 1"")]
public int o12_b1_1
{
get
{
return (_bitfield4 >> 1) & 0x1;
}
set
{
_bitfield4 = (_bitfield4 & ~(0x1 << 1)) | ((value & 0x1) << 1);
}
}
}
public partial struct MyStruct2
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
public uint _bitfield1;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield1 & 0x1u;
}
set
{
_bitfield1 = (_bitfield1 & ~0x1u) | (value & 0x1u);
}
}
public int x;
[NativeBitfield(""o8_b0_1"", offset: 0, length: 1)]
public uint _bitfield2;
[NativeTypeName(""unsigned int : 1"")]
public uint o8_b0_1
{
get
{
return _bitfield2 & 0x1u;
}
set
{
_bitfield2 = (_bitfield2 & ~0x1u) | (value & 0x1u);
}
}
}
public partial struct MyStruct3
{
[NativeBitfield(""o0_b0_1"", offset: 0, length: 1)]
[NativeBitfield(""o0_b1_1"", offset: 1, length: 1)]
public uint _bitfield;
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b0_1
{
get
{
return _bitfield & 0x1u;
}
set
{
_bitfield = (_bitfield & ~0x1u) | (value & 0x1u);
}
}
[NativeTypeName(""unsigned int : 1"")]
public uint o0_b1_1
{
get
{
return (_bitfield >> 1) & 0x1u;
}
set
{
_bitfield = (_bitfield & ~(0x1u << 1)) | ((value & 0x1u) << 1);
}
}
}
}
";
return ValidateGeneratedCSharpPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -133,9 +133,9 @@ public sealed class XmlCompatibleUnix_StructDeclarationTest : StructDeclarationT
unsigned int o4_b0_16 : 16; unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3; unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3; int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1; unsigned char o4_b22_1 : 1;
int o12_b0_1 : 1; int o4_b23_1 : 1;
int o12_b1_1 : 1; int o4_b24_1 : 1;
}; };
struct MyStruct2 struct MyStruct2
@ -202,7 +202,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set> </set>
</field> </field>
<field name=""o8_b0_1"" access=""public""> <field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type> <type native=""unsigned char : 1"">byte</type>
<get> <get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -212,7 +212,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set> </set>
</field> </field>
<field name=""o12_b0_1"" access=""public""> <field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -222,7 +222,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set> </set>
</field> </field>
<field name=""o12_b1_1"" access=""public""> <field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -296,6 +296,188 @@ struct MyStruct3
return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b22_1"", offset: 22, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b23_1"", offset: 23, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b24_1"", offset: 24, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set>
</field>
<field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set>
</field>
<field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>24</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 24);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlCompatibleUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -302,6 +302,194 @@ struct MyStruct3
return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""_bitfield3"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>byte</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)(<bitfieldName>_bitfield3</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield3</bitfieldName> = (<typeNameBacking>byte</typeNameBacking>)((_bitfield3 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>));</code>
</set>
</field>
<field name=""_bitfield4"" access=""public"">
<attribute>NativeBitfield(""o12_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o12_b1_1"", offset: 1, length: 1)</attribute>
<type>int</type>
</field>
<field name=""o12_b0_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return <bitfieldName>_bitfield4</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1</bitwidthHexString>);</code>
</set>
</field>
<field name=""o12_b1_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<bitfieldName>_bitfield4</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~(0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlCompatibleWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -133,9 +133,9 @@ public sealed class XmlDefaultUnix_StructDeclarationTest : StructDeclarationTest
unsigned int o4_b0_16 : 16; unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3; unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3; int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1; unsigned char o4_b22_1 : 1;
int o12_b0_1 : 1; int o4_b23_1 : 1;
int o12_b1_1 : 1; int o4_b24_1 : 1;
}; };
struct MyStruct2 struct MyStruct2
@ -202,7 +202,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set> </set>
</field> </field>
<field name=""o8_b0_1"" access=""public""> <field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type> <type native=""unsigned char : 1"">byte</type>
<get> <get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -212,7 +212,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set> </set>
</field> </field>
<field name=""o12_b0_1"" access=""public""> <field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -222,7 +222,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set> </set>
</field> </field>
<field name=""o12_b1_1"" access=""public""> <field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -296,6 +296,188 @@ struct MyStruct3
return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b22_1"", offset: 22, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b23_1"", offset: 23, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b24_1"", offset: 24, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set>
</field>
<field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set>
</field>
<field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>24</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 24);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlDefaultUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -302,6 +302,194 @@ struct MyStruct3
return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""_bitfield3"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>byte</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)(<bitfieldName>_bitfield3</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield3</bitfieldName> = (<typeNameBacking>byte</typeNameBacking>)((_bitfield3 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>));</code>
</set>
</field>
<field name=""_bitfield4"" access=""public"">
<attribute>NativeBitfield(""o12_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o12_b1_1"", offset: 1, length: 1)</attribute>
<type>int</type>
</field>
<field name=""o12_b0_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return <bitfieldName>_bitfield4</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1</bitwidthHexString>);</code>
</set>
</field>
<field name=""o12_b1_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<bitfieldName>_bitfield4</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~(0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlDefaultWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -133,9 +133,9 @@ public sealed class XmlLatestUnix_StructDeclarationTest : StructDeclarationTest
unsigned int o4_b0_16 : 16; unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3; unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3; int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1; unsigned char o4_b22_1 : 1;
int o12_b0_1 : 1; int o4_b23_1 : 1;
int o12_b1_1 : 1; int o4_b24_1 : 1;
}; };
struct MyStruct2 struct MyStruct2
@ -202,7 +202,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set> </set>
</field> </field>
<field name=""o8_b0_1"" access=""public""> <field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type> <type native=""unsigned char : 1"">byte</type>
<get> <get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -212,7 +212,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set> </set>
</field> </field>
<field name=""o12_b0_1"" access=""public""> <field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -222,7 +222,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set> </set>
</field> </field>
<field name=""o12_b1_1"" access=""public""> <field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -296,6 +296,188 @@ struct MyStruct3
return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b22_1"", offset: 22, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b23_1"", offset: 23, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b24_1"", offset: 24, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set>
</field>
<field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set>
</field>
<field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>24</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 24);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlLatestUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -302,6 +302,194 @@ struct MyStruct3
return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""_bitfield3"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>byte</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)(<bitfieldName>_bitfield3</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield3</bitfieldName> = (<typeNameBacking>byte</typeNameBacking>)((_bitfield3 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>));</code>
</set>
</field>
<field name=""_bitfield4"" access=""public"">
<attribute>NativeBitfield(""o12_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o12_b1_1"", offset: 1, length: 1)</attribute>
<type>int</type>
</field>
<field name=""o12_b0_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return <bitfieldName>_bitfield4</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1</bitwidthHexString>);</code>
</set>
</field>
<field name=""o12_b1_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<bitfieldName>_bitfield4</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~(0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlLatestWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -133,9 +133,9 @@ public sealed class XmlPreviewUnix_StructDeclarationTest : StructDeclarationTest
unsigned int o4_b0_16 : 16; unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3; unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3; int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1; unsigned char o4_b22_1 : 1;
int o12_b0_1 : 1; int o4_b23_1 : 1;
int o12_b1_1 : 1; int o4_b24_1 : 1;
}; };
struct MyStruct2 struct MyStruct2
@ -202,7 +202,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set> </set>
</field> </field>
<field name=""o8_b0_1"" access=""public""> <field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type> <type native=""unsigned char : 1"">byte</type>
<get> <get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -212,7 +212,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set> </set>
</field> </field>
<field name=""o12_b0_1"" access=""public""> <field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -222,7 +222,7 @@ struct MyStruct3
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code> <bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set> </set>
</field> </field>
<field name=""o12_b1_1"" access=""public""> <field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type> <type native=""int : 1"">int</type>
<get> <get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code> <code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
@ -296,6 +296,188 @@ struct MyStruct3
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o4_b22_1 : 1;
int o4_b23_1 : 1;
int o4_b24_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b22_1"", offset: 22, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b23_1"", offset: 23, length: 1)</attribute>
<attribute>NativeBitfield(""o4_b24_1"", offset: 24, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""o4_b22_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>22</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>22</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 22);</code>
</set>
</field>
<field name=""o4_b23_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>23</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>23</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 23);</code>
</set>
</field>
<field name=""o4_b24_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>24</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>24</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 24);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlPreviewUnixBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();

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

@ -302,6 +302,194 @@ struct MyStruct3
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents); return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents);
} }
protected override Task BitfieldWithNativeBitfieldAttributeTestImpl()
{
var inputContents = @"struct MyStruct1
{
unsigned int o0_b0_24 : 24;
unsigned int o4_b0_16 : 16;
unsigned int o4_b16_3 : 3;
int o4_b19_3 : 3;
unsigned char o8_b0_1 : 1;
int o12_b0_1 : 1;
int o12_b1_1 : 1;
};
struct MyStruct2
{
unsigned int o0_b0_1 : 1;
int x;
unsigned int o8_b0_1 : 1;
};
struct MyStruct3
{
unsigned int o0_b0_1 : 1;
unsigned int o0_b1_1 : 1;
};
";
var expectedOutputContents = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>
<bindings>
<namespace name=""ClangSharp.Test"">
<struct name=""MyStruct1"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_24"", offset: 0, length: 24)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_24"" access=""public"">
<type native=""unsigned int : 24"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>FFFFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o4_b0_16"", offset: 0, length: 16)</attribute>
<attribute>NativeBitfield(""o4_b16_3"", offset: 16, length: 3)</attribute>
<attribute>NativeBitfield(""o4_b19_3"", offset: 19, length: 3)</attribute>
<type>uint</type>
</field>
<field name=""o4_b0_16"" access=""public"">
<type native=""unsigned int : 16"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>FFFFu</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>FFFFu</bitwidthHexString>);</code>
</set>
</field>
<field name=""o4_b16_3"" access=""public"">
<type native=""unsigned int : 3"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>16</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>16</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>7u</bitwidthHexString>) &lt;&lt; 16);</code>
</set>
</field>
<field name=""o4_b19_3"" access=""public"">
<type native=""int : 3"">int</type>
<get>
<code>return (<typeName>int</typeName>)((<bitfieldName>_bitfield2</bitfieldName> &gt;&gt; <bitfieldOffset>19</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~(0x<bitwidthHexStringBacking>7u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>19</bitfieldOffset>)) | (uint)((value &amp; 0x<bitwidthHexString>7</bitwidthHexString>) &lt;&lt; 19);</code>
</set>
</field>
<field name=""_bitfield3"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>byte</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned char : 1"">byte</type>
<get>
<code>return (<typeName>byte</typeName>)(<bitfieldName>_bitfield3</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>);</code>
</get>
<set>
<code>
<bitfieldName>_bitfield3</bitfieldName> = (<typeNameBacking>byte</typeNameBacking>)((_bitfield3 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>));</code>
</set>
</field>
<field name=""_bitfield4"" access=""public"">
<attribute>NativeBitfield(""o12_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o12_b1_1"", offset: 1, length: 1)</attribute>
<type>int</type>
</field>
<field name=""o12_b0_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return <bitfieldName>_bitfield4</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1</bitwidthHexString>);</code>
</set>
</field>
<field name=""o12_b1_1"" access=""public"">
<type native=""int : 1"">int</type>
<get>
<code>return (<bitfieldName>_bitfield4</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield4</bitfieldName> = (_bitfield4 &amp; ~(0x<bitwidthHexStringBacking>1</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
<struct name=""MyStruct2"" access=""public"">
<field name=""_bitfield1"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield1</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield1</bitfieldName> = (_bitfield1 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""x"" access=""public"">
<type>int</type>
</field>
<field name=""_bitfield2"" access=""public"">
<attribute>NativeBitfield(""o8_b0_1"", offset: 0, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o8_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield2</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield2</bitfieldName> = (_bitfield2 &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
</struct>
<struct name=""MyStruct3"" access=""public"">
<field name=""_bitfield"" access=""public"">
<attribute>NativeBitfield(""o0_b0_1"", offset: 0, length: 1)</attribute>
<attribute>NativeBitfield(""o0_b1_1"", offset: 1, length: 1)</attribute>
<type>uint</type>
</field>
<field name=""o0_b0_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return <bitfieldName>_bitfield</bitfieldName> &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>) | (value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>);</code>
</set>
</field>
<field name=""o0_b1_1"" access=""public"">
<type native=""unsigned int : 1"">uint</type>
<get>
<code>return (<bitfieldName>_bitfield</bitfieldName> &gt;&gt; <bitfieldOffset>1</bitfieldOffset>) &amp; 0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking>;</code>
</get>
<set>
<code>
<bitfieldName>_bitfield</bitfieldName> = (_bitfield &amp; ~(0x<bitwidthHexStringBacking>1u</bitwidthHexStringBacking> &lt;&lt; <bitfieldOffset>1</bitfieldOffset>)) | ((value &amp; 0x<bitwidthHexString>1u</bitwidthHexString>) &lt;&lt; 1);</code>
</set>
</field>
</struct>
</namespace>
</bindings>
";
return ValidateGeneratedXmlPreviewWindowsBindingsAsync(inputContents, expectedOutputContents, PInvokeGeneratorConfigurationOptions.GenerateNativeBitfieldAttribute);
}
protected override Task DeclTypeTestImpl() protected override Task DeclTypeTestImpl()
{ {
var inputContents = @"extern ""C"" void MyFunction(); var inputContents = @"extern ""C"" void MyFunction();