| Index: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
|
| diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
|
| index 659b5e2f288f75b6f4e2d8ef46b682d026efa13b..7ccf271bcb07e6738c6c02dbd8bd7175218cffb6 100644
|
| --- a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
|
| +++ b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart
|
| @@ -1196,21 +1196,26 @@ class Branch extends TailExpression {
|
| /// boolean.
|
| bool isStrictCheck;
|
|
|
| - Branch.strict(Primitive condition,
|
| - Continuation trueCont,
|
| - Continuation falseCont)
|
| + Branch(Primitive condition,
|
| + Continuation trueCont,
|
| + Continuation falseCont,
|
| + {bool strict})
|
| : this.condition = new Reference<Primitive>(condition),
|
| trueContinuation = new Reference<Continuation>(trueCont),
|
| falseContinuation = new Reference<Continuation>(falseCont),
|
| - isStrictCheck = true;
|
| + isStrictCheck = strict {
|
| + assert(strict != null);
|
| + }
|
| +
|
| + Branch.strict(Primitive condition,
|
| + Continuation trueCont,
|
| + Continuation falseCont)
|
| + : this(condition, trueCont, falseCont, strict: true);
|
|
|
| Branch.loose(Primitive condition,
|
| Continuation trueCont,
|
| Continuation falseCont)
|
| - : this.condition = new Reference<Primitive>(condition),
|
| - trueContinuation = new Reference<Continuation>(trueCont),
|
| - falseContinuation = new Reference<Continuation>(falseCont),
|
| - this.isStrictCheck = false;
|
| + : this(condition, trueCont, falseCont, strict: false);
|
|
|
| accept(BlockVisitor visitor) => visitor.visitBranch(this);
|
|
|
| @@ -1909,6 +1914,33 @@ abstract class BlockVisitor<T> {
|
| }
|
| nodes.reversed.forEach(v.visit);
|
| }
|
| +
|
| + /// Visits block-level nodes in lexical pre-order.
|
| + ///
|
| + /// The IR may be transformed during the traversal, but the currently
|
| + /// visited node should not be removed, as its 'body' pointer is needed
|
| + /// for the traversal.
|
| + static void traverseInPreOrder(FunctionDefinition root, BlockVisitor v) {
|
| + List<Continuation> stack = <Continuation>[];
|
| + void walkBlock(InteriorNode block) {
|
| + v.visit(block);
|
| + Expression node = block.body;
|
| + v.visit(node);
|
| + while (node.next != null) {
|
| + if (node is LetCont) {
|
| + stack.addAll(node.continuations);
|
| + } else if (node is LetHandler) {
|
| + stack.add(node.handler);
|
| + }
|
| + node = node.next;
|
| + v.visit(node);
|
| + }
|
| + }
|
| + walkBlock(root);
|
| + while (stack.isNotEmpty) {
|
| + walkBlock(stack.removeLast());
|
| + }
|
| + }
|
| }
|
|
|
| abstract class Visitor<T> implements BlockVisitor<T> {
|
|
|