Skip to content

Commit 9d21e44

Browse files
authored
[3.0] Rework naming system (#2565)
* Update OpenAL name overrides to match the 2 character acronym threshold used by other bindings The default acronym threshold was changed during Exanite#29, which was merged as part of #2503. * Start of feature/nested-struct-name-affixes branch * Cleanup leftover return statement * Split TransformHandles into two mods * Rename UseDSL to UseDsl Considering we decided to follow Microsoft's Framework Design Guidelines (acronym threshold of 2) for the bindings and rest of the API, might as well be consistent here. * Cleanup unused property in TransformHandles * Cleanup usages of redundant collections expressions in TransformHandles * Add NameAffixer.AddResolvedNameAffix() for handling compound names * Use AddResolvedNameAffix for extracted function pointer delegate types * Use AddResolvedNameAffix for extracted nested structs and remove name separation hack (no longer necessary) * Rename resolved affix to referenced affix and add parsing code for referenced affixes * Add extra ConsecutiveNumbers test case documenting that Xs between numbers are normalized * Fix incorrect declarationOrder implementation * Change Prettify to not prefix identifiers starting with numbers This lets us handle prefixing and prettification separately, which notably is important if we add prefixes after prettification. We want to prefix the final name, not the intermediate name in this case. * Change the list and order of INameTrimmers used to be statically configured (cherry picked from commit bc94260) * Replace now outdated comment * Move PrettifyNamesTrimmer higher up in the class to make it more obvious that it is not the last trimmer * Remove INameTrimmer.Version This no longer makes sense to keep and enabling features by baseline version seems fiddly. If we need to toggle features for newer versions, we can explicitly add a boolean config option. * Add PrefixIfStartsWithNumberTrimmer * Remove TrimmerBaseline config option * Rename INameTrimmer to INameProcessor and update rest of codebase * Simplify name affixer name processor names to be StripAffixesNameProcessor and ReapplyAffixesNameProcessor * Shorten names a bit more for readability * Decide to only support references within the same scope depth Kinda a cop out decision, but it keeps thing simple (and thus maintainable) and implementing it fully seems overkill for what we need. * Restrict feature set of AddReferencedNameAffix even more for simplicity * Implement referenced affixes and change how -Delegate types generated for function pointer types are named * Update OpenAL name overrides in generator.json This is because we no longer output the separating underscore in ExtractNestedTyping * Update doc comment in ServiceCollectionExtensions to indicate removal of INameTrimmer registrations * Update name overrides for OpenAL to match new Delegate type naming convention Note that the goal is to eventually remove the name overrides for the `EFXEAXREVERBPROPERTIESflLateReverbPan` and `-Delegate` cases entirely. This is because these are theoretically possible to handle automatically and the reason it doesn't work is due to an edge case interaction with the name override system. See the "Tasks" section here for more info: #2555 * Optimize comparison by hoisting the calculation * Add topological sort to ReapplyAffixesProcessor This covers cases where there are multiple levels of nested structs, such as in SDL: GamepadBinding contains GamepadBindingInput which contains GamepadBindingInputAxis * Improve error handling by checking for case where dependencies are not fully fulfilled * Edit error message * Add test: PrettifyNamesTests.SuccessfullyUsesReferencedAffixes * Use "SDL.gen.cs" for test document name This is just to hint that these structs come from SDL * Add tests for referenced affix behavior MissingReferencedAffix_Throws currently fails, but seems to be an unrelated issue. * Alphabetically sort the mod names * Add start of IdentifySharedPrefixes mod * Work on IdentifySharedPrefixes * Remove ApplyPrettifyOnlyPipeline * Rename BreakIntoWords as SplitIntoWords * Remove the double legacy NameTrimmers * Fix compile errors * Temporary: Disable all mods after PrettifyNames * Add SharedPrefix affix config to Vulkan job * Remove unused isContainer param from GetTrimmingName * Work on IdentifySharedPrefixes * Replace regex based NameUtils.LenientUnderscore() with NameSplitter.Underscore() * Fix compile errors due to changes * Remove NonDeterminant/Transformed attribute handling from PrettifyNames * Slightly simplify NameTrimmer * Remove NameTrimmer usage from ExtractNestedTyping and slightly optimize the foreach loops * Slightly cleanup NameTrimmer * Annotate the param names for NameTrimmer's GetPrefix call for readability * Implement visitor for IdentifySharedPrefixes * Properly store scopes * Handle filtering of non C-prefixed names * Work on migrating the NameTrimmer code over to IdentifySharedPrefixes * Cleanup * Add affix handling to IdentifySharedPrefixes * Implement shared prefix identification output to name affixes * Fix incorrect Rewriter implementation * Simplify code * Add missing ModConfiguration attribute * Fix incorrect method call * Fix incorrect member name output for identified prefixes * Fix duplicate key exception caused by functions being able to have duplicate names * Revert "Temporary: Disable all mods after PrettifyNames" This reverts commit 3ec90a7. * Update generator config for OpenAL, OpenGL, and SDL to use IdentifySharedPrefixes * Add another test case as an example of how "2D" is split * Add another prefix override for SeparableTargetEXT This is because 2D isn't trimmed properly by my new name splitter, but I decided that this case was not worth handling in favor of keeping the trimming code simple. See my thoughts here: https://discord.com/channels/521092042781229087/1485943448069738608/1489457083857506336 * Migrate over most prefix trimming/identification tests from PrettifyNamesTests to IdentifySharedPrefixesTests * Update PrettifyNamesTests now that prefix identification is done separately * Migrate over the NameTrimmerTests * Remove IdentifiesSharedPrefix_WhenPrefixesDeclared See #2557 for full reasoning, but the short is that this edge case is purely theoretical and can be handled later on when actually necessary. * Also remove the snapshot for IdentifiesSharedPrefix_WhenPrefixesDeclared * Change INameProcessor to be private to PrettifyNames * Change nPasses to be a class constant to allow usage of doc comments * Rename _forbiddenTrimmings to _forbiddenPrefixes and adjust docs * Change GetPrefix to use a non-null scope parameter for consistency * Add comment explaining why the topological sort exists * Begin replacing the "container" terminology with "scope" * Fix failing tests since the global scope is now represented with an empty string instead of null * Cleanup IdentifySharedPrefixes * Combine EnumInProgress with TypeInProgress * Simplify affix data storage and retrieval * Update docs for Visitor.AffixData * Edit docs for IdentifySharedPrefixes * Swap parameter order on ReportName in IdentifySharedPrefixes * Rewrite PrettifyNames.Visitor to match IdentifySharedPrefixes.Visitor This reduces the amount of code by ~100 lines (1331 -> 1227 lines), which is pretty significant. * Reorder PrettifyNames.Configuration members to improve scannability * Begin rewriting the name processing part of PrettifyNames.ExecuteAsync * Adjust error message for cycle detection * Fix missing method declaration data * Fix missing name data * Add todos and work on updating docs * Change code and comments to refer to trimming names as original names (and some other cleanup) * Move CandidateNames into PrettifyNames * Fix typo * Rename DiscrimStr to GetMethodDiscriminator * Cleanup naming * Use if statements instead of ternaries for populating dictionaries If statements are generally easier to read and debug for this. That said, I do find the original ternary approach better for the method discriminator tuple case, but I decided to use it for all 3 cases for consistency. * Update name conflict resolution code to account for non-method and method names being mixed together now * Add another todo * Change NameProcessorContext to be a class * Begin exposing the entire set of names to name processors and rewriting the rest of the pipeline as INameProcessors * Roughly outline the final implementation and move code to where it roughly belongs * Define name processor inputs * Also provide affix config to ReapplyAffixesProcessor * Implement HandleOverridesProcessor * Cleanup NameProcessorContext * Remove helper data retrieval methods from ScrapedNameData since it can lead to inefficient data access * Remove ScrapedNameData since it's now just an empty wrapper class * Reimplement StripAffixesProcessor * Reimplement PrettifyProcessor * Reimplement ReapplyAffixesProcessor * Reimplement PrefixIfStartsWithNumberProcessor * Edit documentation and add RemoveUnmodifiedFinalNamesProcessor * Add docs for PrefixIfStartsWithNumberProcessor * Implement ResolveConflictsProcessor using adapted name conflict resolution code * Add remark doc comment on ResolveConflictsProcessor about it copying names from the final to working set * Add NameSymbolVisitor for gathering symbols to rename * Add remark comment on nested type support in PrettifyNames * Fix constructors not getting renamed * Add PrettifyNamesTests.ConflictsAreResolved_ForMethodsAndConstants (currently fails) * Work on non-method/method conflict resolution * Also add test case: ConflictsAreResolved_ForMethodsAndConstants_WithAdditionalDiscriminatorAffixes * Ensure conflicts are iterated deterministically This wasn't an actual observed issue, but is a possible edge case I noticed when I was reading the code. The underlying data collection is a hashset or dictionary, both of which have non-deterministic iteration order. This commit adds a tie-breaker to prevent this issue from possibly happening. * Add ConflictsAreResolved_ForMethodsAndConstants_WithAdditionalDiscriminatorAffixes_ReversedPriority and add more comments on why the tests exist * Implement non-method/method conflict resolution and fix secondaries not getting chosen properly * Ensure that the temporary data collections are allocated once and edit comments/variable names to be clearer * Implement "-Value" suffixing for non-methods conflicting with methods and update test cases to reflect expected behavior * Decide it's not worth implementing cross-scope name referencing for affixes yet * Remove unused RenamedType struct and unused MemberData.Name property * Fix -Value suffixing not working properly I expected this to be an issue *eventually*, but apparently it also affects the SDL output already. This is probably because SDL has multiple overloads of the SDL_main method, which my test case does not test for. * Update test snapshot This new snapshot matches the expected output that I wrote in the comments earlier. I just forgot to update the snapshot. * Also resolve referenced affixes from the final set of names and the OpenAL overrides that are now unnecessary * Add ReapplyAffixesProcessor.TryResolveName method (refactor) * Change ReapplyAffixesProcessor to use one global topological sort and update test to indicate that one level of scoping is now supported * Fix issue where overrides break the topological sort * Reorder tests in file * Add test case: SuccessfullyUsesReferencedAffixes_WhenOverridden * Rename NameProcessorContext/NameDataVisitor.Scopes to Names * Work on refactoring name affix processors * Add local OutputName function * Implement the option to prettify individual affixes * Update generator config now that affixes are prettified by default * Don't prettify referenced affixes by default since we usually want the verbatim value of the referenced name * Change affixes to not be prettified by default since it simplifies the code and config * Empty commit * Update snapshot to match expected stated by comment * Adjust doc comment wording for IdentifySharedPrefixes._passCount
1 parent e726bb2 commit 9d21e44

148 files changed

Lines changed: 3696 additions & 2777 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.silktouch/openal-clangsharp.stout

0 Bytes
Binary file not shown.

.silktouch/vulkan-clangsharp.stout

0 Bytes
Binary file not shown.

generator.json

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@
4242
"AddIncludes",
4343
"ClangScraper",
4444
"MarkNativeNames",
45+
"ExtractHandles",
4546
"ExtractNestedTyping",
4647
"TransformHandles",
4748
"TransformFunctions",
4849
"TransformProperties",
50+
"IdentifySharedPrefixes",
4951
"PrettifyNames",
5052
"TransformEnums",
5153
"AddVTables",
@@ -59,17 +61,23 @@
5961
"InputTestRoot": "tests/SDL"
6062
},
6163
"TransformHandles": {
62-
"AssumeMissingTypesOpaque": true,
63-
"UseDSL": true
64+
"UseDsl": true
6465
},
6566
"TransformFunctions": {
6667
"BoolTypes": {
6768
"SDL_bool": null
6869
}
6970
},
70-
"PrettifyNames": {
71+
"IdentifySharedPrefixes": {
7172
"GlobalPrefixHints": ["SDL"]
7273
},
74+
"PrettifyNames": {
75+
"Affixes": {
76+
"SharedPrefix": {
77+
"Remove": true
78+
}
79+
}
80+
},
7381
"TransformEnums": {
7482
"AddNoneMemberToFlags": true,
7583
"RewriteMemberValues": true
@@ -95,6 +103,7 @@
95103
"MixKhronosData",
96104
"AddOpaqueStructs",
97105
"TransformFunctions",
106+
"IdentifySharedPrefixes",
98107
"PrettifyNames",
99108
"TransformEnums",
100109
"AddVTables",
@@ -171,14 +180,17 @@
171180
}
172181
]
173182
},
174-
"PrettifyNames": {
183+
"IdentifySharedPrefixes": {
175184
"GlobalPrefixHints": ["gl"],
176185
"PrefixOverrides": {
177186
"SyncObjectMask": "GL_SYNC",
178187
"OcclusionQueryParameterNameNV": "GL",
179188
"TexStorageAttribs": "GL",
180-
"ContainerType": "GL"
181-
},
189+
"ContainerType": "GL",
190+
"SeparableTargetEXT": "GL"
191+
}
192+
},
193+
"PrettifyNames": {
182194
"Affixes": {
183195
"HandleType": {
184196
"Order": 1
@@ -197,6 +209,9 @@
197209
},
198210
"KhronosNonExclusiveVendor": {
199211
"Remove": true
212+
},
213+
"SharedPrefix": {
214+
"Remove": true
200215
}
201216
}
202217
},
@@ -228,10 +243,12 @@
228243
"ChangeNativeClass",
229244
"AddApiProfiles",
230245
"MixKhronosData",
246+
"ExtractHandles",
231247
"ExtractNestedTyping",
232248
"TransformHandles",
233249
"InterceptNativeFunctions",
234250
"TransformFunctions",
251+
"IdentifySharedPrefixes",
235252
"PrettifyNames",
236253
"TransformEnums",
237254
"AddVTables",
@@ -294,25 +311,20 @@
294311
}
295312
]
296313
},
314+
"IdentifySharedPrefixes": {
315+
"GlobalPrefixHints": ["alc", "al"]
316+
},
297317
"PrettifyNames": {
298-
"GlobalPrefixHints": ["alc", "al"],
299318
"NameOverrides": {
300319
"ALContext": "ALContext",
301320
"EFXEAXREVERBPROPERTIES": "EfxEaxReverbProperties",
302-
"EFXEAXREVERBPROPERTIES_flReflectionsPan": "EfxEaxReverbPropertiesFlReflectionsPan",
303-
"EFXEAXREVERBPROPERTIES_flLateReverbPan": "EfxEaxReverbPropertiesFlLateReverbPan",
304321
"ALCcontextHandle": "ContextHandle",
305322
"ALCdeviceHandle": "DeviceHandle",
306323
"ALBUFFERCALLBACKTYPESOFT": "BufferCallbackSOFT",
307-
"ALBUFFERCALLBACKTYPESOFTDelegate": "BufferCallbackDelegateSOFT",
308324
"ALCEVENTPROCTYPESOFT": "ContextEventProcSOFT",
309-
"ALCEVENTPROCTYPESOFTDelegate": "ContextEventProcDelegateSOFT",
310325
"ALEVENTPROCSOFT": "EventProcSOFT",
311-
"ALEVENTPROCSOFTDelegate": "EventProcDelegateSOFT",
312326
"ALDEBUGPROCEXT": "DebugProcEXT",
313-
"ALDEBUGPROCEXTDelegate": "DebugProcDelegateEXT",
314-
"LPALFOLDBACKCALLBACK": "FoldbackCallback",
315-
"LPALFOLDBACKCALLBACKDelegate": "FoldbackCallbackDelegate"
327+
"LPALFOLDBACKCALLBACK": "FoldbackCallback"
316328
},
317329
"Affixes": {
318330
"HandleType": {
@@ -332,6 +344,9 @@
332344
},
333345
"KhronosNonExclusiveVendor": {
334346
"Remove": true
347+
},
348+
"SharedPrefix": {
349+
"Remove": true
335350
}
336351
}
337352
},
@@ -347,8 +362,7 @@
347362
"BenefitOfTheDoubtArrayTransformation": true
348363
},
349364
"TransformHandles": {
350-
"AssumeMissingTypesOpaque": true,
351-
"UseDSL": true
365+
"UseDsl": true
352366
},
353367
"StripAttributes": {
354368
"Remove": [
@@ -366,13 +380,15 @@
366380
"AddIncludes",
367381
"ClangScraper",
368382
"MarkNativeNames",
383+
"ExtractHandles",
369384
"ExtractNestedTyping",
370385
"TransformHandles",
371386
"MixKhronosData",
372387
"AddApiProfiles",
373388
"InterceptNativeFunctions",
374389
"TransformFunctions",
375390
"TransformProperties",
391+
"IdentifySharedPrefixes",
376392
"PrettifyNames",
377393
"TransformEnums",
378394
"AddVTables",
@@ -419,15 +435,16 @@
419435
}
420436
},
421437
"TransformHandles": {
422-
"AssumeMissingTypesOpaque": true,
423-
"UseDSL": true
438+
"UseDsl": true
424439
},
425-
"PrettifyNames": {
426-
"GlobalPrefixHints": ["PFN_vk","vk"],
440+
"IdentifySharedPrefixes": {
441+
"GlobalPrefixHints": ["PFN_vk", "vk"],
427442
"PrefixOverrides": {
428443
"VkPipelineCreateFlags2": "VK_PIPELINE_CREATE_2",
429444
"VkMemoryDecompressionMethodFlagsEXT": "VK_MEMORY_DECOMPRESSION_METHOD"
430-
},
445+
}
446+
},
447+
"PrettifyNames": {
431448
"NameOverrides": {
432449
"numAABBs": "NumAabbs"
433450
},
@@ -446,6 +463,9 @@
446463
},
447464
"KhronosHandleType": {
448465
"Remove": true
466+
},
467+
"SharedPrefix": {
468+
"Remove": true
449469
}
450470
}
451471
},

