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

Unified Diff: pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart

Issue 1203423003: dart2js cps: Better fallthrough analysis and eliminate "return null". (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update tests Created 5 years, 6 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/tree_ir/tree_ir_nodes.dart
diff --git a/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart b/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart
index 3c937f1b6416085f039f300807702e4a4520c974..ab549e23cc78497dbbc689dc27be4f4a0b48bf38 100644
--- a/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart
+++ b/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart
@@ -1341,3 +1341,39 @@ class RecursiveTransformer extends Transformer {
return node;
}
}
+
+class FallthroughTarget {
+ final Statement target;
+ int useCount = 0;
+
+ FallthroughTarget(this.target);
+}
+
+/// A stack machine for tracking fallthrough while traversing the Tree IR.
+class FallthroughStack {
+ final List<FallthroughTarget> _stack =
+ <FallthroughTarget>[new FallthroughTarget(null)];
+
+ /// Set a new fallthrough target.
+ void push(Statement newFallthrough) {
+ _stack.add(new FallthroughTarget(newFallthrough));
+ }
+
+ /// Remove the current fallthrough target.
+ void pop() {
+ _stack.removeLast();
+ }
+
+ /// The current fallthrough target, or `null` if control will fall over
+ /// the end of the method.
+ Statement get target => _stack.last.target;
+
+ /// Number of uses of the current fallthrough target.
+ int get useCount => _stack.last.useCount;
+
+ /// Indicate that a statement will fall through to the current fallthrough
+ /// target.
+ void use() {
+ ++_stack.last.useCount;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698