Skip to content

Commit 6c6d633

Browse files
committed
Run CSharpier
1 parent 0d11394 commit 6c6d633

13 files changed

+256
-161
lines changed

Diff for: sources/SilkTouch/SilkTouch/Clang/ClangScraper.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ out var handle
176176
using var diagnostic = handle.GetDiagnostic(i);
177177

178178
logger.Log(
179-
diagnostic.Severity switch {
179+
diagnostic.Severity switch
180+
{
180181
CXDiagnostic_Ignored => LogLevel.Trace,
181182
CXDiagnostic_Note => LogLevel.Debug,
182183
CXDiagnostic_Warning => LogLevel.Warning,

Diff for: sources/SilkTouch/SilkTouch/Mods/AddOpaqueStructs.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ public Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
7272
{
7373
var qualified = name.LastIndexOf('.');
7474
var ns =
75-
qualified != -1
76-
? ModUtils.NamespaceIntoIdentifierName(name.AsSpan()[..qualified])
77-
: _defaultNamespaces.TryGetValue(ctx.JobKey, out var def)
78-
? ModUtils.NamespaceIntoIdentifierName(def)
79-
: null;
75+
qualified != -1 ? ModUtils.NamespaceIntoIdentifierName(name.AsSpan()[..qualified])
76+
: _defaultNamespaces.TryGetValue(ctx.JobKey, out var def)
77+
? ModUtils.NamespaceIntoIdentifierName(def)
78+
: null;
8079
if (ns is null)
8180
{
8281
logger.LogWarning(

Diff for: sources/SilkTouch/SilkTouch/Mods/ChangeNamespace.cs

+25-22
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
using Microsoft.CodeAnalysis;
1010
using Microsoft.CodeAnalysis.CSharp;
1111
using Microsoft.CodeAnalysis.CSharp.Syntax;
12-
using Microsoft.Extensions.Options;
1312
using Microsoft.Extensions.Logging;
13+
using Microsoft.Extensions.Options;
1414
using Silk.NET.SilkTouch.Clang;
1515
using Silk.NET.SilkTouch.Utility;
1616
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
@@ -99,7 +99,7 @@ public Task<List<ResponseFile>> BeforeScrapeAsync(string key, List<ResponseFile>
9999
WithTypes = rsp.GeneratorConfiguration.WithTypes,
100100
WithUsings = rsp.GeneratorConfiguration.WithUsings,
101101
WithPackings = rsp.GeneratorConfiguration.WithPackings,
102-
}
102+
},
103103
};
104104

105105
ProgressBarUtility.SetPercentage(i / (float)rsps.Count);
@@ -156,17 +156,16 @@ public Rewriter(
156156
_usingsToAdd.Clear();
157157
return base.VisitCompilationUnit(node) switch
158158
{
159-
CompilationUnitSyntax syntax
160-
=> syntax.AddUsings(
161-
_usingsToAdd
162-
.Select(x => UsingDirective(ModUtils.NamespaceIntoIdentifierName(x)))
163-
.Where(x =>
164-
syntax.Usings.All(y => x.Name?.ToString() != y.Name?.ToString())
165-
)
166-
.ToArray()
167-
),
159+
CompilationUnitSyntax syntax => syntax.AddUsings(
160+
_usingsToAdd
161+
.Select(x => UsingDirective(ModUtils.NamespaceIntoIdentifierName(x)))
162+
.Where(x =>
163+
syntax.Usings.All(y => x.Name?.ToString() != y.Name?.ToString())
164+
)
165+
.ToArray()
166+
),
168167
{ } ret => ret,
169-
null => null
168+
null => null,
170169
};
171170
}
172171

@@ -180,10 +179,11 @@ CompilationUnitSyntax syntax
180179
}
181180
return base.VisitNamespaceDeclaration(node) switch
182181
{
183-
NamespaceDeclarationSyntax syntax
184-
=> syntax.WithName(ModUtils.NamespaceIntoIdentifierName(newNs)),
182+
NamespaceDeclarationSyntax syntax => syntax.WithName(
183+
ModUtils.NamespaceIntoIdentifierName(newNs)
184+
),
185185
{ } ret => ret,
186-
null => null
186+
null => null,
187187
};
188188
}
189189

@@ -199,10 +199,11 @@ FileScopedNamespaceDeclarationSyntax node
199199
}
200200
return base.VisitFileScopedNamespaceDeclaration(node) switch
201201
{
202-
FileScopedNamespaceDeclarationSyntax syntax
203-
=> syntax.WithName(ModUtils.NamespaceIntoIdentifierName(newNs)),
202+
FileScopedNamespaceDeclarationSyntax syntax => syntax.WithName(
203+
ModUtils.NamespaceIntoIdentifierName(newNs)
204+
),
204205
{ } ret => ret,
205-
null => null
206+
null => null,
206207
};
207208
}
208209