sources/OpenAL/OpenAL/al/BufferCallbackSOFT.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Silk.NET.OpenAL;
1919

2020
public BufferCallbackSOFT(delegate* unmanaged<void*, void*, int, int> ptr) => Pointer = ptr;
2121

22-
public BufferCallbackSOFT(BufferCallbackDelegateSOFT proc) =>
22+
public BufferCallbackSOFT(BufferCallbackSOFTDelegate proc) =>
2323
Pointer = SilkMarshal.DelegateToPtr(proc);
2424

2525
public void Dispose() => SilkMarshal.Free(Pointer);

sources/OpenAL/OpenAL/al/BufferCallbackDelegateSOFT.gen.cs renamed to sources/OpenAL/OpenAL/al/BufferCallbackSOFTDelegate.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
namespace Silk.NET.OpenAL;
1212

1313
[NativeName("ALBUFFERCALLBACKTYPESOFT")]
14-
public unsafe delegate int BufferCallbackDelegateSOFT(void* arg0, void* arg1, int arg2);
14+
public unsafe delegate int BufferCallbackSOFTDelegate(void* arg0, void* arg1, int arg2);

sources/OpenAL/OpenAL/al/ContextEventProcSOFT.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ContextEventProcSOFT(
2121
delegate* unmanaged<int, int, DeviceHandle, int, sbyte*, void*, void> ptr
2222
) => Pointer = ptr;
2323

