Skip to content

Commit b2cbb69

Browse files
committed
TransformInterfaces TransformCOM split
moved to internal Native struct INativeInterface and IComInterface added to represent all interfaces and Com interfaces, respectively. - IComInterface is a child of INativeInterface and INativeGuid
1 parent 0a5c7c5 commit b2cbb69

File tree

360 files changed

+4445
-1932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+4445
-1932
lines changed

generator.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Mods": [
99
"ClangScraper",
1010
"ChangeNamespace",
11+
"TransformInterfaces",
1112
"TransformCOM",
1213
"DisableWarnings"
1314
],
@@ -52,17 +53,29 @@
5253
"TerraFX.Interop(?!.Windows)(.*)": "Silk.NET$1"
5354
}
5455
},
56+
"TransformInterfaces": {
57+
"AdditionalInterfaces": [
58+
"IDispatchEx"
59+
]
60+
},
5561
"TransformCOM": {
5662
"BaseTypes": {
57-
"IUnknown.Interface": "Silk.NET.Win32.IUnknown.Interface"
63+
"IUnknown.Native.Interface": "Silk.NET.Win32.IUnknown.Native.Interface"
64+
},
65+
"AdditionalCOMTypes": {
66+
"IDispatchEx.Native.Interface": {
67+
"Namespace": "Silk.NET.Win32",
68+
"Parent": "IDispatch.Native.Interface"
69+
70+
}
5871
}
5972
},
6073
"DisableWarnings": {
6174
"WarningCodes": [
6275
"CS1589", //XML Comments missing (due to missing docs)
6376
"CS0419", //Inheritdoc issue (due to bug)
6477
"CA1416", //Function available outside of target os (intended)
65-
"CS0618" //Obsolete Warnings
78+
"CS0618" //Obsolete Warnings
6679
]
6780
}
6881
},

sources/Core/Core/IComInterface.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Core
5+
{
6+
/// <summary>
7+
/// A specialized native interface representing a ComType
8+
/// </summary>
9+
public interface IComInterface : INativeInterface, INativeGuid
10+
{
11+
}
12+
}

sources/Core/Core/INativeInterface.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Silk.NET.Core
5+
{
6+
/// <summary>
7+
/// Represents a native interface structure
8+
/// </summary>
9+
public unsafe interface INativeInterface
10+
{
11+
/// <summary>
12+
/// Gets the address of the pointer to the interface object address
13+
/// </summary>
14+
/// <typeparam name="TNativeInterface">The native interface object type</typeparam>
15+
/// <returns>pointer to interface object address </returns>
16+
TNativeInterface** GetAddressOf<TNativeInterface>() where TNativeInterface : unmanaged;
17+
/// <summary>
18+
/// Gets the address of the pointer to the interface object address
19+
/// </summary>
20+
/// <returns>pointer to interface object address </returns>
21+
void** GetAddressOf();
22+
}
23+
}

sources/Core/Core/PublicAPI/net8.0/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Silk.NET.Core.IBoolScheme
9191
Silk.NET.Core.IBoolScheme.False<T>() -> T
9292
Silk.NET.Core.IBoolScheme.IsTrue<T>(T value) -> bool
9393
Silk.NET.Core.IBoolScheme.True<T>() -> T
94+
Silk.NET.Core.IComInterface
9495
Silk.NET.Core.IGLContext
9596
Silk.NET.Core.IGLContext.IsCurrent.get -> bool
9697
Silk.NET.Core.IGLContext.IsCurrent.set -> void
@@ -105,6 +106,9 @@ Silk.NET.Core.INativeWindow
105106
Silk.NET.Core.INativeWindow.TryGetPlatformInfo<TPlatformInfo>(out TPlatformInfo? info) -> bool
106107
Silk.NET.Core.INativeGuid
107108
Silk.NET.Core.INativeGuid.NativeGuid.get -> System.Guid*
109+
Silk.NET.Core.INativeInterface
110+
Silk.NET.Core.INativeInterface.GetAddressOf() -> void**
111+
Silk.NET.Core.INativeInterface.GetAddressOf<TNativeInterface>() -> TNativeInterface**
108112
Silk.NET.Core.Loader.DefaultNativeContext
109113
Silk.NET.Core.Loader.DefaultNativeContext.DefaultNativeContext() -> void
110114
Silk.NET.Core.Loader.DefaultNativeContext.Dispose() -> void

sources/SilkTouch/SilkTouch/Clang/ClangScraper.cs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ out var handle
179179
CXDiagnostic_Warning => LogLevel.Warning,
180180
CXDiagnostic_Error => LogLevel.Error,
181181
CXDiagnostic_Fatal => LogLevel.Critical,
182-
_ => LogLevel.Trace
182+
_ => LogLevel.Trace,
183183
},
184184
" {0}",
185185
diagnostic.Format(CXDiagnostic.DefaultDisplayOptions).ToString()
@@ -202,7 +202,14 @@ out var handle
202202
using var translationUnit = TranslationUnit.GetOrCreate(handle);
203203
Debug.Assert(translationUnit is not null);
204204

