Revert "Revert "moved SkSL ExpressionStatement's data into IRNode""

This reverts commit dd33b3ea90.

Change-Id: I348b2b5976966a7451d88bd7f96ce17ce1702b79
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320826
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@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-30 09:29:55 -04:00 committed by Skia Commit-Bot
parent 718ae76d5b
commit d503a5a00f
11 changed files with 29 additions and 20 deletions

View File

@ -423,7 +423,7 @@ bool ProgramVisitor::visitStatement(const Statement& s) {
const DoStatement& d = s.as<DoStatement>();
return this->visitExpression(*d.test()) || this->visitStatement(*d.statement()); }
case Statement::Kind::kExpression:
return this->visitExpression(*s.as<ExpressionStatement>().fExpression);
return this->visitExpression(*s.as<ExpressionStatement>().expression());
case Statement::Kind::kFor: {
const ForStatement& f = s.as<ForStatement>();
return (f.fInitializer && this->visitStatement(*f.fInitializer)) ||

View File

@ -1809,7 +1809,7 @@ void ByteCodeGenerator::writeStatement(const Statement& s) {
this->writeDoStatement(s.as<DoStatement>());
break;
case Statement::Kind::kExpression:
this->writeExpression(*s.as<ExpressionStatement>().fExpression, true);
this->writeExpression(*s.as<ExpressionStatement>().expression(), true);
break;
case Statement::Kind::kFor:
this->writeForStatement(s.as<ForStatement>());

View File

@ -509,7 +509,7 @@ void CFGGenerator::addStatement(CFG& cfg, std::unique_ptr<Statement>* s) {
break;
}
case Statement::Kind::kExpression: {
this->addExpression(cfg, &(*s)->as<ExpressionStatement>().fExpression,
this->addExpression(cfg, &(*s)->as<ExpressionStatement>().expression(),
/*constantPropagate=*/true);
cfg.currentBlock().fNodes.push_back(BasicBlock::MakeStatement(s));
break;

View File

@ -1393,9 +1393,9 @@ void Compiler::simplifyStatement(DefinitionMap& definitions,
case Statement::Kind::kExpression: {
ExpressionStatement& e = stmt->as<ExpressionStatement>();
SkASSERT((*iter)->statement()->get() == &e);
if (!e.fExpression->hasSideEffects()) {
if (!e.expression()->hasSideEffects()) {
// Expression statement with no side effects, kill it
if (!b.tryRemoveExpressionBefore(iter, e.fExpression.get())) {
if (!b.tryRemoveExpressionBefore(iter, e.expression().get())) {
*outNeedsRescan = true;
}
SkASSERT((*iter)->statement()->get() == stmt);

View File

@ -420,7 +420,7 @@ void Dehydrator::write(const Statement* s) {
case Statement::Kind::kExpression: {
const ExpressionStatement& e = s->as<ExpressionStatement>();
this->writeU8(Rehydrator::kExpressionStatement_Command);
this->write(e.fExpression.get());
this->write(e.expression().get());
break;
}
case Statement::Kind::kFor: {

View File

@ -1294,7 +1294,7 @@ void GLSLCodeGenerator::writeStatement(const Statement& s) {
this->writeBlock(s.as<Block>());
break;
case Statement::Kind::kExpression:
this->writeExpression(*s.as<ExpressionStatement>().fExpression, kTopLevel_Precedence);
this->writeExpression(*s.as<ExpressionStatement>().expression(), kTopLevel_Precedence);
this->write(";");
break;
case Statement::Kind::kReturn:

View File

@ -243,7 +243,7 @@ std::unique_ptr<Statement> IRGenerator::convertSingleStatement(const ASTNode& st
std::unique_ptr<Statement> result = this->convertExpressionStatement(statement);
if (fRTAdjust && fKind == Program::kGeometry_Kind) {
SkASSERT(result->kind() == Statement::Kind::kExpression);
Expression& expr = *result->as<ExpressionStatement>().fExpression;
Expression& expr = *result->as<ExpressionStatement>().expression();
if (expr.kind() == Expression::Kind::kFunctionCall) {
FunctionCall& fc = expr.as<FunctionCall>();
if (fc.fFunction.fBuiltin && fc.fFunction.fName == "EmitVertex") {

View File

@ -470,7 +470,7 @@ std::unique_ptr<Statement> Inliner::inlineStatement(int offset,
}
case Statement::Kind::kExpression: {
const ExpressionStatement& e = statement.as<ExpressionStatement>();
return std::make_unique<ExpressionStatement>(expr(e.fExpression));
return std::make_unique<ExpressionStatement>(expr(e.expression()));
}
case Statement::Kind::kFor: {
const ForStatement& f = statement.as<ForStatement>();
@ -868,7 +868,7 @@ bool Inliner::analyze(Program& program) {
}
case Statement::Kind::kExpression: {
ExpressionStatement& expr = (*stmt)->as<ExpressionStatement>();
this->visitExpression(&expr.fExpression);
this->visitExpression(&expr.expression());
break;
}
case Statement::Kind::kFor: {

View File

@ -1249,7 +1249,7 @@ void MetalCodeGenerator::writeStatement(const Statement& s) {
this->writeBlock(s.as<Block>());
break;
case Statement::Kind::kExpression:
this->writeExpression(*s.as<ExpressionStatement>().fExpression, kTopLevel_Precedence);
this->writeExpression(*s.as<ExpressionStatement>().expression(), kTopLevel_Precedence);
this->write(";");
break;
case Statement::Kind::kReturn:
@ -1796,7 +1796,7 @@ MetalCodeGenerator::Requirements MetalCodeGenerator::requirements(const Statemen
return result;
}
case Statement::Kind::kExpression:
return this->requirements(s->as<ExpressionStatement>().fExpression.get());
return this->requirements(s->as<ExpressionStatement>().expression().get());
case Statement::Kind::kReturn: {
const ReturnStatement& r = s->as<ReturnStatement>();
return this->requirements(r.fExpression.get());

View File

@ -2873,7 +2873,7 @@ void SPIRVCodeGenerator::writeStatement(const Statement& s, OutputStream& out) {
this->writeBlock((Block&) s, out);
break;
case Statement::Kind::kExpression:
this->writeExpression(*s.as<ExpressionStatement>().fExpression, out);
this->writeExpression(*s.as<ExpressionStatement>().expression(), out);
break;
case Statement::Kind::kReturn:
this->writeReturnStatement(s.as<ReturnStatement>(), out);

View File

@ -16,23 +16,32 @@ namespace SkSL {
/**
* A lone expression being used as a statement.
*/
struct ExpressionStatement : public Statement {
class ExpressionStatement : public Statement {
public:
static constexpr Kind kStatementKind = Kind::kExpression;
ExpressionStatement(std::unique_ptr<Expression> expression)
: INHERITED(expression->fOffset, kStatementKind)
, fExpression(std::move(expression)) {}
: INHERITED(expression->fOffset, kStatementKind) {
fExpressionChildren.push_back(std::move(expression));
}
const std::unique_ptr<Expression>& expression() const {
return fExpressionChildren[0];
}
std::unique_ptr<Expression>& expression() {
return fExpressionChildren[0];
}
std::unique_ptr<Statement> clone() const override {
return std::unique_ptr<Statement>(new ExpressionStatement(fExpression->clone()));
return std::unique_ptr<Statement>(new ExpressionStatement(this->expression()->clone()));
}
String description() const override {
return fExpression->description() + ";";
return this->expression()->description() + ";";
}
std::unique_ptr<Expression> fExpression;
private:
using INHERITED = Statement;
};