@@ -214,11 +215,13 @@ FileScopedNamespaceDeclarationSyntax syntax
214215
{
215216
_usingsToAdd.Add(oldNs);
216217
}
217-
return base.VisitUsingDirective(node) switch {
218-
UsingDirectiveSyntax syntax
219-
=> syntax.WithName(ModUtils.NamespaceIntoIdentifierName(newNs)),
218+
return base.VisitUsingDirective(node) switch
219+
{
220+
UsingDirectiveSyntax syntax => syntax.WithName(
221+
ModUtils.NamespaceIntoIdentifierName(newNs)
222+
),
220223
{ } ret => ret,
221-
null => null
224+
null => null,
222225
};
223226
}
224227
}

Diff for: sources/SilkTouch/SilkTouch/Mods/ManualFileImporter.cs

+14-10
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,20 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
8282
{
8383
string outputLocation = regex.Key.Replace(file, regex.Value);
8484
bool isTest = outputLocation.StartsWith("tests/");
85-
outputLocation = outputLocation.Remove(0, outputLocation.IndexOf(isTest ? "tests/" : "sources/"));
85+
outputLocation = outputLocation.Remove(
86+
0,
87+
outputLocation.IndexOf(isTest ? "tests/" : "sources/")
88+
);
8689
string relativeKey = outputLocation.Remove(0, isTest ? 6 : 8);
8790
if (
88-
!(isTest ? aggregatedTests : aggregatedSources).TryAdd(
89-
relativeKey,
90-
CSharpSyntaxTree.ParseText(
91-
SourceText.From(
92-
File.OpenRead(file)),
93-
path: relativeKey
94-
)
95-
)
91+
!(isTest ? aggregatedTests : aggregatedSources).TryAdd(
92+
relativeKey,
93+
CSharpSyntaxTree.ParseText(
94+
SourceText.From(File.OpenRead(file)),
95+
path: relativeKey
9696
)
97+
)
98+
)
9799
{
98100
logger.LogError(
99101
"Failed to add {0} - are the response file outputs conflicting?",
@@ -145,7 +147,9 @@ private string GlobToRegexInput(string glob)
145147
private string GlobToRegexOutput(string glob)
146148
{
147149
int index = 1;
148-
return glob.Split("**").SelectMany(split => split.Split('*')).Aggregate((s1, s2) => $"{s1}${index++}{s2}");
150+
return glob.Split("**")
151+
.SelectMany(split => split.Split('*'))
152+
.Aggregate((s1, s2) => $"{s1}${index++}{s2}");
149153
}
150154
}
151155
}

Diff for: sources/SilkTouch/SilkTouch/Mods/MixKhronosData.cs

+23-24
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ public partial class MixKhronosData(
4949
);
5050
private static readonly char[] _listSeparators = { ',', '|', '+' };
5151

52-
private static readonly Dictionary<string, string> _defaultEnumNativeTypeNameMaps =
53-
new()
54-
{
55-
{ "GLenum", "GLEnum" },
56-
{ "EGLenum", "EGLEnum" },
57-
{ "GLbitfield", "GLEnum" }
58-
};
52+
private static readonly Dictionary<string, string> _defaultEnumNativeTypeNameMaps = new()
53+
{
54+
{ "GLenum", "GLEnum" },
55+
{ "EGLenum", "EGLEnum" },
56+
{ "GLbitfield", "GLEnum" },
57+
};
5958

6059
internal class JobData
6160
{
@@ -185,7 +184,7 @@ public enum ExtensionVendorTrimmingMode
185184
/// <summary>
186185
/// Only trim Khronos/first-party extension vendor names i.e. KHR and ARB.
187186
/// </summary>
188-
KhronosOnly
187+
KhronosOnly,
189188
}
190189

191190
private class ExtensionVendorTrimmingModeJsonConverter
@@ -231,7 +230,7 @@ public async Task InitializeAsync(IModContext ctx, CancellationToken ct = defaul
231230
Configuration = currentConfig,
232231
TypeMap = currentConfig.TypeMap is not null
233232
? new Dictionary<string, string>(currentConfig.TypeMap)
234-
: []
233+
: [],
235234
};
236235
job.TypeMap.TryAdd("int8_t", "sbyte");
237236
job.TypeMap.TryAdd("uint8_t", "byte");
@@ -266,7 +265,7 @@ .. xml.Element("registry")
266265
?.Element("extensions")
267266
?.Elements("extension")
268267
.Attributes("name")
269-
.Select(x => x.Value.Split('_')[1].ToUpper()) ?? Enumerable.Empty<string>()
268+
.Select(x => x.Value.Split('_')[1].ToUpper()) ?? Enumerable.Empty<string>(),
270269
];
271270
job.ApiSets = apiSets;
272271
job.SupportedApiProfiles = supportedApiProfiles;
@@ -444,7 +443,7 @@ public SupportedApiProfileAttribute ToAttribute(string profile) =>
444443
ImpliesSets = ImpliedSets?.ToArray(),
445444
MaxVersion = EndVersion?.ToString(),
446445
MinVersion = StartVersion?.ToString(),
447-
RequireAll = RequireAll
446+
RequireAll = RequireAll,
448447
};
449448
}
450449

