Skip to content

Commit b67724a

Browse files
committed
Change the gatherer/rewriter classes I wrote to be only designed to be used once
Putting a cancellation token and the rest of the parameters in the constructor is a bit weird, but does simplify things.
1 parent c87277b commit b67724a

2 files changed

Lines changed: 4 additions & 24 deletions

File tree

sources/SilkTouch/SilkTouch/Mods/ExtractNestedTyping.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public override async Task ExecuteAsync(IModContext ctx, CancellationToken ct =
101101
}
102102

103103
// Find missing handle types
104-
var handleDiscoverer = new MissingHandleTypeDiscoverer(logger);
105-
var missingHandleTypes = handleDiscoverer.GetMissingHandleTypes(compilation, ct);
104+
var handleDiscoverer = new MissingHandleTypeDiscoverer(logger, compilation, ct);
105+
var missingHandleTypes = handleDiscoverer.GetMissingHandleTypes();
106106

107107
// Second pass to modify project based on gathered data
108108
if (cfg.GenerateEmptyStructsForMissingHandleTypes)
@@ -296,7 +296,7 @@ string nativeTypeName
296296
}
297297
}
298298

299-
private class MissingHandleTypeDiscoverer(ILogger logger) : SymbolVisitor
299+
private class MissingHandleTypeDiscoverer(ILogger logger, Compilation compilation, CancellationToken ct) : SymbolVisitor
300300
{
301301
private readonly HashSet<IErrorTypeSymbol> _nonHandleTypes = new(SymbolEqualityComparer.Default);
302302
private readonly Dictionary<IErrorTypeSymbol, string> _missingTypes = new(SymbolEqualityComparer.Default);
@@ -307,10 +307,8 @@ private class MissingHandleTypeDiscoverer(ILogger logger) : SymbolVisitor
307307
/// <summary>
308308
/// Gets all missing handle types that are found and the namespace that they should be created in.
309309
/// </summary>
310-
public Dictionary<IErrorTypeSymbol, string> GetMissingHandleTypes(Compilation compilation, CancellationToken ct)
310+
public Dictionary<IErrorTypeSymbol, string> GetMissingHandleTypes()
311311
{
312-
Clear();
313-
314312
// We need to find and generate all missing handle types
315313
// Handle types are types that are only referenced through a pointer
316314
// We do this by parsing through the list of type errors
@@ -390,17 +388,6 @@ public Dictionary<IErrorTypeSymbol, string> GetMissingHandleTypes(Compilation co
390388
return new Dictionary<IErrorTypeSymbol, string>(_missingTypes.Where(kvp => !_nonHandleTypes.Contains(kvp.Key)), SymbolEqualityComparer.Default);
391389
}
392390

393-
/// <summary>
394-
/// Resets internal state.
395-
/// </summary>
396-
private void Clear()
397-
{
398-
_nonHandleTypes.Clear();
399-
_missingTypes.Clear();
400-
_currentNamespace = null;
401-
_pointerTypeDepth = 0;
402-
}
403-
404391
public override void VisitMethod(IMethodSymbol symbol)
405392
{
406393
base.VisitMethod(symbol);

sources/SilkTouch/SilkTouch/Mods/TransformHandles.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ private class HandleTypeDiscoverer(Project project, Compilation compilation, Can
168168
/// </summary>
169169
public async Task<List<INamedTypeSymbol>> GetHandleTypesAsync()
170170
{
171-
Clear();
172-
173171
Visit(compilation.GlobalNamespace);
174172

175173
var results = new List<INamedTypeSymbol>();
@@ -218,11 +216,6 @@ public async Task<List<INamedTypeSymbol>> GetHandleTypesAsync()
218216
return results;
219217
}
220218

221-
/// <summary>
222-
/// Clears all internal state
223-
/// </summary>
224-
private void Clear() => _emptyStructs.Clear();
225-
226219
public override void VisitNamespace(INamespaceSymbol symbol)
227220
{
228221
base.VisitNamespace(symbol);

0 commit comments

Comments
 (0)