Replace vector<SwitchCase> in Switch with a StatementArray.
This is conceptually the same thing, but we have various places in the
code which expect a unique_ptr<Statement>, and they don't allow a
unique_ptr<SwitchCase> to be passed in, since the types don't match.
This change is particularly relevant to the ProgramWriter, which will be
updated in a followup CL to pass the unique_ptr to visit methods.
Change-Id: I012669fa429a13658ac2be31342c92750fe84b92
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/382723
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index 10bea6c..b10b0f5 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -515,11 +515,12 @@
}
case Statement::Kind::kSwitch: {
const SwitchStatement& ss = statement.as<SwitchStatement>();
- std::vector<std::unique_ptr<SwitchCase>> cases;
- cases.reserve(ss.cases().size());
- for (const std::unique_ptr<SwitchCase>& sc : ss.cases()) {
- cases.push_back(std::make_unique<SwitchCase>(offset, expr(sc->value()),
- stmt(sc->statement())));
+ StatementArray cases;
+ cases.reserve_back(ss.cases().size());
+ for (const std::unique_ptr<Statement>& statement : ss.cases()) {
+ const SwitchCase& sc = statement->as<SwitchCase>();
+ cases.push_back(std::make_unique<SwitchCase>(offset, expr(sc.value()),
+ stmt(sc.statement())));
}
return SwitchStatement::Make(*fContext, offset, ss.isStatic(), expr(ss.value()),
std::move(cases), SymbolTable::WrapIfBuiltin(ss.symbols()));
@@ -952,9 +953,9 @@
}
this->visitExpression(&switchStmt.value());
- for (const std::unique_ptr<SwitchCase>& switchCase : switchStmt.cases()) {
+ for (const std::unique_ptr<Statement>& switchCase : switchStmt.cases()) {
// The switch-case's fValue cannot be a FunctionCall; skip it.
- this->visitStatement(&switchCase->statement());
+ this->visitStatement(&switchCase->as<SwitchCase>().statement());
}
break;
}