diff --git a/src/sksl/SkSLDSLParser.cpp b/src/sksl/SkSLDSLParser.cpp index 1ff1ebf2e1..f7c87636a1 100644 --- a/src/sksl/SkSLDSLParser.cpp +++ b/src/sksl/SkSLDSLParser.cpp @@ -212,6 +212,17 @@ bool DSLParser::expectIdentifier(Token* result) { return true; } +bool DSLParser::checkIdentifier(Token* result) { + if (!this->checkNext(Token::Kind::TK_IDENTIFIER, result)) { + return false; + } + if (IsBuiltinType(this->text(*result))) { + this->pushback(std::move(*result)); + return false; + } + return true; +} + skstd::string_view DSLParser::text(Token token) { return skstd::string_view(fText->data() + token.fOffset, token.fLength); } @@ -645,9 +656,9 @@ SkTArray DSLParser::structVarDeclaration(const DSLModifiers& return {}; } Token name; - if (this->checkNext(Token::Kind::TK_IDENTIFIER, &name)) { + if (this->checkIdentifier(&name)) { this->globalVarDeclarationEnd(this->position(name), modifiers, std::move(*type), - this->text(name)); + this->text(name)); } else { this->expect(Token::Kind::TK_SEMICOLON, "';'"); } @@ -901,7 +912,7 @@ bool DSLParser::interfaceBlock(const dsl::DSLModifiers& modifiers) { skstd::string_view instanceName; Token instanceNameToken; SKSL_INT arraySize = 0; - if (this->checkNext(Token::Kind::TK_IDENTIFIER, &instanceNameToken)) { + if (this->checkIdentifier(&instanceNameToken)) { instanceName = this->text(instanceNameToken); if (this->checkNext(Token::Kind::TK_LBRACKET)) { arraySize = this->arraySize(); diff --git a/src/sksl/SkSLDSLParser.h b/src/sksl/SkSLDSLParser.h index 8e2a6cc239..cdd4f7b3ee 100644 --- a/src/sksl/SkSLDSLParser.h +++ b/src/sksl/SkSLDSLParser.h @@ -88,6 +88,13 @@ private: */ bool checkNext(Token::Kind kind, Token* result = nullptr); + /** + * Behaves like checkNext(TK_IDENTIFIER), but also verifies that identifier is not a builtin + * type. If the token was actually a builtin type, false is returned (the next token is not + * considered to be an identifier). + */ + bool checkIdentifier(Token* result = nullptr); + /** * Reads the next non-whitespace token and generates an error if it is not the expected type. * The 'expected' string is part of the error message, which reads: diff --git a/tests/sksl/errors/InterfaceBlockReservedName.glsl b/tests/sksl/errors/InterfaceBlockReservedName.glsl index 284b23c08e..49164ae826 100644 --- a/tests/sksl/errors/InterfaceBlockReservedName.glsl +++ b/tests/sksl/errors/InterfaceBlockReservedName.glsl @@ -1,7 +1,4 @@ +### Compilation failed: -IB { - float f; -} float; -vec4 main() { - return vec4(float.f); -} +error: 3: expected ';', but found 'float' +1 error diff --git a/tests/sksl/errors/StructVariableReservedName.glsl b/tests/sksl/errors/StructVariableReservedName.glsl index 60bd4bea51..49164ae826 100644 --- a/tests/sksl/errors/StructVariableReservedName.glsl +++ b/tests/sksl/errors/StructVariableReservedName.glsl @@ -1,8 +1,4 @@ +### Compilation failed: -struct S { - float f; -}; -S float; -vec4 main() { - return vec4(float.f); -} +error: 3: expected ';', but found 'float' +1 error