Skip to content

Commit 3d94412

Browse files
committed
Added casts + disabled blocking warnings
Fixed some manual warnings as well
1 parent b0efaf9 commit 3d94412

File tree

13 files changed

+553
-78
lines changed

13 files changed

+553
-78
lines changed

generator.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"Mods": [
99
"ClangScraper",
1010
"ChangeNamespace",
11-
"TransformCOM"
11+
"TransformCOM",
12+
"DisableWarnings"
1213
],
1314
"ClangScraper": {
1415
"ClangSharpResponseFiles": [
@@ -50,8 +51,15 @@
5051
}
5152
},
5253
"TransformCOM": {
53-
"BaseTypes": [
54-
"IUnknown.Interface"
54+
"BaseTypes": {
55+
"IUnknown.Interface": "Silk.NET.Windows.IUnknown.Interface"
56+
}
57+
},
58+
"DisableWarnings": {
59+
"WarningCodes": [
60+
"CS1589", //XML Comments missing (due to missing docs)
61+
"CS0419", //Inheritdoc issue (due to bug)
62+
"CA1416" //Function available outside of target os (intended)
5563
]
5664
}
5765
},

sources/SilkTouch/SilkTouch/Clang/ResponseFileHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.CommandLine;
44
using System.CommandLine.Parsing;
@@ -1204,7 +1204,7 @@ out Dictionary<string, string> withPackings
12041204

12051205
case "generate-doc-includes":
12061206
{
1207-
configOptions |= PInvokeGeneratorConfigurationOptions.GenerateDocIncludes;
1207+
//configOptions |= PInvokeGeneratorConfigurationOptions.GenerateDocIncludes;
12081208
break;
12091209
}
12101210

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ModLoader
3030
nameof(TransformProperties) => typeof(TransformProperties),
3131
nameof(ClangScraper) => typeof(ClangScraper),
3232
nameof(TransformCOM) => typeof(TransformCOM),
33+
nameof(DisableWarnings) => typeof(DisableWarnings),
3334
_ => null,
3435
};
3536
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
using Microsoft.CodeAnalysis.CSharp.Syntax;
5+
using Microsoft.CodeAnalysis.CSharp;
6+
using Microsoft.CodeAnalysis;
7+
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
8+
using Microsoft.CodeAnalysis.Editing;
9+
using Microsoft.Extensions.Logging;
10+
using Microsoft.Extensions.Options;
11+
using System.Reflection;
12+
using Silk.NET.SilkTouch.Utility;
13+
using Silk.NET.SilkTouch.Sources;
14+
15+
namespace Silk.NET.SilkTouch.Mods
16+
{
17+
/// <summary>
18+
/// A mod to Add warning disabling pragmas
19+
/// </summary>
20+
/// <param name="config">The configuration to use.</param>
21+
[ModConfiguration<Configuration>]
22+
public class DisableWarnings(
23+
IOptionsSnapshot<DisableWarnings.Configuration> config) : Mod
24+
{
25+
/// <summary>
26+
/// The configuration for the <see cref="DisableWarnings"/> mod.
27+
/// </summary>
28+
public class Configuration
29+
{
30+
/// <summary>
31+
/// Warning Codes to Disable
32+
/// </summary>
33+
public string[]? WarningCodes { get; init; }
34+
}
35+
36+
/// <inheritdoc />
37+
public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
38+
{
39+
await base.ExecuteAsync(ctx, ct);
40+
41+
// Read the configuration.
42+
var cfg = config.Get(ctx.JobKey);
43+
44+
if (cfg.WarningCodes is null)
45+
{
46+
return;
47+
}
48+
49+
var proj = ctx.SourceProject;
50+
51+
// Create the pragma directive trivia
52+
var pragmaDirective = Trivia(
53+
PragmaWarningDirectiveTrivia(
54+
Token(SyntaxKind.DisableKeyword),
55+
true)
56+
.WithErrorCodes(
57+
SeparatedList<ExpressionSyntax>(
58+
cfg.WarningCodes.Select(warn => IdentifierName(warn)))));
59+
60+
foreach (var docId in proj?.DocumentIds ?? [])
61+
{
62+
var doc =
63+
proj?.GetDocument(docId) ?? throw new InvalidOperationException("Document missing");
64+
if (await doc.GetSyntaxRootAsync(ct) is not { } root)
65+
{
66+
continue;
67+
}
68+
69+
// Find the using directive
70+
SyntaxNode? namespaceNode = root.DescendantNodes().OfType<FileScopedNamespaceDeclarationSyntax>().FirstOrDefault();
71+
72+
if (namespaceNode == null)
73+
{
74+
// Skip the case where no using directive is found
75+
continue;
76+
}
77+
78+
// Get the leading trivia (comments) of the first using directive
79+
var leadingTrivia = namespaceNode.GetLeadingTrivia();
80+
81+
// Insert the pragma directive after the comments
82+
var newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count, pragmaDirective)
83+
.Add(CarriageReturnLineFeed);
84+
85+
// Update the using directive with the new leading trivia
86+
var newUsingDirective = namespaceNode.WithLeadingTrivia(newLeadingTrivia);
87+
88+
// Replace the old using directive with the new one in the root node
89+
root = root.ReplaceNode(namespaceNode, newUsingDirective);
90+
doc = doc.WithSyntaxRoot(root);
91+
92+
proj = doc.Project;
93+
}
94+
95+
ctx.SourceProject = proj;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)