OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 |
| 5 import 'package:kernel/ast.dart' |
| 6 show |
| 7 AssertStatement, |
| 8 Block, |
| 9 BreakStatement, |
| 10 Catch, |
| 11 ContinueSwitchStatement, |
| 12 DoStatement, |
| 13 EmptyStatement, |
| 14 ExpressionStatement, |
| 15 ForInStatement, |
| 16 ForStatement, |
| 17 FunctionDeclaration, |
| 18 IfStatement, |
| 19 InvalidStatement, |
| 20 LabeledStatement, |
| 21 ReturnStatement, |
| 22 Statement, |
| 23 StatementVisitor, |
| 24 SwitchStatement, |
| 25 Throw, |
| 26 TryCatch, |
| 27 TryFinally, |
| 28 VariableDeclaration, |
| 29 WhileStatement, |
| 30 YieldStatement; |
| 31 |
| 32 /// Returns true if [node] would let execution reach the next node (aka |
| 33 /// fall-through in switch cases). |
| 34 bool fallsThrough(Statement node) => node.accept(const FallThroughVisitor()); |
| 35 |
| 36 /// Visitor implementing [computeFallThrough]. |
| 37 class FallThroughVisitor implements StatementVisitor<bool> { |
| 38 const FallThroughVisitor(); |
| 39 |
| 40 bool defaultStatement(Statement node) => throw "Not implemented."; |
| 41 |
| 42 bool visitInvalidStatement(InvalidStatement node) => false; |
| 43 |
| 44 bool visitExpressionStatement(ExpressionStatement node) { |
| 45 return node.expression is! Throw; |
| 46 } |
| 47 |
| 48 bool visitBlock(Block node) { |
| 49 for (Statement statement in node.statements) { |
| 50 if (!statement.accept(this)) return false; |
| 51 } |
| 52 return true; |
| 53 } |
| 54 |
| 55 bool visitEmptyStatement(EmptyStatement node) => true; |
| 56 |
| 57 bool visitAssertStatement(AssertStatement node) => true; |
| 58 |
| 59 bool visitLabeledStatement(LabeledStatement node) => true; |
| 60 |
| 61 bool visitBreakStatement(BreakStatement node) => false; |
| 62 |
| 63 bool visitWhileStatement(WhileStatement node) => true; |
| 64 |
| 65 bool visitDoStatement(DoStatement node) => node.body.accept(this); |
| 66 |
| 67 bool visitForStatement(ForStatement node) => true; |
| 68 |
| 69 bool visitForInStatement(ForInStatement node) => true; |
| 70 |
| 71 bool visitSwitchStatement(SwitchStatement node) => true; |
| 72 |
| 73 bool visitContinueSwitchStatement(ContinueSwitchStatement node) => false; |
| 74 |
| 75 bool visitIfStatement(IfStatement node) { |
| 76 if (node.then == null || node.otherwise == null) return true; |
| 77 return node.then.accept(this) || node.otherwise.accept(this); |
| 78 } |
| 79 |
| 80 bool visitReturnStatement(ReturnStatement node) => false; |
| 81 |
| 82 bool visitTryCatch(TryCatch node) { |
| 83 if (node.body.accept(this)) return true; |
| 84 for (Catch catchNode in node.catches) { |
| 85 if (catchNode.body.accept(this)) return true; |
| 86 } |
| 87 return false; |
| 88 } |
| 89 |
| 90 bool visitTryFinally(TryFinally node) { |
| 91 return node.body.accept(this) && node.finalizer.accept(this); |
| 92 } |
| 93 |
| 94 bool visitYieldStatement(YieldStatement node) => true; |
| 95 |
| 96 bool visitVariableDeclaration(VariableDeclaration node) => true; |
| 97 |
| 98 bool visitFunctionDeclaration(FunctionDeclaration node) => true; |
| 99 } |
OLD | NEW |