diff options
Diffstat (limited to 'source/slang/parser.cpp')
| -rw-r--r-- | source/slang/parser.cpp | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 3c879302c..38a28745a 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -4612,8 +4612,6 @@ namespace Slang return modifier; } - - static RefPtr<RefObject> parseLayoutModifier(Parser* parser, void* /*userData*/) { ModifierListBuilder listBuilder; @@ -4653,47 +4651,35 @@ namespace Slang } else { - if (nameText == "push_constant") + RefPtr<Modifier> modifier; + +#define CASE(key, type) if (nameText == #key) { modifier = new type; } else + CASE(push_constant, PushConstantAttribute) + CASE(shaderRecordNV, ShaderRecordAttribute) + CASE(constant_id, GLSLConstantIDLayoutModifier) + CASE(location, GLSLLocationLayoutModifier) + CASE(local_size_x, GLSLLocalSizeXLayoutModifier) + CASE(local_size_y, GLSLLocalSizeYLayoutModifier) + CASE(local_size_z, GLSLLocalSizeZLayoutModifier) { - RefPtr<PushConstantAttribute> modifier(new PushConstantAttribute); - - modifier->name = nameAndLoc.name; - modifier->loc = nameAndLoc.loc; - - listBuilder.add(modifier); + modifier = new GLSLUnparsedLayoutModifier(); } - else - { - RefPtr<GLSLLayoutModifier> modifier; + SLANG_ASSERT(modifier); +#undef CASE - // TODO: better handling of this choice (e.g., lookup in scope) - if(0) {} - #define CASE(KEYWORD, CLASS) \ - else if(nameText == #KEYWORD) modifier = new CLASS() + modifier->name = nameAndLoc.name; + modifier->loc = nameAndLoc.loc; - CASE(constant_id, GLSLConstantIDLayoutModifier); - CASE(location, GLSLLocationLayoutModifier); - CASE(local_size_x, GLSLLocalSizeXLayoutModifier); - CASE(local_size_y, GLSLLocalSizeYLayoutModifier); - CASE(local_size_z, GLSLLocalSizeZLayoutModifier); - CASE(shaderRecordNV, ShaderRecordNVLayoutModifier); - - #undef CASE - else - { - modifier = new GLSLUnparsedLayoutModifier(); - } - - modifier->name = nameAndLoc.name; - modifier->loc = nameAndLoc.loc; - - if(AdvanceIf(parser, TokenType::OpAssign)) + // Special handling for GLSLLayoutModifier + if (auto glslModifier = as<GLSLLayoutModifier>(modifier)) + { + if (AdvanceIf(parser, TokenType::OpAssign)) { - modifier->valToken = parser->ReadToken(TokenType::IntegerLiteral); + glslModifier->valToken = parser->ReadToken(TokenType::IntegerLiteral); } - - listBuilder.add(modifier); } + + listBuilder.add(modifier); } if (AdvanceIf(parser, TokenType::RParent)) |
