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

Unified Diff: pkg/compiler/lib/src/ssa/switch_handler.dart

Issue 2637483002: Implement switch statement, without the "complex switch statement" (aka switch statement with conti… (Closed)
Patch Set: . Created 3 years, 11 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
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);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698