| 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 SwitchContinueAnalysis._(); | 7 SwitchContinueAnalysis._(); |
| 8 | 8 |
| 9 static bool containsContinue(ir.Statement switchCaseBody) { | 9 static bool containsContinue(ir.Statement switchCaseBody) { |
| 10 return switchCaseBody.accept(new SwitchContinueAnalysis._()); | 10 return switchCaseBody.accept(new SwitchContinueAnalysis._()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 return false; | 52 return false; |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool visitSwitchCase(ir.SwitchCase switchCase) { | 55 bool visitSwitchCase(ir.SwitchCase switchCase) { |
| 56 return switchCase.body.accept(this); | 56 return switchCase.body.accept(this); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool visitIfStatement(ir.IfStatement ifStatement) { | 59 bool visitIfStatement(ir.IfStatement ifStatement) { |
| 60 if (ifStatement.then.accept(this)) { | 60 return ifStatement.then.accept(this) || |
| 61 if (ifStatement.otherwise != null) { | 61 (ifStatement.otherwise != null && ifStatement.otherwise.accept(this)); |
| 62 return ifStatement.otherwise.accept(this); | |
| 63 } | |
| 64 } | |
| 65 return false; | |
| 66 } | 62 } |
| 67 | 63 |
| 68 bool visitTryCatch(ir.TryCatch tryCatch) { | 64 bool visitTryCatch(ir.TryCatch tryCatch) { |
| 69 if (tryCatch.body.accept(this)) { | 65 if (tryCatch.body.accept(this)) { |
| 70 for (var catchStatement in tryCatch.catches) { | 66 for (var catchStatement in tryCatch.catches) { |
| 71 if (catchStatement.accept(this)) { | 67 if (catchStatement.accept(this)) { |
| 72 return true; | 68 return true; |
| 73 } | 69 } |
| 74 } | 70 } |
| 75 } | 71 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 106 node is ir.YieldStatement || | 102 node is ir.YieldStatement || |
| 107 node is ir.VariableDeclaration) { | 103 node is ir.VariableDeclaration) { |
| 108 return false; | 104 return false; |
| 109 } | 105 } |
| 110 throw 'Statement type ${node.runtimeType} not handled in ' | 106 throw 'Statement type ${node.runtimeType} not handled in ' |
| 111 'SwitchContinueAnalysis'; | 107 'SwitchContinueAnalysis'; |
| 112 } | 108 } |
| 113 | 109 |
| 114 bool defaultNode(ir.Node node) => false; | 110 bool defaultNode(ir.Node node) => false; |
| 115 } | 111 } |
| OLD | NEW |