Skip to content

Commit 9b3a0b9

Browse files
committed
QualifiedName Fix
- Fixes several instances of QualifiedNames instead of using ParseTypeName
1 parent 0cc49b8 commit 9b3a0b9

7 files changed

Lines changed: 128 additions & 85 deletions

File tree

generator.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
],
6767
"InjectedRemappedNames": {
6868
"BOOL": "MaybeBool<int>",
69-
"HANDLE": "Handle"
69+
"HANDLE": "Handle",
70+
"HSTRING": "HString",
71+
"HRESULT": "HResult"
7072
},
7173
"InjectedGeneratorOptions": [
7274
"--config",

sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ z.MethodKind is MethodKind.Constructor or MethodKind.Destructor
316316
);
317317
}),
318318
logger,
319-
ct
319+
ct,
320+
includeCandidateLocations: true
320321
);
321322

322323
logger.LogDebug(

sources/SilkTouch/SilkTouch/Mods/RemapTypes.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ await proj.GetCompilationAsync(ct)
6666

6767
List<Location> retrievedLocations = [];
6868

69-
foreach (var diagnostic in diagnostics)
70-
{
69+
Parallel.ForEach(diagnostics, diagnostic => {
7170
if (diagnostic.Id == "CS0246" && !retrievedLocations.Contains(diagnostic.Location))
7271
{
7372
retrievedLocations.Add(diagnostic.Location);
7473
}
75-
progressService.SetProgress(index++ / total);
76-
}
74+
progressService.SetProgress(Interlocked.Increment(ref index) / total);
75+
});
7776

7877
progressService.SetTask("Remapping Errored Types");
7978
await NameUtils.RemapAllAsync(ctx, cfg.Mappings!, retrievedLocations, logger);

sources/SilkTouch/SilkTouch/Mods/TransformCOM.cs

Lines changed: 89 additions & 57 deletions
Large diffs are not rendered by default.

sources/SilkTouch/SilkTouch/Mods/TransformInterfaces.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using Silk.NET.SilkTouch.Logging;
2121
using Silk.NET.SilkTouch.Utility;
2222
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
23-
using static Silk.NET.SilkTouch.Utility.KeyedStringTree;
2423

2524
namespace Silk.NET.SilkTouch.Mods
2625
{
@@ -149,7 +148,12 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
149148
? compilation.GetSemanticModel(syntaxTree!)
150149
: await doc.GetSemanticModelAsync();
151150

152-
doc = doc.WithSyntaxRoot(updater.Visit(root).NormalizeWhitespace());
151+
doc = doc.WithSyntaxRoot(root = (updater.Visit(root).NormalizeWhitespace()));
152+
153+
if (doc.FilePath?.ToLower().Contains("idxgifactory.gen.cs") ?? false)
154+
{
155+
File.WriteAllText($"IDXGIFactory.TransformInterface.UsageUpdater.cs", root.ToFullString());
156+
}
153157

154158
proj = doc.Project;
155159

@@ -176,7 +180,12 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
176180
continue;
177181
}
178182

179-
doc = doc.WithSyntaxRoot(rewriter.Visit(root).NormalizeWhitespace());
183+
doc = doc.WithSyntaxRoot(root = rewriter.Visit(root).NormalizeWhitespace());
184+
185+
if (doc.FilePath?.ToLower().Contains("idxgifactory.gen.cs") ?? false)
186+
{
187+
File.WriteAllText($"IDXGIFactory.TransformInterface.Rewriter.cs", root.ToFullString());
188+
}
180189

181190
proj = doc.Project;
182191

@@ -437,7 +446,7 @@ typeInfoL.Type is null
437446
return BinaryExpression(
438447
node.Kind(),
439448
node.Left,
440-
IdentifierName($"{node.Right.ToString()}.lpVtbl")
449+
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, node.Right, IdentifierName("lpVtbl"))
441450
);
442451
}
443452
}
@@ -448,7 +457,7 @@ typeInfoL.Type is null
448457
{
449458
return BinaryExpression(
450459
node.Kind(),
451-
IdentifierName($"{node.Left.ToString()}.lpVtbl"),
460+
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, node.Left, IdentifierName("lpVtbl")),
452461
node.Right
453462
);
454463
}
@@ -476,7 +485,7 @@ var.Initializer is not null
476485

477486
if (pointerDepth == 0)
478487
{
479-
return node.WithType(ParseTypeName($"{variableType}.Native"));
488+
return node.WithType(QualifiedName(IdentifierName($"{variableType}"), IdentifierName("Native")));
480489
}
481490