24-
public ContextEventProcSOFT(ContextEventProcDelegateSOFT proc) =>
24+
public ContextEventProcSOFT(ContextEventProcSOFTDelegate proc) =>
2525
Pointer = SilkMarshal.DelegateToPtr(proc);
2626

2727
public void Dispose() => SilkMarshal.Free(Pointer);

sources/OpenAL/OpenAL/al/ContextEventProcDelegateSOFT.gen.cs renamed to sources/OpenAL/OpenAL/al/ContextEventProcSOFTDelegate.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Silk.NET.OpenAL;
1212

1313
[NativeName("ALCEVENTPROCTYPESOFT")]
14-
public unsafe delegate void ContextEventProcDelegateSOFT(
14+
public unsafe delegate void ContextEventProcSOFTDelegate(
1515
int arg0,
1616
int arg1,
1717
DeviceHandle arg2,

sources/OpenAL/OpenAL/al/DebugProcEXT.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Silk.NET.OpenAL;
2020
public DebugProcEXT(delegate* unmanaged<int, int, uint, int, int, sbyte*, void*, void> ptr) =>
2121
Pointer = ptr;
2222

23-
public DebugProcEXT(DebugProcDelegateEXT proc) => Pointer = SilkMarshal.DelegateToPtr(proc);
23+
public DebugProcEXT(DebugProcEXTDelegate proc) => Pointer = SilkMarshal.DelegateToPtr(proc);
2424

2525
public void Dispose() => SilkMarshal.Free(Pointer);
2626

sources/OpenAL/OpenAL/al/DebugProcDelegateEXT.gen.cs renamed to sources/OpenAL/OpenAL/al/DebugProcEXTDelegate.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Silk.NET.OpenAL;
1212

1313
[NativeName("ALDEBUGPROCEXT")]
14-
public unsafe delegate void DebugProcDelegateEXT(
14+
public unsafe delegate void DebugProcEXTDelegate(
1515
int arg0,
1616
int arg1,
1717
uint arg2,

sources/OpenAL/OpenAL/al/EventProcSOFT.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Silk.NET.OpenAL;
2020
public EventProcSOFT(delegate* unmanaged<int, uint, uint, int, sbyte*, void*, void> ptr) =>
2121
Pointer = ptr;
2222

23-
public EventProcSOFT(EventProcDelegateSOFT proc) => Pointer = SilkMarshal.DelegateToPtr(proc);
23+
public EventProcSOFT(EventProcSOFTDelegate proc) => Pointer = SilkMarshal.DelegateToPtr(proc);
2424

2525
public void Dispose() => SilkMarshal.Free(Pointer);
2626

0 commit comments

Comments
 (0)