34 bool visitExpressionPtr(std::unique_ptr<Expression>& expr)
override {
39 bool visitStatementPtr(std::unique_ptr<Statement>& stmt)
override {
41 INHERITED::visitStatementPtr(stmt);
43 switch (stmt->kind()) {
46 EliminateBracesFrom(ifStmt.
ifTrue());
47 EliminateBracesFrom(ifStmt.
ifFalse());
68 static void EliminateBracesFrom(std::unique_ptr<Statement>& stmt) {
69 if (!stmt || !stmt->is<
Block>()) {
73 std::unique_ptr<Statement>* usefulStmt =
nullptr;
74 for (std::unique_ptr<Statement>& childStmt : block.
children()) {
75 if (childStmt->isEmpty()) {
84 usefulStmt = &childStmt;
92 stmt = std::move(*usefulStmt);
99 for (std::unique_ptr<ProgramElement>& pe : elements) {
101 UnnecessaryBraceEliminator visitor;
#define INHERITED(method,...)
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
const StatementArray & children() const
std::unique_ptr< Statement > & statement()
std::unique_ptr< Statement > & statement()
std::unique_ptr< Statement > & body()
std::unique_ptr< Statement > & ifTrue()
std::unique_ptr< Statement > & ifFalse()
static std::unique_ptr< Statement > Make()
static void eliminate_unnecessary_braces(SkSpan< std::unique_ptr< ProgramElement > > elements)
std::vector< std::unique_ptr< ProgramElement > > fElements