482491
var name = GetTypeName(innerType.ToString() ?? string.Empty);
@@ -531,7 +540,7 @@ variableExpression is not null
531540
{
532541
pointerDepth = GetPointerDepth(orig.ReturnType, out innerType);
533542
var returnType = shouldEditReturnType
534-
? IdentifierName($"{innerType}.Native")
543+
? QualifiedName(IdentifierName($"{innerType}"), IdentifierName("Native"))
535544
: orig.ReturnType;
536545
if (shouldEditReturnType)
537546
{
@@ -793,7 +802,7 @@ anc is MethodDeclarationSyntax mds
793802
return
794803
InterfaceTypes.ContainsKey(name)
795804
&& node.Ancestors().OfType<TypeSyntax>().Count() > 0
796-
? IdentifierName($"{name}.Native")
805+
? QualifiedName(IdentifierName(name), IdentifierName("Native"))
797806
: base.VisitIdentifierName(node);
798807
}
799808

@@ -868,7 +877,7 @@ visitedParameter is null
868877
node.RemoveNodes(interfaceNodes ?? [], SyntaxRemoveOptions.KeepNoTrivia)
869878
?? node;
870879

871-
var nativeName = $"{name}.Native";
880+
var nativeName = QualifiedName(IdentifierName(name), IdentifierName("Native"));
872881

873882
var parentNode = StructDeclaration(
874883
node.AttributeLists,
@@ -1059,7 +1068,7 @@ mem is MethodDeclarationSyntax
10591068
SyntaxKind.SimpleAssignmentExpression,
10601069
IdentifierName("lpVtbl"),
10611070
CastExpression(
1062-
PointerType(ParseTypeName(nativeName)),
1071+
PointerType(nativeName),
10631072
IdentifierName("vtbl")
10641073
)
10651074
)
@@ -1193,7 +1202,7 @@ mem is MethodDeclarationSyntax
11931202
ParameterList(
11941203
SingletonSeparatedList(
11951204
Parameter(Identifier("vtbl"))
1196-
.WithType(ParseTypeName($"Ptr<{nativeName}>"))
1205+
.WithType(GenericName(Identifier("Ptr"), TypeArgumentList(SingletonSeparatedList<TypeSyntax>(nativeName))))
11971206
)
11981207
)
11991208
)
@@ -1333,8 +1342,8 @@ mem is MethodDeclarationSyntax
13331342
parentNode = generateCasts(
13341343
parentNode,
13351344
name,
1336-
PointerType(ParseTypeName(nativeName)),
1337-
nativeName,
1345+
PointerType(nativeName),
1346+
nativeName.ToString(),
13381347
CastExpression(ParseTypeName("Ptr<Native>"), IdentifierName("value")),
13391348
false,
13401349
true

sources/SilkTouch/SilkTouch/Naming/NameUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public static async Task RemapAllAsync(
497497
var testProjId = ctx.TestProject?.Id;
498498
foreach (
499499
var (syntaxTree, renameLocations) in candidateLocations
500-
.GroupBy(x => x.SourceTree)
500+
.GroupBy(x => x?.SourceTree ?? default)
501501
.Select(x => (x.Key, x.OrderByDescending(y => y.SourceSpan)))
502502
)
503503
{

sources/SilkTouch/SilkTouch/Utility/KeyedStringTree.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ namespace Silk.NET.SilkTouch.Utility
88
/// <summary>
99
/// Easily combinable and searchable tree structure
1010
/// </summary>
11-
public class KeyedStringTree
11+
public class KeyedStringTree<TValue>
1212
{
1313
ReaderWriterLockSlim _concurrencyLock = new();
1414

1515
/// <summary>
16-
/// ctor for <see cref="KeyedStringTree"/>
16+
/// ctor for <see cref="KeyedStringTree{TValue}"/>
1717
/// </summary>
1818
/// <param name="rootKey"></param>
1919
/// <param name="rootValue"></param>
20-
public KeyedStringTree(string rootKey, string rootValue)
20+
public KeyedStringTree(string rootKey, TValue rootValue)
2121
{
2222
RootNode = new(rootKey, rootValue);
2323
}
@@ -78,7 +78,7 @@ private bool _FindNode(string key, [NotNullWhen(true)] out Node? node)
7878
/// </summary>
7979
/// <param name="other"></param>
8080
/// <returns>Whether combination was successful</returns>
81-
public bool TryConsume(KeyedStringTree other)
81+
public bool TryConsume(KeyedStringTree<TValue> other)
8282
{
8383
_concurrencyLock.EnterWriteLock();
8484
if (!_FindNode(other.RootNode.Key, out Node? node))
@@ -99,7 +99,7 @@ public bool TryConsume(KeyedStringTree other)
9999
/// <param name="newNodeKey">key of the new child node</param>
100100
/// <param name="newNodeValue">value of the new child node</param>
101101
/// <returns>if the parent node was found in the tree</returns>
102-
public bool TryAddNode(string parentKey, string newNodeKey, string newNodeValue)
102+
public bool TryAddNode(string parentKey, string newNodeKey, TValue newNodeValue)
103103
{
104104
_concurrencyLock.EnterWriteLock();
105105
if (!_FindNode(parentKey, out Node? node))
@@ -132,11 +132,11 @@ private void CombineNodes(Node baseNode, Node additiveNode)
132132
}
133133

134134
/// <summary>
135-
/// Node from a <see cref="KeyedStringTree" />
135+
/// Node from a <see cref="KeyedStringTree{TValue}" />
136136
/// </summary>
137137
public class Node
138138
{
139-
internal Node(string key, string value, Node? parent = null)
139+
internal Node(string key, TValue value, Node? parent = null)
140140
{
141141
Key = key;
142142
Value = value;
@@ -151,7 +151,7 @@ internal Node(string key, string value, Node? parent = null)
151151
/// <summary>
152152
/// Value at this node
153153
/// </summary>
154-
public string Value;
154+
public TValue Value;
155155

156156
/// <summary>
157157
/// All children for this node

0 commit comments

Comments
 (0)