Skip to content

Commit adf4eee

Browse files
committed
Rename INameTrimmer to INameProcessor and update rest of codebase
1 parent 464703c commit adf4eee

File tree

7 files changed

+69
-70
lines changed

7 files changed

+69
-70
lines changed

sources/SilkTouch/SilkTouch/Mods/PrettifyNames.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
126126

127127
// Trim and prettify the trimmable names
128128

129-
// Define trimmers
130-
var trimmers = new INameTrimmer[]
129+
// Define name processors
130+
var nameProcessors = new INameProcessor[]
131131
{
132-
new NameAffixerEarlyTrimmer(nameAffixer),
132+
new NameAffixerEarlyNameProcessor(nameAffixer),
133133
new NameTrimmer(),
134-
new PrettifyNamesTrimmer(namePrettifier),
135-
new NameAffixerLateTrimmer(nameAffixer),
136-
new PrefixIfStartsWithNumberTrimmer(),
134+
new PrettifyNameProcessor(namePrettifier),
135+
new NameAffixerLateNameProcessor(nameAffixer),
136+
new PrefixIfStartsWithNumberNameProcessor(),
137137
};
138138

139139
// Create a type name dictionary to trim the type names.
@@ -146,16 +146,16 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
146146
// trim.
147147
if (typeNames.Count > 1 || cfg.GlobalPrefixHints is not null)
148148
{
149-
Trim(
150-
new NameTrimmerContext
149+
ProcessNames(
150+
new NameProcessorContext
151151
{
152152
Container = null,
153153
Names = typeNames,
154154
Configuration = cfg,
155155
JobKey = ctx.JobKey,
156156
NonDeterminant = visitor.NonDeterminant,
157157
},
158-
trimmers
158+
nameProcessors
159159
);
160160
}
161161

@@ -169,16 +169,16 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
169169
var constNames = consts.ToDictionary(x => x, x => new CandidateNames(x, []));
170170

171171
// Trim the constants.
172-
Trim(
173-
new NameTrimmerContext
172+
ProcessNames(
173+
new NameProcessorContext
174174
{
175175
Container = typeName,
176176
Names = constNames,
177177
Configuration = cfg,
178178
JobKey = ctx.JobKey,
179179
NonDeterminant = visitor.NonDeterminant,
180180
},
181-
trimmers
181+
nameProcessors
182182
);
183183

184184
// Rename the functions. More often that not functions have different nomenclature to constants, so we
@@ -194,16 +194,16 @@ public async Task ExecuteAsync(IModContext ctx, CancellationToken ct = default)
194194
);
195195

196196
// Trim the functions.
197-
Trim(
198-
new NameTrimmerContext
197+
ProcessNames(
198+
new NameProcessorContext
199199
{
200200
Container = typeName,
201201
Names = functionNames,
202202
Configuration = cfg,
203203
JobKey = ctx.JobKey,
204204
NonDeterminant = visitor.NonDeterminant,
205205
},
206-
trimmers,
206+
nameProcessors,
207207
functionSyntax
208208
);
209209

@@ -461,15 +461,15 @@ NamePrettifier namePrettifier
461461
return result;
462462
}
463463

464-
private void Trim(
465-
NameTrimmerContext context,
466-
IEnumerable<INameTrimmer> trimmers,
464+
private void ProcessNames(
465+
NameProcessorContext context,
466+
IEnumerable<INameProcessor> nameProcessors,
467467
Dictionary<string, IEnumerable<MethodDeclarationSyntax>>? functionSyntax = null
468468
)
469469
{
470470
// Ensure the trimmers don't see names that have been manually overridden, as we don't want them to influence
471471
// automatic prefix determination for example
472-
var namesToTrim = context.Names;
472+
var namesToProcess = context.Names;
473473
foreach (var (nativeName, overriddenName) in context.Configuration.NameOverrides)
474474
{
475475
var nameToAdd = nativeName;
@@ -497,21 +497,21 @@ private void Trim(
497497
}
498498
}
499499

500-
if (!namesToTrim.TryGetValue(nameToAdd, out var v))
500+
if (!namesToProcess.TryGetValue(nameToAdd, out var v))
501501
{
502502
continue;
503503
}
504504

505505
// If we haven't created the differentiated dictionary yet, then do so now. We do want to keep the original
506506
// dictionary so we can actually apply the renames; if we have created two different branching dictionaries
507-
// they are recombined following trimming.
508-
if (namesToTrim == context.Names)
507+
// they are recombined following name processing.
508+
if (namesToProcess == context.Names)
509509
{
510-
namesToTrim = namesToTrim.ToDictionary();
510+
namesToProcess = namesToProcess.ToDictionary();
511511
}
512512

513-
// Don't let the trimmers see the overridden native name.
514-
namesToTrim.Remove(nameToAdd);
513+
// Don't let the name processors see the overridden native name.
514+
namesToProcess.Remove(nameToAdd);
515515

516516
// Apply the name override to the dictionary we actually use.
517517
context.Names[nameToAdd] = new CandidateNames(
@@ -520,16 +520,16 @@ private void Trim(
520520
);
521521
}
522522

523-
// Run each trimmer
524-
foreach (var trimmer in trimmers)
523+
// Run each name processor
524+
foreach (var nameProcessor in nameProcessors)
525525
{
526-
trimmer.Trim(context with { Names = namesToTrim });
526+
nameProcessor.ProcessNames(context with { Names = namesToProcess });
527527
}
528528

529529
// Apply changes
530-
if (namesToTrim != context.Names)
530+
if (namesToProcess != context.Names)
531531
{
532-
foreach (var (evalName, result) in namesToTrim)
532+
foreach (var (evalName, result) in namesToProcess)
533533
{
534534
context.Names[evalName] = result;
535535
}
@@ -1201,7 +1201,7 @@ Dictionary<string, NameAffixConfiguration> config
12011201
/// Removes affixes from the specified primary name and adds the original specified primary to the secondary list if provided.
12021202
/// </summary>
12031203
/// <remarks>
1204-
/// Designed to be used by either <see cref="ApplyPrettifyOnlyPipeline"/> or <see cref="NameAffixerEarlyTrimmer"/>.
1204+
/// Designed to be used by either <see cref="ApplyPrettifyOnlyPipeline"/> or <see cref="NameAffixerEarlyNameProcessor"/>.
12051205
/// </remarks>
12061206
/// <param name="primary">The current primary name.</param>
12071207
/// <param name="container">The container name. Either null or the containing type.</param>
@@ -1234,7 +1234,7 @@ public string RemoveAffixes(
12341234
/// Applies affixes to the specified primary name and adds fallbacks to the secondary list if provided.
12351235
/// </summary>
12361236
/// <remarks>
1237-
/// Designed to be used by either <see cref="ApplyPrettifyOnlyPipeline"/> or <see cref="NameAffixerLateTrimmer"/>.
1237+
/// Designed to be used by either <see cref="ApplyPrettifyOnlyPipeline"/> or <see cref="NameAffixerLateNameProcessor"/>.
12381238
/// </remarks>
12391239
/// <param name="primary">The current primary name.</param>
12401240
/// <param name="container">The container name. Either null or the containing type.</param>
@@ -1397,12 +1397,12 @@ private NameAffixConfiguration GetConfiguration(string category) =>
13971397
}
13981398

13991399
/// <summary>
1400-
/// Removes identified affixes so that other trimmers can process the base name separately.
1401-
/// These affixes should be reapplied by <see cref="NameAffixerLateTrimmer"/>.
1400+
/// Removes identified affixes so that other name processors can process the base name separately.
1401+
/// These affixes should be reapplied by <see cref="NameAffixerLateNameProcessor"/>.
14021402
/// </summary>
1403-
private class NameAffixerEarlyTrimmer(PrettifyNamesAffixer affixer) : INameTrimmer
1403+
private class NameAffixerEarlyNameProcessor(PrettifyNamesAffixer affixer) : INameProcessor
14041404
{
1405-
public void Trim(NameTrimmerContext context)
1405+
public void ProcessNames(NameProcessorContext context)
14061406
{
14071407
if (context.Container == null)
14081408
{
@@ -1430,9 +1430,9 @@ public void Trim(NameTrimmerContext context)
14301430
}
14311431
}
14321432

1433-
private class PrettifyNamesTrimmer(NamePrettifier namePrettifier) : INameTrimmer
1433+
private class PrettifyNameProcessor(NamePrettifier namePrettifier) : INameProcessor
14341434
{
1435-
public void Trim(NameTrimmerContext context)
1435+
public void ProcessNames(NameProcessorContext context)
14361436
{
14371437
foreach (var (original, (primary, secondary)) in context.Names)
14381438
{
@@ -1455,9 +1455,9 @@ public void Trim(NameTrimmerContext context)
14551455
/// <summary>
14561456
/// Reapplies and transforms identified affixes based on <see cref="NameAffixConfiguration"/>.
14571457
/// </summary>
1458-
private class NameAffixerLateTrimmer(PrettifyNamesAffixer affixer) : INameTrimmer
1458+
private class NameAffixerLateNameProcessor(PrettifyNamesAffixer affixer) : INameProcessor
14591459
{
1460-
public void Trim(NameTrimmerContext context)
1460+
public void ProcessNames(NameProcessorContext context)
14611461
{
14621462
if (context.Container == null)
14631463
{
@@ -1485,9 +1485,9 @@ public void Trim(NameTrimmerContext context)
14851485
}
14861486
}
14871487

1488-
private class PrefixIfStartsWithNumberTrimmer : INameTrimmer
1488+
private class PrefixIfStartsWithNumberNameProcessor : INameProcessor
14891489
{
1490-
public void Trim(NameTrimmerContext context)
1490+
public void ProcessNames(NameProcessorContext context)
14911491
{
14921492
foreach (var (original, (primary, secondary)) in context.Names)
14931493
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Silk.NET.SilkTouch.Naming;
2+
3+
/// <summary>
4+
/// Represents a name processor.
5+
/// </summary>
6+
public interface INameProcessor
7+
{
8+
/// <summary>
9+
/// Process and transform the names within the given container.
10+
/// </summary>
11+
public void ProcessNames(NameProcessorContext context);
12+
}

sources/SilkTouch/SilkTouch/Naming/INameTrimmer.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

sources/SilkTouch/SilkTouch/Naming/NameTrimmerContext.cs renamed to sources/SilkTouch/SilkTouch/Naming/NameProcessorContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
namespace Silk.NET.SilkTouch.Naming;
77

88
/// <summary>
9-
/// State made available to <see cref="INameTrimmer"/> implementations when determining a trimmed name.
9+
/// State made available to <see cref="INameProcessor"/> implementations when determining a trimmed name.
1010
/// </summary>
11-
public readonly struct NameTrimmerContext
11+
public readonly struct NameProcessorContext
1212
{
1313
/// <summary>
1414
/// Gets the name of the "container" (e.g. a type name) of the APIs in <see cref="Names"/>.

sources/SilkTouch/SilkTouch/Naming/NameTrimmer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <summary>
44
/// The default name trimmer ported from Silk.NET 2.18 with modifications for 3.0.
55
/// </summary>
6-
public class NameTrimmer : INameTrimmer
6+
public class NameTrimmer : INameProcessor
77
{
88
/// <summary>
99
/// Determines whether a second pass without using <see cref="GetTrimmingName"/> is warranted.
@@ -20,7 +20,7 @@ public class NameTrimmer : INameTrimmer
2020
private static readonly HashSet<string> s_forbiddenTrimmings = new() { "unsigned", "per" };
2121

2222
/// <inheritdoc />
23-
public void Trim(NameTrimmerContext context)
23+
public void ProcessNames(NameProcessorContext context)
2424
{
2525
string? identifiedPrefix = null;
2626
List<AugmentedCandidateNames> localNames = null!;

sources/SilkTouch/SilkTouch/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static ServiceCollectionExtensions()
5555
/// <item><description><see cref="ResponseFileHandler"/></description></item>
5656
/// <item><description><see cref="SilkTouchGenerator"/></description></item>
5757
/// <item><description><see cref="NameTrimmer"/></description></item>
58-
/// <item><description>One or more <see cref="INameTrimmer"/>s</description></item>
58+
/// <item><description>One or more <see cref="INameProcessor"/>s</description></item>
5959
/// <item><description>An appropriate implementation of <see cref="IStdIncludeResolver"/></description></item>
6060
/// <item><description>Mod implementations referenced in the configurations</description></item>
6161
/// <item>

tests/SilkTouch/SilkTouch/Naming/NameTrimmerTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public void SimpleGlfwTestDetermination(string? hint)
2727
GetPrefix(null, hint, test, null, null, false, true)?.Prefix,
2828
Is.EqualTo("GLFW")
2929
);
30-
Trim(
31-
new NameTrimmerContext
30+
ProcessNames(
31+
new NameProcessorContext
3232
{
3333
Configuration = new PrettifyNames.Configuration
3434
{
@@ -66,8 +66,8 @@ public void RegressionFragmentShaderColorModMaskATI()
6666
{ "GL_NEGATE_BIT_ATI", new CandidateNames("GL_NEGATE_BIT_ATI", []) },
6767
{ "GL_BIAS_BIT_ATI", new CandidateNames("GL_BIAS_BIT_ATI", []) },
6868
};
69-
Trim(
70-
new NameTrimmerContext
69+
ProcessNames(
70+
new NameProcessorContext
7171
{
7272
Container = "FragmentShaderColorModMaskATI",
7373
Configuration = new PrettifyNames.Configuration { GlobalPrefixHints = ["gl"] },
@@ -96,8 +96,8 @@ public void RegressionEvalTargetNV()
9696
{ "GL_EVAL_2D_NV", new CandidateNames("GL_EVAL_2D_NV", []) },
9797
{ "GL_EVAL_TRIANGULAR_2D_NV", new CandidateNames("GL_EVAL_TRIANGULAR_2D_NV", []) },
9898
};
99-
Trim(
100-
new NameTrimmerContext
99+
ProcessNames(
100+
new NameProcessorContext
101101
{
102102
Container = "EvalTargetNV",
103103
Configuration = new PrettifyNames.Configuration { GlobalPrefixHints = ["gl"] },
@@ -123,15 +123,15 @@ public void RegressionSingleMemberEnumUsesGlobalPrefixHint()
123123
{
124124
{ "GL_FILL_NV", new CandidateNames("GL_FILL_NV", []) },
125125
};
126-
var ctx = new NameTrimmerContext
126+
var ctx = new NameProcessorContext
127127
{
128128
Configuration = new PrettifyNames.Configuration { GlobalPrefixHints = ["gl"] },
129129
Container = "EvalMapsModeNV",
130130
JobKey = "OpenGL",
131131
Names = names,
132132
};
133133
var uut = new NameTrimmer();
134-
uut.Trim(ctx);
134+
uut.ProcessNames(ctx);
135135
Assert.That(names["GL_FILL_NV"].Primary, Is.EqualTo("FILL_NV"));
136136
}
137137

@@ -142,15 +142,15 @@ public void MultipleGlobalPrefixHints()
142142
{
143143
{ "ALC_CONTEXT_DEBUG_BIT_EXT", new CandidateNames("ALC_CONTEXT_DEBUG_BIT_EXT", []) },
144144
};
145-
var ctx = new NameTrimmerContext
145+
var ctx = new NameProcessorContext
146146
{
147147
Configuration = new PrettifyNames.Configuration { GlobalPrefixHints = ["alc", "al"] },
148148
Container = "ContextFlagsEXT",
149149
JobKey = "OpenAL",
150150
Names = names,
151151
};
152152
var uut = new NameTrimmer();
153-
uut.Trim(ctx);
153+
uut.ProcessNames(ctx);
154154
Assert.That(
155155
names["ALC_CONTEXT_DEBUG_BIT_EXT"].Primary,
156156
Is.EqualTo("CONTEXT_DEBUG_BIT_EXT")

0 commit comments

Comments
 (0)