205-
logger.LogInformation("Generating raw bindings for '{0}' ({1}/{2}) ({3}/{4})", fileName, index, count, rspIndex, rspCount);
205+
logger.LogInformation(
206+
"Generating raw bindings for '{0}' ({1}/{2}) ({3}/{4})",
207+
fileName,
208+
index,
209+
count,
210+
rspIndex,
211+
rspCount
212+
);
206213
pinvokeGenerator.GenerateBindings(
207214
translationUnit,
208215
filePath,
@@ -213,15 +220,14 @@ out var handle
213220

214221
if (files.Count == 0)
215222
{
216-
logger.LogWarning("No files generated for {0}",
217-
filePath);
223+
logger.LogWarning("No files generated for {0}", filePath);
218224
}
219225
else
220226
{
221227
logger.LogDebug(
222-
"Completed generation for {0}, file count: {1}",
223-
filePath,
224-
files.Count
228+
"Completed generation for {0}, file count: {1}",
229+
filePath,
230+
files.Count
225231
);
226232
}
227233
}
@@ -298,15 +304,19 @@ await Parallel.ForEachAsync(
298304
new ParallelOptions
299305
{
300306
CancellationToken = ct,
301-
MaxDegreeOfParallelism = parallelism
307+
MaxDegreeOfParallelism = parallelism,
302308
},
303309
async (rsp, innerCt) =>
304310
await Task.Run(
305311
async () =>
306312
{
307313
int index = Interlocked.Increment(ref rspIndex);
308314
// Generate the raw bindings.
309-
var (sources, tests, hasErrors) = ScrapeRawBindings(rsp, index, rspCount);
315+
var (sources, tests, hasErrors) = ScrapeRawBindings(
316+
rsp,
317+
index,
318+
rspCount
319+
);
310320

311321
static MemoryStream Reopen(MemoryStream ms) =>
312322
ms.TryGetBuffer(out var buff) && buff.Array is not null
@@ -334,8 +344,9 @@ static MemoryStream Reopen(MemoryStream ms) =>
334344
// Cache the output.
335345
//TODO: Refactor for better Parallelisation
336346
//Breaks with high concurrency
337-
string relativePath = $"{(isTest ? "tests" : "sources")}/{relativeKey}";
338-
if (cacheKey is not null && !hasErrors && cfg.CacheOutput)
347+
string relativePath =
348+
$"{(isTest ? "tests" : "sources")}/{relativeKey}";
349+
if (cacheKey is not null && !hasErrors && cfg.CacheOutput)
339350
{
340351
cacheDir ??= (
341352
await cacheProvider!.GetDirectory(
@@ -359,7 +370,7 @@ static MemoryStream Reopen(MemoryStream ms) =>
359370
logger.LogTrace("ClangSharp skipped {0}", relativePath);
360371
continue;
361372
}
362-
373+
363374
// Add it to the dictionary.
364375
if (
365376
!(isTest ? aggregatedTests : aggregatedSources).TryAdd(
@@ -471,7 +482,7 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
471482
// Others
472483
VisualStudioResolver.TryGetVisualStudioInfo(out _)
473484
? "vs"
474-
: "!vs"
485+
: "!vs",
475486
};
476487

477488
// Read the configuration.
@@ -486,19 +497,35 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
486497
var toRemoveMatcher = new Matcher();
487498
if (cfg.GeneratedToRemove is not null)
488499
{
489-
toRemoveMatcher.AddIncludePatterns(cfg.GeneratedToRemove.Where(toRemove => !toRemove.StartsWith("!")).Select(ResponseFileHandler.PathFixup));
490-
toRemoveMatcher.AddExcludePatterns(cfg.GeneratedToRemove.Where(toRemove => toRemove.StartsWith("!")).Select(toRemove => toRemove[1..]).Select(ResponseFileHandler.PathFixup));
500+
toRemoveMatcher.AddIncludePatterns(
501+
cfg.GeneratedToRemove.Where(toRemove => !toRemove.StartsWith("!"))
502+
.Select(ResponseFileHandler.PathFixup)
503+
);
504+
toRemoveMatcher.AddExcludePatterns(
505+
cfg.GeneratedToRemove.Where(toRemove => toRemove.StartsWith("!"))
506+
.Select(toRemove => toRemove[1..])
507+
.Select(ResponseFileHandler.PathFixup)
508+
);
491509
}
492510

493511
if (rsps.Count == 0)
494512
{
495513
logger.LogWarning("No Response files found for {}", ctx.JobKey);
496514
}
497515

498-
var missingIncludes = rsps.SelectMany<ResponseFile, string>(rsp => rsp.ClangCommandLineArgs.Where(arg => arg.StartsWith("--include-directory=") && !Directory.Exists(arg.Substring(20)))).Select(arg => arg.Substring(20)).Distinct();
516+
var missingIncludes = rsps.SelectMany<ResponseFile, string>(rsp =>
517+
rsp.ClangCommandLineArgs.Where(arg =>
518+
arg.StartsWith("--include-directory=") && !Directory.Exists(arg.Substring(20))
519+
)
520+
)
521+
.Select(arg => arg.Substring(20))
522+
.Distinct();
499523
if (missingIncludes.Count() > 0)
500524
{
501-
logger.LogWarning("The following includes are missing and may cause erroneous generation: \n" + string.Join("\n", missingIncludes));
525+
logger.LogWarning(
526+
"The following includes are missing and may cause erroneous generation: \n"
527+
+ string.Join("\n", missingIncludes)
528+
);
502529
}
503530

504531
// Apply modifications. This is done before the cache key as modifications to the rsps result in different

sources/SilkTouch/SilkTouch/Mods/Common/ModLoader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ModLoader
2929
nameof(ExtractNestedTyping) => typeof(ExtractNestedTyping),
3030
nameof(TransformProperties) => typeof(TransformProperties),
3131
nameof(ClangScraper) => typeof(ClangScraper),
32+
nameof(TransformInterfaces) => typeof(TransformInterfaces),
3233
nameof(TransformCOM) => typeof(TransformCOM),
3334
nameof(DisableWarnings) => typeof(DisableWarnings),
3435
_ => null,

sources/SilkTouch/SilkTouch/Mods/DisableWarnings.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.CodeAnalysis.CSharp.Syntax;
5-
using Microsoft.CodeAnalysis.CSharp;
4+
using Microsoft.Build.Evaluation;
65
using Microsoft.CodeAnalysis;
7-
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
6+
using Microsoft.CodeAnalysis.CSharp;
7+
using Microsoft.CodeAnalysis.CSharp.Syntax;
88
using Microsoft.Extensions.Options;
9-
using Microsoft.Build.Evaluation;
9+
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
1010

1111
namespace Silk.NET.SilkTouch.Mods
1212
{
@@ -15,8 +15,7 @@ namespace Silk.NET.SilkTouch.Mods
1515
/// </summary>
1616
/// <param name="config">The configuration to use.</param>
1717
[ModConfiguration<Configuration>]
18-
public class DisableWarnings(
19-
IOptionsSnapshot<DisableWarnings.Configuration> config) : Mod
18+
public class DisableWarnings(IOptionsSnapshot<DisableWarnings.Configuration> config) : Mod
2019
{
2120
/// <summary>
2221
/// The configuration for the <see cref="DisableWarnings"/> mod.
@@ -44,30 +43,38 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
4443

4544
// Create the pragma directive trivia
4645
var pragmaDirective = Trivia(
47-
PragmaWarningDirectiveTrivia(
48-
Token(SyntaxKind.DisableKeyword),
49-
true)
50-
.WithErrorCodes(
51-
SeparatedList<ExpressionSyntax>(
52-
cfg.WarningCodes.Select(warn => IdentifierName(warn)))));
46+
PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)
47+
.WithErrorCodes(
48+
SeparatedList<ExpressionSyntax>(
49+
cfg.WarningCodes.Select(warn => IdentifierName(warn))
50+
)
51+
)
52+
);
5353

5454
ctx.SourceProject = await DisableWarningsAsync(ctx.SourceProject, pragmaDirective, ct);
5555
ctx.TestProject = await DisableWarningsAsync(ctx.TestProject, pragmaDirective, ct);
5656
}
5757

58-
private async Task<Microsoft.CodeAnalysis.Project?> DisableWarningsAsync(Microsoft.CodeAnalysis.Project? proj, SyntaxTrivia pragmaDirective, CancellationToken ct)
58+
private async Task<Microsoft.CodeAnalysis.Project?> DisableWarningsAsync(
59+
Microsoft.CodeAnalysis.Project? proj,
60+
SyntaxTrivia pragmaDirective,
61+
CancellationToken ct
62+
)
5963
{
6064
foreach (var docId in proj?.DocumentIds ?? [])
6165
{
6266
var doc =
63-
proj?.GetDocument(docId) ?? throw new InvalidOperationException("Document missing");
67+
proj?.GetDocument(docId)
68+
?? throw new InvalidOperationException("Document missing");
6469
if (await doc.GetSyntaxRootAsync(ct) is not { } root)
6570
{
6671
continue;
6772
}
6873

6974
// Find the using directive
70-
SyntaxNode? namespaceNode = root.DescendantNodes().OfType<FileScopedNamespaceDeclarationSyntax>().FirstOrDefault();
75+
SyntaxNode? namespaceNode = root.DescendantNodes()
76+
.OfType<FileScopedNamespaceDeclarationSyntax>()
77+
.FirstOrDefault();
7178

7279
if (namespaceNode == null)
7380
{
@@ -79,7 +86,8 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
7986
var leadingTrivia = namespaceNode.GetLeadingTrivia();
8087

8188
// Insert the pragma directive after the comments
82-
var newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count, pragmaDirective)
89+
var newLeadingTrivia = leadingTrivia
90+
.Insert(leadingTrivia.Count, pragmaDirective)
8391
.Add(CarriageReturnLineFeed);
8492

8593
// Update the using directive with the new leading trivia

0 commit comments

Comments
 (0)