@@ -588,7 +587,7 @@ .. profileElement
588587
) // <-- future proofing
589588
.Where(x => x != "compatibility") // <-- assuming default "gl" is "glcompatibility"
590589
.Select(x => $"{variant}{x}"),
591-
.. profileVariations.TryGetValue(variant, out var v) ? v : []
590+
.. profileVariations.TryGetValue(variant, out var v) ? v : [],
592591
];
593592
}
594593
}
@@ -710,11 +709,10 @@ private void EvaluateFeature(
710709
// Create a HashSet to store all the symbols in this feature.
711710
// If we're not using explicit dependencies, then we track the profile-wide symbol list. We assume that the
712711
// "number" order is being respected.
713-
var symbols = explicitDependencies
714-
? inheritance[apiSet] = []
715-
: inheritance.TryGetValue(variant, out var syms)
716-
? syms
717-
: inheritance[variant] = [];
712+
var symbols =
713+
explicitDependencies ? inheritance[apiSet] = []
714+
: inheritance.TryGetValue(variant, out var syms) ? syms
715+
: inheritance[variant] = [];
718716

719717
// If we're using implicit dependencies in the form of secondary APIs, the symbol changes we explicitly need to
720718
// inherit are contained in the pendingChanges dictionary for this variant.
@@ -840,7 +838,7 @@ and var idx
840838
// The symbol has been removed, mark it with the end version.
841839
evals[idx] = evals[idx] with
842840
{
843-
EndVersion = number
841+
EndVersion = number,
844842
};
845843
}
846844
}
@@ -1242,7 +1240,7 @@ vendorSuffix is null
12421240

12431241
job.Groups[current] = groupInfo = groupInfo with
12441242
{
1245-
ExclusiveVendor = vendorSuffix
1243+
ExclusiveVendor = vendorSuffix,
12461244
};
12471245

12481246
if (notSafeToTrim)
@@ -1610,10 +1608,11 @@ is not { } newType
16101608
static TypeSyntax PointerToGroupPointer(TypeSyntax original, string group) =>
16111609
original switch
16121610
{
1613-
PointerTypeSyntax ptr
1614-
=> ptr.WithElementType(PointerToGroupPointer(ptr.ElementType, group)),
1611+
PointerTypeSyntax ptr => ptr.WithElementType(
1612+
PointerToGroupPointer(ptr.ElementType, group)
1613+
),
16151614
PredefinedTypeSyntax or IdentifierNameSyntax => IdentifierName(group),
1616-
_ => throw new ArgumentOutOfRangeException(nameof(original))
1615+
_ => throw new ArgumentOutOfRangeException(nameof(original)),
16171616
};
16181617

