Split convertIf into an AST part and IR part.

Change-Id: I14205773c5934cfc1896be48783818ff096e71c2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352504
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-01-11 13:00:49 -05:00
parent 52a7eca13d
commit 5ede6e3657
2 changed files with 23 additions and 9 deletions

View File

@ -495,19 +495,29 @@ std::unique_ptr<Statement> IRGenerator::convertIf(const ASTNode& n) {
return nullptr;
}
}
if (test->kind() == Expression::Kind::kBoolLiteral) {
// static boolean value, fold down to a single branch
bool isStatic = n.getBool();
return this->convertIf(n.fOffset, isStatic, std::move(test), std::move(ifTrue),
std::move(ifFalse));
}
std::unique_ptr<Statement> IRGenerator::convertIf(int offset, bool isStatic,
std::unique_ptr<Expression> test,
std::unique_ptr<Statement> ifTrue,
std::unique_ptr<Statement> ifFalse) {
SkASSERT(test->type().isBoolean());
if (test->is<BoolLiteral>()) {
// Static Boolean values can fold down to a single branch.
if (test->as<BoolLiteral>().value()) {
return ifTrue;
} else if (ifFalse) {
return ifFalse;
} else {
// False & no else clause. Not an error, so don't return null!
return std::make_unique<Nop>();
}
if (ifFalse) {
return ifFalse;
}
// False, but no else-clause. Not an error, so don't return null!
return std::make_unique<Nop>();
}
return std::make_unique<IfStatement>(n.fOffset, n.getBool(), std::move(test),
std::move(ifTrue), std::move(ifFalse));
return std::make_unique<IfStatement>(offset, isStatic, std::move(test), std::move(ifTrue),
std::move(ifFalse));
}
std::unique_ptr<Statement> IRGenerator::convertFor(const ASTNode& f) {

View File

@ -199,6 +199,10 @@ private:
std::unique_ptr<Expression> convertIdentifier(int offset, StringFragment identifier);
std::unique_ptr<Expression> convertIdentifier(const ASTNode& identifier);
std::unique_ptr<Statement> convertIf(const ASTNode& s);
std::unique_ptr<Statement> convertIf(int offset, bool isStatic,
std::unique_ptr<Expression> test,
std::unique_ptr<Statement> ifTrue,
std::unique_ptr<Statement> ifFalse);
std::unique_ptr<InterfaceBlock> convertInterfaceBlock(const ASTNode& s);
Modifiers convertModifiers(const Modifiers& m);
std::unique_ptr<Expression> convertPrefixExpression(const ASTNode& expression);