@@ -248,8 +248,6 @@ The use of a *lowercase* x in particular is a stylistic choice and matches names
248248
249249## Name Affixes
250250
251- (TODO: Explain how these actually look in metadata/attribute form)
252-
253251Name prefixes and suffixes are used commonly in both native code and in identifiers created by the SilkTouch generator.
254252
255253For example, in ` VkPresentInfoKHR ` from Vulkan, ` Vk- ` is a namespace prefix commonly used in C code, while ` -KHR ` is a
@@ -267,6 +265,68 @@ Furthermore, because each category of affix can be identified by different mods,
267265identification process localized to the mod that specializes in that area. For example, C-style namespace prefixes
268266are handled by ` IdentifySharedPrefixes ` .
269267
268+ ### Name Affixes - Metadata Format
269+
270+ The name affixes for a corresponding identifier are stored as C# attributes declared on that identifier. This takes
271+ advantage of the fact that the SilkTouch generator is designed such that mods primarily take Roslyn syntax trees as
272+ input and return new syntax trees as output.
273+
274+ For example, from the OpenGL bindings:
275+ ``` cs
276+ public enum InternalFormat
277+ {
278+ [NameAffix (" Prefix" , " SharedPrefix" , " GL" )]
279+ [NameAffix (" Suffix" , " KhronosVendor" , " ARB" )]
280+ GL_RGBA32F_ARB = 34836 ,
281+ }
282+ ```
283+
284+ In order, the parameters are:
285+
286+ 1 . Affix type - Either "Prefix" or "Suffix".
287+ 2 . Affix category - Used to identify the purpose or source of that affix.
288+ - ` PrettifyNames ` can be configured to process different affix categories in different ways. For example,
289+ shared prefixes can be removed by targeting the ` SharedPrefix ` category.
290+ 3 . Affix value - The affix as it appears in the identifier.
291+ - Note: Currently, affixes need to verbatim match the part of the identifier they represent. For example, stripping
292+ ` GL_RGBA32F_ARB ` of the ` GL- ` prefix leads to ` _RGBA32F_ARB ` , while ` GL_- ` will lead to ` RGBA32F_ARB ` . Despite
293+ this, the codebase is written to not include the underscore since it currently does not affect the output and is
294+ arguably cleaner to avoid leading or trailing underscores in affix values. If this does prove to be a problem,
295+ prefer updating the affix stripping code to be tolerant of extra underscores.
296+
297+ These parameters are all strings for simplicity when parsing.
298+
299+ However, as a user of the name affix system, the utilities provided by ` NameAffixer ` should provide everything necessary
300+ for interacting with name affixes without interacting with the exact syntax node representation.
301+
302+ ### Name Affixes - Notable Interactions
303+
304+ #### IdentifySharedPrefixes and Name Affixes
305+
306+ ` IdentifySharedPrefixes ` strips affixes before identifying shared prefixes. Therefore, names like ` ID3D12Device ` will
307+ appear as ` D3D12Device ` if the ` I- ` prefix is identified beforehand.
308+
309+ #### Deferring Renames
310+
311+ Renames that involve the addition of affixes can be done simply by adding the affix to the name, assuming that
312+ ` PrettifyNames ` runs afterward. This is preferable because it avoids a project-wide symbol search to locate and update
313+ where that identifier is used.
314+
315+ This is because stripping affixes is tolerant of missing affixes and affixes reapplication will then add the newly
316+ declared affix to the final name.
317+
318+ For example, the ` -Handle ` suffix is added by ` TransformHandles ` . This leads to syntax that looks like:
319+ ``` cs
320+ [NameAffix (" Suffix" , " HandleType" , " Handle" )]
321+ public struct Buffer ;
322+ ```
323+
324+ Even though ` Buffer ` does not have a ` -Handle ` suffix, it will have it after ` PrettifyNames ` executes. This is assuming
325+ that ` PrettifyNames ` is not configured to remove it.
326+
327+ The removal of affixes can be done similarly, but will involve updating the generator config so that ` PrettifyNames `
328+ removes the affix.
329+
270330### Referenced Affixes
271331
272332(TODO: Explain how these actually look in metadata/attribute form)
0 commit comments