Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,15 @@ private void VisitRecordDecl(RecordDecl recordDecl)
var className = GetClass(uuidName);

_testOutputBuilder.AddUsingDirective("System");
_testOutputBuilder.AddUsingDirective($"static {GetNamespace(className)}.{className}");

if (_config.DontUseUsingStaticsForGuidMember)
{
_testOutputBuilder.AddUsingDirective($"{GetNamespace(className)}");
}
else
{
_testOutputBuilder.AddUsingDirective($"static {GetNamespace(className)}.{className}");
}

_testOutputBuilder.WriteIndented("/// <summary>Validates that the <see cref=\"Guid\" /> of the <see cref=\"");
_testOutputBuilder.Write(escapedName);
Expand Down Expand Up @@ -1440,7 +1448,13 @@ private void VisitRecordDecl(RecordDecl recordDecl)
_testOutputBuilder.Write("Is.EqualTo(");
}

_testOutputBuilder.Write(uuidName);
var usableUuidName = uuidName;
if (_config.DontUseUsingStaticsForGuidMember)
{
usableUuidName = $"{className}.{usableUuidName}";
}

_testOutputBuilder.Write(usableUuidName);

if (_config.GenerateTestsNUnit)
{
Expand Down Expand Up @@ -1626,12 +1640,26 @@ private void VisitRecordDecl(RecordDecl recordDecl)
_outputBuilder.EmitUsingDirective("System");
_outputBuilder.EmitUsingDirective("System.Runtime.CompilerServices");

_outputBuilder.EmitUsingDirective($"static {GetNamespace(uuidClassName)}.{uuidClassName}");
if (_config.DontUseUsingStaticsForGuidMember)
{
_outputBuilder.EmitUsingDirective($"{GetNamespace(uuidClassName)}");
}
else
{
_outputBuilder.EmitUsingDirective($"static {GetNamespace(uuidClassName)}.{uuidClassName}");
}

var usableUuidName = uuidName;
if (_config.DontUseUsingStaticsForGuidMember)
{
usableUuidName = $"{uuidClassName}.{usableUuidName}";
}

_outputBuilder.BeginValue(in valueDesc);

var code = _outputBuilder.BeginCSharpCode();
code.Write("(Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in ");
code.Write(uuidName);
code.Write(usableUuidName);
code.Write("))");
_outputBuilder.EndCSharpCode(code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ public IReadOnlyCollection<string> ExcludedNames

public bool StripEnumMemberTypeName => _options.HasFlag(PInvokeGeneratorConfigurationOptions.StripEnumMemberTypeName);

public bool DontUseUsingStaticsForGuidMember => _options.HasFlag(PInvokeGeneratorConfigurationOptions.DontUseUsingStaticsForGuidMember);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some corresponding code in Program.cs of ClangSharpPInvokeGenerator that needs updating to actually set this flag (Silk.NET's ResponseFileHandler is a manually maintained subset of this Program.cs file)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed it


public string HeaderText => _headerText;

[AllowNull]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ public enum PInvokeGeneratorConfigurationOptions : long
GenerateGenericPointerWrapper = 1L << 38,

StripEnumMemberTypeName = 1L << 39,

DontUseUsingStaticsForGuidMember = 1L << 40,
}
7 changes: 7 additions & 0 deletions sources/ClangSharpPInvokeGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@ public static void Run(InvocationContext context)
break;
}

case "exclude-using-statics-for-guid-members":
case "dont-use-using-statics-for-guid-members":
{
configOptions |= PInvokeGeneratorConfigurationOptions.DontUseUsingStaticsForGuidMember;
break;
}

// VTBL Options

case "explicit-vtbls":
Expand Down