16191618
TypeSyntax? GetTypeTransformation(
@@ -1667,7 +1666,7 @@ ref bool anyNonTrivialParams
16671666
2 when otherGroup is not null => PointerToGroupPointer(type, group),
16681667
1 when otherGroup is not null => PointerToGroupPointer(type, otherGroup),
16691668
1 => PointerToGroupPointer(type, group),
1670-
_ => null
1669+
_ => null,
16711670
};
16721671
}
16731672

@@ -1943,7 +1942,7 @@ var group in (groupName is null ? Enumerable.Empty<string>() : [groupName])
19431942
Namespace =
19441943
enumNamespace is not null && groupInfo.Namespace == enumNamespace
19451944
? enumNamespace
1946-
: null
1945+
: null,
19471946
}
19481947
: new EnumGroup(
19491948
group,

Diff for: sources/SilkTouch/SilkTouch/Mods/TransformCOM.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,7 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
128128

129129
proj = doc.Project;
130130

131-
logger.LogDebug(
132-
"COM Rewrite for {0} Complete ({1}/{2})",
133-
doc.Name,
134-
index,
135-
count
136-
);
131+
logger.LogDebug("COM Rewrite for {0} Complete ({1}/{2})", doc.Name, index, count);
137132
ProgressBarUtility.SetPercentage((float)index / count);
138133
}
139134

Diff for: sources/SilkTouch/SilkTouch/Mods/TransformFunctions.cs

+22-14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ namespace Silk.NET.SilkTouch.Mods;
2121
/// Mods the bindings to use the Silk.NET.Core pointer types.
2222
/// </summary>
2323
[ModConfiguration<Configuration>]
24-
public class TransformFunctions(FunctionTransformer ft,
25-
ILogger<TransformFunctions> logger) : ModCSharpSyntaxRewriter, IMod
24+
public class TransformFunctions(FunctionTransformer ft, ILogger<TransformFunctions> logger)
25+
: ModCSharpSyntaxRewriter,
26+
IMod
2627
{
2728
private ThreadLocal<string> _jobKey = new();
2829

@@ -120,9 +121,10 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
120121
if (await doc.GetSyntaxRootAsync(ct) is { } root)
121122
{
122123
var syntaxTree = await doc.GetSyntaxTreeAsync();
123-
_semanticModel = compilation is not null && syntaxTree is not null
124-
? compilation.GetSemanticModel(syntaxTree!)
125-
: await doc.GetSemanticModelAsync();
124+
_semanticModel =
125+
compilation is not null && syntaxTree is not null
126+
? compilation.GetSemanticModel(syntaxTree!)
127+
: await doc.GetSemanticModelAsync();
126128

127129
visitor.SemanticModel = _semanticModel;
128130
visitor.Visit(root);
@@ -215,8 +217,11 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
215217
return ret;
216218
}
217219

218-
219-
private class Visitor(Dictionary<string, string> toRename, List<(ISymbol, string)> toRenameSymbols, ILogger logger) : CSharpSyntaxWalker
220+
private class Visitor(
221+
Dictionary<string, string> toRename,
222+
List<(ISymbol, string)> toRenameSymbols,
223+
ILogger logger
224+
) : CSharpSyntaxWalker
220225
{
221226
public SemanticModel? SemanticModel;
222227

@@ -250,13 +255,16 @@ public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
250255
{
251256
base.VisitMethodDeclaration(node);
252257

253-
var discrimWithRet = _typeName + ":" + ModUtils.DiscrimStr(
254-
node.Modifiers,
255-
node.TypeParameterList,
256-
node.Identifier.ToString(),
257-
node.ParameterList,
258-
node.ReturnType
259-
);
258+
var discrimWithRet =
259+
_typeName
260+
+ ":"
261+
+ ModUtils.DiscrimStr(
262+
node.Modifiers,
263+
node.TypeParameterList,
264+
node.Identifier.ToString(),
265+
node.ParameterList,
266+
node.ReturnType
267+
);
260268

261269
if (!toRename.TryGetValue(discrimWithRet, out string? newName))
262270
{

0 commit comments

Comments
 (0)