diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-08-12 14:43:25 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-08-12 14:50:01 -0700 |
| commit | f1bda6ada269716dd28653222a10d2c11dd052c5 (patch) | |
| tree | 63fdd927ca39462176d506ea7bb99a5b8b8bfa87 /source/slang/slang-stdlib.cpp | |
| parent | 495f88167527945e680e091d49b5705f5f1af1f9 (diff) | |
Data-driven parsing of modifiers
Just like the previous change did for declaration keywords, this change uses the lexical environment to drive the lookup and dispatch of modifier parsing.
This allows us to easily add modifiers to Slang, even when they might conflict with identifiers used in user code (because the modifier names are no longer special keywords, but ordinary identifiers).
There was already some support for ideas like this with `__modifier` declarations (`ModifierDecl`) used to introduce some GLSL-specific keywords (so that they wouldn't pollute the namespace of HLSL files).
The new approach changes these to be actual `syntax` declarations (`SyntaxDecl`) with the same representation as those used to introduce declaration keywords.
Because many modifiers just introduce a single keyword that maps to a simple AST node (no further tokens/data), I modified the handling of syntax declarations so that they can take a user-data parameter, and this allows the common case ("just create an AST node of this type...") to be handled with minimal complications.
This also adds in a general-purpose string-based lookup path for AST node classes, that should support programmatic creation in more cases.
Statements are now the main case of keywords that need to be made table driven.
Diffstat (limited to 'source/slang/slang-stdlib.cpp')
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 71e8a6621..3ec8b9db4 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -2232,19 +2232,19 @@ namespace Slang // Define additional keywords - sb << "__modifier(GLSLBufferModifier) buffer;\n"; + sb << "syntax buffer : GLSLBufferModifier;\n"; // [GLSL 4.3] Storage Qualifiers // TODO: need to support `shared` here with its GLSL meaning - sb << "__modifier(GLSLPatchModifier) patch;\n"; + sb << "syntax patch : GLSLPatchModifier;\n"; // `centroid` and `sample` handled centrally // [GLSL 4.5] Interpolation Qualifiers - sb << "__modifier(SimpleModifier) smooth;\n"; - sb << "__modifier(SimpleModifier) flat;\n"; - sb << "__modifier(SimpleModifier) noperspective;\n"; + sb << "syntax smooth : SimpleModifier;\n"; + sb << "syntax flat : SimpleModifier;\n"; + sb << "syntax noperspectie : SimpleModifier;\n"; // [GLSL 4.3.2] Constant Qualifier @@ -2253,24 +2253,24 @@ namespace Slang // since they mean such different things. // [GLSL 4.7.2] Precision Qualifiers - sb << "__modifier(SimpleModifier) highp;\n"; - sb << "__modifier(SimpleModifier) mediump;\n"; - sb << "__modifier(SimpleModifier) lowp;\n"; + sb << "syntax highp : SimpleModifier;\n"; + sb << "syntax mediump : SimpleModifier;\n"; + sb << "syntax lowp : SimpleModifier;\n"; // [GLSL 4.8.1] The Invariant Qualifier - sb << "__modifier(GLSLWriteOnlyModifier) invariant;\n"; + sb << "syntax invariant : SimpleModifier;\n"; // [GLSL 4.10] Memory Qualifiers - sb << "__modifier(SimpleModifier) coherent;\n"; - sb << "__modifier(SimpleModifier) volatile;\n"; - sb << "__modifier(SimpleModifier) restrict;\n"; - sb << "__modifier(GLSLReadOnlyModifier) readonly;\n"; - sb << "__modifier(GLSLWriteOnlyModifier) writeonly;\n"; + sb << "syntax coherent : SimpleModifier;\n"; + sb << "syntax volatile : SimpleModifier;\n"; + sb << "syntax restrict : SimpleModifier;\n"; + sb << "syntax readonly : GLSLReadOnlyModifier;\n"; + sb << "syntax writeonly : GLSLWriteOnlyModifier;\n"; - // We will treat `subroutine` as a qualifier - sb << "__modifier(SimpleModifier) subroutine;\n"; + // We will treat `subroutine` as a qualifier for now + sb << "syntax subroutine : SimpleModifier;\n"; glslLibraryCode = sb.ProduceString(); return glslLibraryCode; |
