Refactored SkSL convertDo & convertFor
No functionality changes, but the new variants of the methods make them more accessible from upcoming DSL code. Change-Id: Iaa9f1fab31cb7db00007b00d7d3b88ff5b9696b6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356103 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
abef5efa2a
commit
2ed0d94887
@ -538,6 +538,30 @@ std::unique_ptr<Statement> IRGenerator::convertIf(int offset, bool isStatic,
|
||||
std::move(ifFalse));
|
||||
}
|
||||
|
||||
std::unique_ptr<Statement> IRGenerator::convertFor(int offset,
|
||||
std::unique_ptr<Statement> initializer,
|
||||
std::unique_ptr<Expression> test,
|
||||
std::unique_ptr<Expression> next,
|
||||
std::unique_ptr<Statement> statement) {
|
||||
if (test) {
|
||||
test = this->coerce(std::move(test), *fContext.fTypes.fBool);
|
||||
if (!test) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto forStmt =
|
||||
std::make_unique<ForStatement>(offset, std::move(initializer), std::move(test),
|
||||
std::move(next), std::move(statement), fSymbolTable);
|
||||
if (this->strictES2Mode()) {
|
||||
if (!Analysis::ForLoopIsValidForES2(*forStmt, /*outLoopInfo=*/nullptr,
|
||||
&this->errorReporter())) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return std::move(forStmt);
|
||||
}
|
||||
|
||||
std::unique_ptr<Statement> IRGenerator::convertFor(const ASTNode& f) {
|
||||
SkASSERT(f.fKind == ASTNode::Kind::kFor);
|
||||
AutoLoopLevel level(this);
|
||||
@ -553,7 +577,7 @@ std::unique_ptr<Statement> IRGenerator::convertFor(const ASTNode& f) {
|
||||
++iter;
|
||||
std::unique_ptr<Expression> test;
|
||||
if (*iter) {
|
||||
test = this->coerce(this->convertExpression(*iter), *fContext.fTypes.fBool);
|
||||
test = this->convertExpression(*iter);
|
||||
if (!test) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -572,16 +596,8 @@ std::unique_ptr<Statement> IRGenerator::convertFor(const ASTNode& f) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto forStmt =
|
||||
std::make_unique<ForStatement>(f.fOffset, std::move(initializer), std::move(test),
|
||||
std::move(next), std::move(statement), fSymbolTable);
|
||||
if (this->strictES2Mode()) {
|
||||
if (!Analysis::ForLoopIsValidForES2(*forStmt, /*outLoopInfo=*/nullptr,
|
||||
&this->errorReporter())) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return std::move(forStmt);
|
||||
return this->convertFor(f.fOffset, std::move(initializer), std::move(test), std::move(next),
|
||||
std::move(statement));
|
||||
}
|
||||
|
||||
std::unique_ptr<Statement> IRGenerator::convertWhile(int offset, std::unique_ptr<Expression> test,
|
||||
@ -614,25 +630,33 @@ std::unique_ptr<Statement> IRGenerator::convertWhile(const ASTNode& w) {
|
||||
return this->convertWhile(w.fOffset, std::move(test), std::move(statement));
|
||||
}
|
||||
|
||||
std::unique_ptr<Statement> IRGenerator::convertDo(const ASTNode& d) {
|
||||
SkASSERT(d.fKind == ASTNode::Kind::kDo);
|
||||
std::unique_ptr<Statement> IRGenerator::convertDo(std::unique_ptr<Statement> stmt,
|
||||
std::unique_ptr<Expression> test) {
|
||||
if (this->strictES2Mode()) {
|
||||
this->errorReporter().error(d.fOffset, "do-while loops are not supported");
|
||||
this->errorReporter().error(stmt->fOffset, "do-while loops are not supported");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoLoopLevel level(this);
|
||||
test = this->coerce(std::move(test), *fContext.fTypes.fBool);
|
||||
if (!test) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<DoStatement>(stmt->fOffset, std::move(stmt), std::move(test));
|
||||
}
|
||||
|
||||
std::unique_ptr<Statement> IRGenerator::convertDo(const ASTNode& d) {
|
||||
SkASSERT(d.fKind == ASTNode::Kind::kDo);
|
||||
auto iter = d.begin();
|
||||
std::unique_ptr<Statement> statement = this->convertStatement(*(iter++));
|
||||
if (!statement) {
|
||||
return nullptr;
|
||||
}
|
||||
std::unique_ptr<Expression> test =
|
||||
this->coerce(this->convertExpression(*(iter++)), *fContext.fTypes.fBool);
|
||||
std::unique_ptr<Expression> test = this->convertExpression(*(iter++));
|
||||
if (!test) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<DoStatement>(d.fOffset, std::move(statement), std::move(test));
|
||||
return this->convertDo(std::move(statement), std::move(test));
|
||||
}
|
||||
|
||||
std::unique_ptr<Statement> IRGenerator::convertSwitch(const ASTNode& s) {
|
||||
|
@ -188,6 +188,8 @@ private:
|
||||
ExpressionArray params);
|
||||
std::unique_ptr<Statement> convertContinue(const ASTNode& c);
|
||||
std::unique_ptr<Statement> convertDiscard(const ASTNode& d);
|
||||
std::unique_ptr<Statement> convertDo(std::unique_ptr<Statement> stmt,
|
||||
std::unique_ptr<Expression> test);
|
||||
std::unique_ptr<Statement> convertDo(const ASTNode& d);
|
||||
std::unique_ptr<Statement> convertSwitch(const ASTNode& s);
|
||||
std::unique_ptr<Expression> convertBinaryExpression(const ASTNode& expression);
|
||||
@ -195,6 +197,11 @@ private:
|
||||
std::unique_ptr<Statement> convertExpressionStatement(const ASTNode& s);
|
||||
std::unique_ptr<Expression> convertField(std::unique_ptr<Expression> base,
|
||||
StringFragment field);
|
||||
std::unique_ptr<Statement> convertFor(int offset,
|
||||
std::unique_ptr<Statement> initializer,
|
||||
std::unique_ptr<Expression> test,
|
||||
std::unique_ptr<Expression> next,
|
||||
std::unique_ptr<Statement> statement);
|
||||
std::unique_ptr<Statement> convertFor(const ASTNode& f);
|
||||
std::unique_ptr<Expression> convertIdentifier(int offset, StringFragment identifier);
|
||||
std::unique_ptr<Expression> convertIdentifier(const ASTNode& identifier);
|
||||
|
Loading…
Reference in New Issue
Block a user