Skip to content

Commit dccfa75

Browse files
committed
Add more information to the IdentifySharedPrefixes section
1 parent 3befc1c commit dccfa75

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

docs/for-contributors/Generator/generator-mods.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,33 @@ Mod categories: Metadata, Naming
244244

245245
This mod is designed to handle C-style namespace prefixes where all types, functions, and constants in a library share
246246
a common prefix. This includes casing convention differences. For example, constants often use screaming case while
247-
type and function names use camel case or pascal case.
247+
type and function names use camel case or pascal case. This can be seen in Vulkan, where functions are prefixed with
248+
`vk`, such as in `vkCreateInstance` and `vkCmdBindPipeline`, and constants are prefixed with `VK_`, such as in
249+
`VK_MAX_MEMORY_HEAPS` and `VK_TRUE`.
250+
251+
Furthermore, identification of shared prefixes is done per scope and only in cases where C-style namespace prefixes
252+
might be used. For example, a struct type typically does not use namespace prefixes because the struct itself acts as
253+
a way to disambiguate names contained inside of it. However, C-style enum values are often defined as global constants
254+
using macros such as `#define SDL_BLENDMODE_BLEND_PREMULTIPLIED 0x00000010u`. After these constants are moved to their
255+
corresponding enum types by `ExtractNestedTyping`, `IdentifySharedPrefixes` then handles the identification of the
256+
prefix shared by the enum type's members. In the case of `SDL_BlendMode`, all of the members of `SDL_BlendMode` share
257+
`SDL_BLENDMODE_` as their common prefix.
258+
259+
Note: Despite `VK_` and `SDL_BLENDMODE_` being the "true" shared prefix, `IdentifySharedPrefixes` annotates the
260+
identifier with `VK` and `SDL_BLENDMODE` as the shared prefix, without the trailing underscore. While whether the
261+
inclusion of the underscore can be debated and can subtly affect the bindings output by the generator, this is the
262+
current behavior of `IdentifySharedPrefixes`.
248263

249264
Implementation-wise, this mod's functionality was notably originally part of `PrettifyNames`. In the original form,
250265
`PrettifyNames` handled both the identification of and removal of shared prefixes. This has now been split out to
251266
simplify `PrettifyNames` and to provide better control over how shared prefixes are processed.
252267

253268
Examples for how `IdentifySharedPrefixes` works can be found in the `IdentifySharedPrefixesTests` test cases.
254269

270+
The [Name Processing](name-processing.md) documentation also covers `IdentifySharedPrefixes` to a limited extent,
271+
notably relating to how existing name affixes are treated in the
272+
[IdentifySharedPrefixes and Name Affixes](name-processing.md#identifysharedprefixes-and-name-affixes) section.
273+
255274
Name affix categories:
256275

257276
- `SharedPrefix` - This is a prefix that represents the shared prefix that is identified for a group of names. Silk's
@@ -280,6 +299,10 @@ This mod should be used when the transformation of C-style namespace prefixes or
280299
The most common case of this is the removal of such prefixes by using `IdentifySharedPrefixes` before `PrettifyNames`.
281300
`PrettifyNames` can then be configured like above to remove or use shared prefixes as discriminators.
282301

302+
This mod also interacts with `ExtractNestedTyping`, which moves constants that are identified as likely being part of
303+
an enum to the corresponding enum. As such, this `IdentifySharedPrefixes` should be positioned after
304+
`ExtractNestedTyping` in the mod order.
305+
283306
### InterceptNativeFunctions
284307

285308
Mod categories: Transformation

0 commit comments

Comments
 (0)