Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: pkg/compiler/lib/src/kernel/fall_through_visitor.dart

Issue 2265383002: Copy Rasta visitor to dart2js. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: missed some renames Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/kernel/error.dart ('k') | pkg/compiler/lib/src/kernel/kernel.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/kernel/fall_through_visitor.dart
diff --git a/pkg/compiler/lib/src/kernel/fall_through_visitor.dart b/pkg/compiler/lib/src/kernel/fall_through_visitor.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cd747082b08d94c2a578e9fd32a74f3330c36208
--- /dev/null
+++ b/pkg/compiler/lib/src/kernel/fall_through_visitor.dart
@@ -0,0 +1,99 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE.md file.
+
+import 'package:kernel/ast.dart'
+ show
+ AssertStatement,
+ Block,
+ BreakStatement,
+ Catch,
+ ContinueSwitchStatement,
+ DoStatement,
+ EmptyStatement,
+ ExpressionStatement,
+ ForInStatement,
+ ForStatement,
+ FunctionDeclaration,
+ IfStatement,
+ InvalidStatement,
+ LabeledStatement,
+ ReturnStatement,
+ Statement,
+ StatementVisitor,
+ SwitchStatement,
+ Throw,
+ TryCatch,
+ TryFinally,
+ VariableDeclaration,
+ WhileStatement,
+ YieldStatement;
+
+/// Returns true if [node] would let execution reach the next node (aka
+/// fall-through in switch cases).
+bool fallsThrough(Statement node) => node.accept(const FallThroughVisitor());
+
+/// Visitor implementing [computeFallThrough].
+class FallThroughVisitor implements StatementVisitor<bool> {
+ const FallThroughVisitor();
+
+ bool defaultStatement(Statement node) => throw "Not implemented.";
+
+ bool visitInvalidStatement(InvalidStatement node) => false;
+
+ bool visitExpressionStatement(ExpressionStatement node) {
+ return node.expression is! Throw;
+ }
+
+ bool visitBlock(Block node) {
+ for (Statement statement in node.statements) {
+ if (!statement.accept(this)) return false;
+ }
+ return true;
+ }
+
+ bool visitEmptyStatement(EmptyStatement node) => true;
+
+ bool visitAssertStatement(AssertStatement node) => true;
+
+ bool visitLabeledStatement(LabeledStatement node) => true;
+
+ bool visitBreakStatement(BreakStatement node) => false;
+
+ bool visitWhileStatement(WhileStatement node) => true;
+
+ bool visitDoStatement(DoStatement node) => node.body.accept(this);
+
+ bool visitForStatement(ForStatement node) => true;
+
+ bool visitForInStatement(ForInStatement node) => true;
+
+ bool visitSwitchStatement(SwitchStatement node) => true;
+
+ bool visitContinueSwitchStatement(ContinueSwitchStatement node) => false;
+
+ bool visitIfStatement(IfStatement node) {
+ if (node.then == null || node.otherwise == null) return true;
+ return node.then.accept(this) || node.otherwise.accept(this);
+ }
+
+ bool visitReturnStatement(ReturnStatement node) => false;
+
+ bool visitTryCatch(TryCatch node) {
+ if (node.body.accept(this)) return true;
+ for (Catch catchNode in node.catches) {
+ if (catchNode.body.accept(this)) return true;
+ }
+ return false;
+ }
+
+ bool visitTryFinally(TryFinally node) {
+ return node.body.accept(this) && node.finalizer.accept(this);
+ }
+
+ bool visitYieldStatement(YieldStatement node) => true;
+
+ bool visitVariableDeclaration(VariableDeclaration node) => true;
+
+ bool visitFunctionDeclaration(FunctionDeclaration node) => true;
+}
« no previous file with comments | « pkg/compiler/lib/src/kernel/error.dart ('k') | pkg/compiler/lib/src/kernel/kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698