Repository navigation
Expand file tree
/
Copy pathGeneratedNames.cs
More file actions
57 lines (52 loc) Β· 2.74 KB
/
Copy pathGeneratedNames.cs
File metadata and controls
57 lines (52 loc) Β· 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace Ruri.ShaderTools;
/// <summary>
/// Names this pipeline INVENTS, as opposed to names it recovers.
///
/// They live at the root because three unrelated layers need the same strings:
/// the layout builder that creates such members, the naming layer that assigns
/// them, and the source adapter that explains them to whoever opens the file. A
/// literal duplicated across those layers would drift, and the moment the
/// adapter's copy stops matching, the generated file silently loses its legend.
///
/// Every one of these reads as a STATEMENT rather than as an identifier. That is
/// the whole design rule: a reader who has never seen this codebase β a person
/// months later, or a model given only the file β must be able to tell at a
/// glance that the name was manufactured, and why. A terse placeholder like
/// <c>f_2032</c> fails that test; it looks exactly like a real author name, gets
/// quoted as one, and sends people hunting for a CPU-side property that was
/// never there.
/// </summary>
internal static class GeneratedNames
{
/// <summary>
/// A member whose name did not survive compilation. Always followed by
/// <c>_<byteOffset></c> β the member's only surviving identity, and what
/// any future symbol source would be matched on.
/// </summary>
public const string StrippedSymbol = "Stripped";
/// <summary>
/// A block that could not be split into members at all; the single member
/// spans the whole buffer. Distinct from <see cref="StrippedSymbol"/> because
/// it reports a different fact β nothing was stripped, the structuring simply
/// did not happen.
/// </summary>
public const string UnstructuredBlock = "Unstructured";
/// <summary>
/// A byte range no symbol describes at all, bridged so the members around it
/// could still be named. Deduplication appends <c>_at_<byteOffset></c>
/// when a block contains several.
/// </summary>
public const string UnmappedRegion = "Unmapped";
/// <summary>
/// Whether a member name is one of these markers rather than a recovered
/// symbol. Every marker is the bare word or the word followed by an
/// underscore and its qualifier, so an authored name that merely begins with
/// the same letters is not mistaken for one.
/// </summary>
public static bool IsGenerated(string name)
=> Matches(name, StrippedSymbol) || Matches(name, UnstructuredBlock) || Matches(name, UnmappedRegion);
private static bool Matches(string name, string marker)
=> name.Length == marker.Length
? string.Equals(name, marker, StringComparison.Ordinal)
: name.Length > marker.Length && name[marker.Length] == '_' && name.StartsWith(marker, StringComparison.Ordinal);
}