Commit b323afd
authored
Improve
This PR improves the logic around how valid names are generated with consideration for reserved words defined in specific Syntax objects.
Currently the shader generator calls `Syntax::makeIdentifier()` to ensure that variable names are legal. This compares the current name against a map of already used identifiers. The reserved words for a syntax are prepopulated in this map.
There are some places, namely [here](https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/source/MaterialXGenShader/Nodes/CompoundNode.cpp#L40) and [here](https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp#L70), where we generate names that need to be legal, but do not call `makeIdentifier()` but instead just call `makeValidName()`. Which got me to thinking that make `makeValidName()` should be doing the reserved word check.
Moving the check to `makeValidName()` means we do not have to copy all of the reserved words in to the identifier map for each `ShaderGraph` object we create, as well as plugging the potential bug of being able to generate illegal function names.Syntax::makeValidName function (#2598)1 parent 3435676 commit b323afd
2 files changed
Lines changed: 7 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 25 | | |
31 | 26 | | |
32 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
156 | 162 | | |
157 | 163 | | |
158 | 164 | | |
| |||
0 commit comments