| OLD | NEW |
| 1 import 'package:kernel/ast.dart' as ir; | 1 import 'package:kernel/ast.dart' as ir; |
| 2 | 2 |
| 3 /// Helper class that traverses a kernel AST subtree to see if it has any | 3 /// Helper class that traverses a kernel AST subtree to see if it has any |
| 4 /// continue statements in the body of any switch cases (having continue | 4 /// continue statements in the body of any switch cases (having continue |
| 5 /// statements results in a more complex generated code). | 5 /// statements results in a more complex generated code). |
| 6 class SwitchContinueAnalysis extends ir.Visitor<bool> { | 6 class SwitchContinueAnalysis extends ir.Visitor<bool> { |
| 7 | |
| 8 SwitchContinueAnalysis._(); | 7 SwitchContinueAnalysis._(); |
| 9 | 8 |
| 10 static bool containsContinue(ir.Statement switchCaseBody) { | 9 static bool containsContinue(ir.Statement switchCaseBody) { |
| 11 return switchCaseBody.accept(new SwitchContinueAnalysis._()); | 10 return switchCaseBody.accept(new SwitchContinueAnalysis._()); |
| 12 } | 11 } |
| 13 | 12 |
| 14 bool visitContinueSwitchStatement(ir.ContinueSwitchStatement continueStmt) { | 13 bool visitContinueSwitchStatement(ir.ContinueSwitchStatement continueStmt) { |
| 15 // TODO(efortuna): Check what the target of this continue statement actually | 14 // TODO(efortuna): Check what the target of this continue statement actually |
| 16 // IS, because depending on where the label points if we have a nested | 15 // IS, because depending on where the label points if we have a nested |
| 17 // switch statement we might be able to output simpler code (not the complex | 16 // switch statement we might be able to output simpler code (not the complex |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 78 |
| 80 bool visitWhileStatement(ir.WhileStatement statement) { | 79 bool visitWhileStatement(ir.WhileStatement statement) { |
| 81 return statement.body.accept(this); | 80 return statement.body.accept(this); |
| 82 } | 81 } |
| 83 | 82 |
| 84 bool visitCatch(ir.Catch catchStatement) { | 83 bool visitCatch(ir.Catch catchStatement) { |
| 85 return catchStatement.body.accept(this); | 84 return catchStatement.body.accept(this); |
| 86 } | 85 } |
| 87 | 86 |
| 88 bool visitTryFinally(ir.TryFinally tryFinally) { | 87 bool visitTryFinally(ir.TryFinally tryFinally) { |
| 89 return tryFinally.body.accept(this) && | 88 return tryFinally.body.accept(this) && tryFinally.finalizer.accept(this); |
| 90 tryFinally.finalizer.accept(this); | |
| 91 } | 89 } |
| 92 | 90 |
| 93 bool visitFunctionDeclaration(ir.FunctionDeclaration declaration) { | 91 bool visitFunctionDeclaration(ir.FunctionDeclaration declaration) { |
| 94 return declaration.function.accept(this); | 92 return declaration.function.accept(this); |
| 95 } | 93 } |
| 96 | 94 |
| 97 bool visitFunctionNode(ir.FunctionNode node) { | 95 bool visitFunctionNode(ir.FunctionNode node) { |
| 98 return node.body.accept(this); | 96 return node.body.accept(this); |
| 99 } | 97 } |
| 100 | 98 |
| 101 bool defaultStatement(ir.Statement node) { | 99 bool defaultStatement(ir.Statement node) { |
| 102 if (node is ir.ExpressionStatement || node is ir.EmptyStatement || | 100 if (node is ir.ExpressionStatement || |
| 103 node is ir.InvalidStatement || node is ir.BreakStatement || | 101 node is ir.EmptyStatement || |
| 104 node is ir.ReturnStatement || node is ir.AssertStatement || | 102 node is ir.InvalidStatement || |
| 105 node is ir.YieldStatement || node is ir.VariableDeclaration) { | 103 node is ir.BreakStatement || |
| 104 node is ir.ReturnStatement || |
| 105 node is ir.AssertStatement || |
| 106 node is ir.YieldStatement || |
| 107 node is ir.VariableDeclaration) { |
| 106 return false; | 108 return false; |
| 107 } | 109 } |
| 108 throw 'Statement type ${node.runtimeType} not handled in ' | 110 throw 'Statement type ${node.runtimeType} not handled in ' |
| 109 'SwitchContinueAnalysis'; | 111 'SwitchContinueAnalysis'; |
| 110 } | 112 } |
| 111 | 113 |
| 112 bool defaultNode(ir.Node node) => false; | 114 bool defaultNode(ir.Node node) => false; |
| 113 } | 115 } |
| OLD | NEW |