Comma operator on DSL statements now creates unscoped blocks

Change-Id: I9eb85f25431b2d59b26e8cf8f4a73b9e45faa916
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398017
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2021-04-19 10:55:18 -04:00 committed by Skia Commit-Bot
parent cc3d2d25c5
commit db2326b46a
5 changed files with 34 additions and 0 deletions

View File

@ -149,6 +149,9 @@ DSLPossibleExpression operator|=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator^(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator^=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator,(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLExpression right);
DSLPossibleExpression operator,(DSLExpression left, DSLPossibleExpression right);
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLPossibleExpression right);
DSLPossibleExpression operator==(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator!=(DSLExpression left, DSLExpression right);
DSLPossibleExpression operator>(DSLExpression left, DSLExpression right);

View File

@ -62,6 +62,7 @@ private:
friend class DSLExpression;
friend class DSLPossibleStatement;
friend class DSLWriter;
friend DSLStatement operator,(DSLStatement left, DSLStatement right);
};
/**
@ -90,6 +91,8 @@ private:
friend class DSLStatement;
};
DSLStatement operator,(DSLStatement left, DSLStatement right);
} // namespace dsl
} // namespace SkSL

View File

@ -201,6 +201,22 @@ DSLPossibleExpression operator,(DSLExpression left, DSLExpression right) {
right.release());
}
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLExpression right) {
return DSLWriter::ConvertBinary(DSLExpression(std::move(left)).release(),
SkSL::Token::Kind::TK_COMMA, right.release());
}
DSLPossibleExpression operator,(DSLExpression left, DSLPossibleExpression right) {
return DSLWriter::ConvertBinary(left.release(), SkSL::Token::Kind::TK_COMMA,
DSLExpression(std::move(right)).release());
}
DSLPossibleExpression operator,(DSLPossibleExpression left, DSLPossibleExpression right) {
return DSLWriter::ConvertBinary(DSLExpression(std::move(left)).release(),
SkSL::Token::Kind::TK_COMMA,
DSLExpression(std::move(right)).release());
}
std::unique_ptr<SkSL::Expression> DSLExpression::coerceAndRelease(const SkSL::Type& type) {
// tripping this assert means we had an error occur somewhere else in DSL construction that
// wasn't caught where it should have been

View File

@ -11,6 +11,7 @@
#include "include/sksl/DSLExpression.h"
#include "src/sksl/SkSLCompiler.h"
#include "src/sksl/dsl/priv/DSLWriter.h"
#include "src/sksl/ir/SkSLBlock.h"
#include "src/sksl/ir/SkSLExpressionStatement.h"
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
@ -75,6 +76,14 @@ DSLPossibleStatement::~DSLPossibleStatement() {
}
}
DSLStatement operator,(DSLStatement left, DSLStatement right) {
StatementArray stmts;
stmts.reserve_back(2);
stmts.push_back(left.release());
stmts.push_back(right.release());
return DSLStatement(SkSL::Block::MakeUnscoped(/*offset=*/-1, std::move(stmts)));
}
} // namespace dsl
} // namespace SkSL

View File

@ -1016,6 +1016,9 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBlock, r, ctxInfo) {
Var a(kInt_Type, "a", 1), b(kInt_Type, "b", 2);
Statement y = Block(Declare(a), Declare(b), a = b);
EXPECT_EQUAL(y, "{ int a = 1; int b = 2; (a = b); }");
Statement z = (If(a > 0, --a), ++b);
EXPECT_EQUAL(z, "if ((a > 0)) --a; ++b;");
}
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLBreak, r, ctxInfo) {