Chromium Code Reviews| Index: pkg/compiler/lib/src/ssa/switch_handler.dart |
| diff --git a/pkg/compiler/lib/src/ssa/switch_handler.dart b/pkg/compiler/lib/src/ssa/switch_handler.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8583cda6cbbd2a6e580d7b7386fb605e1bfade58 |
| --- /dev/null |
| +++ b/pkg/compiler/lib/src/ssa/switch_handler.dart |
| @@ -0,0 +1,78 @@ |
| +import 'package:kernel/ast.dart' as ir; |
| + |
| +/// Helper class that traverses a kernel AST subtree to see if it has any |
| +/// continue statements in the body of any switch cases (having continue |
| +/// statements results in a more complex generated code). |
| +class ContinueVisitor extends ir.Visitor { |
|
sra1
2017/01/14 03:18:22
Perhaps call is something more specific, e.g. Swit
Emily Fortuna
2017/01/17 23:33:09
Done.
|
| + bool containsContinue; |
| + |
| + ContinueVisitor(ir.Statement switchCaseBody) { |
| + containsContinue = false; |
| + switchCaseBody.accept(this); |
| + } |
|
sra1
2017/01/14 03:18:23
If there are new statements, will this do the righ
Emily Fortuna
2017/01/17 23:33:09
Done.
|
| + |
| + void visitContinueSwitchStatement(ir.ContinueSwitchStatement continueStmt) { |
| + containsContinue = true; |
|
sra1
2017/01/14 03:18:23
Do we want to know if it targets a specific switch
Emily Fortuna
2017/01/17 23:33:09
added TODO
|
| + } |
| + |
| + void visitBlock(ir.Block block) { |
| + for (ir.Statement statement in block.statements) { |
| + statement.accept(this); |
| + } |
| + } |
| + |
| + void visitLabeledStatement(ir.LabeledStatement statement) { |
| + statement.body.accept(this); |
| + } |
| + |
| + void visitDoStatement(ir.DoStatement doStatement) { |
| + doStatement.body.accept(this); |
| + } |
| + |
| + void visitForStatement(ir.ForStatement forStatement) { |
| + forStatement.body.accept(this); |
| + } |
| + |
| + void visitForInStatement(ir.ForInStatement forInStatement) { |
| + forInStatement.body.accept(this); |
| + } |
| + |
| + void visitSwitchStatement(ir.SwitchStatement switchStatement) { |
| + for (var switchCase in switchStatement.cases) { |
| + switchCase.accept(this); |
| + } |
| + } |
| + |
| + void visitSwitchCase(ir.SwitchCase switchCase) { |
| + switchCase.body.accept(this); |
| + } |
| + |
| + void visitIfStatement(ir.IfStatement ifStatement) { |
| + ifStatement.then.accept(this); |
| + ifStatement.otherwise?.accept(this); |
| + } |
| + |
| + void visitTryCatch(ir.TryCatch tryCatch) { |
| + tryCatch.body.accept(this); |
| + for (var catchStatement in tryCatch.catches) { |
| + catchStatement.accept(this); |
| + } |
| + } |
| + |
| + void visitCatch(ir.Catch catchStatement) { |
| + catchStatement.body.accept(this); |
| + } |
| + |
| + void visitTryFinally(ir.TryFinally tryFinally) { |
| + tryFinally.body.accept(this); |
| + tryFinally.finalizer.accept(this); |
| + } |
| + |
| + void visitFunctionDeclaration(ir.FunctionDeclaration declaration) { |
| + declaration.function.accept(this); |
| + } |
| + |
| + void visitFunctionNode(ir.FunctionNode node) { |
| + node.body.accept(this); |
| + } |
| +} |