38 std::unique_ptr<SwitchStatement> stmt) {
42 bool visitExpressionPtr(std::unique_ptr<Expression>& expr)
override {
47 bool visitStatementPtr(std::unique_ptr<Statement>& stmt)
override {
48 switch (stmt->kind()) {
51 return INHERITED::visitStatementPtr(stmt);
56 return INHERITED::visitStatementPtr(stmt);
62 fVarDeclarations.push_back(&stmt);
81 HoistSwitchVarDeclsVisitor visitor(context);
83 visitor.visitStatementPtr(sc);
87 if (visitor.fVarDeclarations.empty()) {
93 std::unique_ptr<SymbolTable> blockSymbols = switchSymbols->
insertNewParent();
96 blockStmts.
reserve_exact(visitor.fVarDeclarations.size() + 1);
97 for (std::unique_ptr<Statement>* innerDeclaration : visitor.fVarDeclarations) {
102 std::unique_ptr<Statement> replacementStmt;
103 if (decl.
value() && !isConst) {
107 struct AssignmentHelper :
public IRHelpers {
110 std::unique_ptr<Statement> makeAssignmentStmt(
VarDeclaration& decl)
const {
111 return Assign(
Ref(decl.
var()), std::move(decl.
value()));
115 AssignmentHelper helper(context);
116 replacementStmt = helper.makeAssignmentStmt(decl);
127 blockStmts.
push_back(std::move(*innerDeclaration));
128 *innerDeclaration = std::move(replacementStmt);
132 switchSymbols->
moveSymbolTo(blockSymbols.get(), var, context);
139 std::move(blockSymbols));
#define INHERITED(method,...)
static std::unique_ptr< Block > MakeBlock(Position pos, StatementArray statements, Kind kind=Kind::kBracedScope, std::unique_ptr< SymbolTable > symbols=nullptr)
static std::unique_ptr< Statement > Make()
void moveSymbolTo(SymbolTable *otherTable, Symbol *sym, const Context &context)
std::unique_ptr< SymbolTable > insertNewParent()
std::unique_ptr< Expression > & value()
ModifierFlags modifierFlags() const
void reserve_exact(int n)
bool IsConstantExpression(const Expression &expr)
IRHelpers(const Context &c)