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; |
+ } |
+} |