Disallow a bare ';' at the top level of SkSL files

It turns out the parser was accepting empty declarations, turning them
into an empty modifiers declaration. This was causing problems with a
CL that was going to disallow declarations in contexts where they
weren't allowed. Since this was never the intended behavior, we now
disallow it.

Change-Id: Iea56529c76a946e8002ce1e929790aec488fd4f5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314879
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Ethan Nicholas 2020-09-02 14:08:23 -04:00 committed by Skia Commit-Bot
parent 0e47880713
commit da6320ca11
4 changed files with 17 additions and 12 deletions

View File

@ -13,7 +13,7 @@ in fragmentProcessor blurProfile;
@header {
#include "src/gpu/effects/GrTextureEffect.h"
};
}
// The data is formatted as:
// x, y - the center of the circle

View File

@ -297,25 +297,24 @@ public:
circleDataVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf4_GrSLType, "circleData");
fragBuilder->codeAppendf(
R"SkSL(;
half2 vec = half2((sk_FragCoord.xy - float2(%s.xy)) * float(%s.w));
R"SkSL(half2 vec = half2((sk_FragCoord.xy - float2(%s.xy)) * float(%s.w));
half dist = length(vec) + (0.5 - %s.z) * %s.w;)SkSL",
args.fUniformHandler->getUniformCStr(circleDataVar),
args.fUniformHandler->getUniformCStr(circleDataVar),
args.fUniformHandler->getUniformCStr(circleDataVar),
args.fUniformHandler->getUniformCStr(circleDataVar));
SkString _sample13902 = this->invokeChild(0, args);
SkString _sample13901 = this->invokeChild(0, args);
fragBuilder->codeAppendf(
R"SkSL(
half4 inputColor = %s;)SkSL",
_sample13902.c_str());
SkString _coords13950("float2(half2(dist, 0.5))");
SkString _sample13950 = this->invokeChild(1, args, _coords13950.c_str());
_sample13901.c_str());
SkString _coords13949("float2(half2(dist, 0.5))");
SkString _sample13949 = this->invokeChild(1, args, _coords13949.c_str());
fragBuilder->codeAppendf(
R"SkSL(
%s = inputColor * %s.w;
)SkSL",
args.fOutputColor, _sample13950.c_str());
args.fOutputColor, _sample13949.c_str());
}
private:

View File

@ -401,8 +401,14 @@ ASTNode::ID Parser::enumDeclaration() {
(COMMA parameter)* RPAREN (block | SEMICOLON)) | SEMICOLON) | interfaceBlock) */
ASTNode::ID Parser::declaration() {
Token lookahead = this->peek();
if (lookahead.fKind == Token::Kind::TK_ENUM) {
return this->enumDeclaration();
switch (lookahead.fKind) {
case Token::Kind::TK_ENUM:
return this->enumDeclaration();
case Token::Kind::TK_SEMICOLON:
this->error(lookahead.fOffset, "expected a declaration, but found ';'");
return ASTNode::ID::Invalid();
default:
break;
}
Modifiers modifiers = this->modifiers();
lookahead = this->peek();

View File

@ -469,10 +469,10 @@ DEF_TEST(SkSLDivByZero, r) {
DEF_TEST(SkSLUnsupportedGLSLIdentifiers, r) {
test_failure(r,
"void main() { float x = gl_FragCoord.x; };",
"void main() { float x = gl_FragCoord.x; }",
"error: 1: unknown identifier 'gl_FragCoord'\n1 error\n");
test_failure(r,
"void main() { float r = gl_FragColor.r; };",
"void main() { float r = gl_FragColor.r; }",
"error: 1: unknown identifier 'gl_FragColor'\n1 error\n");
}