From f1bda6ada269716dd28653222a10d2c11dd052c5 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sat, 12 Aug 2017 14:43:25 -0700 Subject: 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. --- source/slang/modifier-defs.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'source/slang/modifier-defs.h') diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h index 5bab29aba..b007b3296 100644 --- a/source/slang/modifier-defs.h +++ b/source/slang/modifier-defs.h @@ -35,34 +35,34 @@ END_SYNTAX_CLASS() // directly. SYNTAX_CLASS(IntrinsicOpModifier, IntrinsicModifierBase) - // token that names the intrinsic op - FIELD(Token, opToken) +// token that names the intrinsic op +FIELD(Token, opToken) - // The opcode for the intrinsic operation - FIELD_INIT(IntrinsicOp, op, IntrinsicOp::Unknown) +// The opcode for the intrinsic operation +FIELD_INIT(IntrinsicOp, op, IntrinsicOp::Unknown) END_SYNTAX_CLASS() // A modifier that marks something as an intrinsic function, // for some subset of targets. SYNTAX_CLASS(TargetIntrinsicModifier, IntrinsicModifierBase) - // Token that names the target that the operation - // is an intrisic for. - FIELD(Token, targetToken) +// Token that names the target that the operation +// is an intrisic for. +FIELD(Token, targetToken) - // A custom definition for the operation - FIELD(Token, definitionToken) +// A custom definition for the operation +FIELD(Token, definitionToken) END_SYNTAX_CLASS() // A modifier to tag something as an intrinsic that requires // a certain GLSL extension to be enabled when used SYNTAX_CLASS(RequiredGLSLExtensionModifier, Modifier) - FIELD(Token, extensionNameToken) +FIELD(Token, extensionNameToken) END_SYNTAX_CLASS() // A modifier to tag something as an intrinsic that requires // a certain GLSL version to be enabled when used SYNTAX_CLASS(RequiredGLSLVersionModifier, Modifier) - FIELD(Token, versionNumberToken) +FIELD(Token, versionNumberToken) END_SYNTAX_CLASS() SIMPLE_SYNTAX_CLASS(InOutModifier, OutModifier) @@ -95,12 +95,18 @@ SIMPLE_SYNTAX_CLASS(SharedModifiers, Modifier) // different constructs. ABSTRACT_SYNTAX_CLASS(GLSLLayoutModifier, Modifier) - // The token used to introduce the modifier is stored - // as the `nameToken` field. +// The token used to introduce the modifier is stored +// as the `nameToken` field. + +// TODO: may want to accept a full expression here +FIELD(Token, valToken) +END_SYNTAX_CLASS() - // TODO: may want to accept a full expression here - FIELD(Token, valToken) +// AST nodes to represent the begin/end of a `layout` modifier group +ABSTRACT_SYNTAX_CLASS(GLSLLayoutModifierGroupMarker, Modifier) END_SYNTAX_CLASS() +SIMPLE_SYNTAX_CLASS(GLSLLayoutModifierGroupBegin, GLSLLayoutModifierGroupMarker) +SIMPLE_SYNTAX_CLASS(GLSLLayoutModifierGroupEnd, GLSLLayoutModifierGroupMarker) // We divide GLSL `layout` modifiers into those we have parsed // (in the sense of having some notion of their semantics), and -- cgit v1.2.3