| Index: sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder_visitor.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder_visitor.dart b/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder_visitor.dart
|
| index 04413a8dbf52297cd9193e2c5d326574aed6e05a..294aa0804a3cf60fca9d7002d6c801c0cc030bdf 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder_visitor.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder_visitor.dart
|
| @@ -177,7 +177,13 @@ class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive>
|
| });
|
| }
|
|
|
| - ir.Primitive visit(ast.Node node) => node.accept(this);
|
| + ir.Primitive visit(ast.Node node) => node != null ? node.accept(this) : null;
|
| +
|
| + /// Returns a closure that takes an [IrBuilder] and visits [node] in its
|
| + /// context.
|
| + build(ast.Node node) {
|
| + return (IrBuilder builder) => withBuilder(builder, () => visit(node));
|
| + }
|
|
|
| // ==== Statements ====
|
| // Build(Block(stamements), C) = C'
|
| @@ -376,19 +382,10 @@ class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive>
|
| }
|
|
|
| visitIf(ast.If node) {
|
| - ir.Primitive condition = visit(node.condition);
|
| -
|
| - void buildThenPart(IrBuilder thenBuilder) {
|
| - withBuilder(thenBuilder, () => visit(node.thenPart));
|
| - }
|
| -
|
| - void buildElsePart(IrBuilder elseBuilder) {
|
| - if (node.hasElsePart) {
|
| - withBuilder(elseBuilder, () => visit(node.elsePart));
|
| - }
|
| - }
|
| -
|
| - irBuilder.buildIf(condition, buildThenPart, buildElsePart);
|
| + irBuilder.buildIf(
|
| + visit(node.condition),
|
| + build(node.thenPart),
|
| + build(node.elsePart));
|
| }
|
|
|
| ir.Primitive visitLabeledStatement(ast.LabeledStatement node) {
|
| @@ -646,48 +643,10 @@ class IrBuilderVisitor extends ResolvedVisitor<ir.Primitive>
|
|
|
| // ==== Expressions ====
|
| ir.Primitive visitConditional(ast.Conditional node) {
|
| - assert(irBuilder.isOpen);
|
| - ir.Primitive condition = visit(node.condition);
|
| -
|
| - // The then and else expressions are delimited.
|
| - IrBuilder thenBuilder = new IrBuilder.delimited(irBuilder);
|
| - IrBuilder elseBuilder = new IrBuilder.delimited(irBuilder);
|
| - ir.Primitive thenValue =
|
| - withBuilder(thenBuilder, () => visit(node.thenExpression));
|
| - ir.Primitive elseValue =
|
| - withBuilder(elseBuilder, () => visit(node.elseExpression));
|
| -
|
| - // Treat the values of the subexpressions as named values in the
|
| - // environment, so they will be treated as arguments to the join-point
|
| - // continuation.
|
| - assert(irBuilder.environment.length == thenBuilder.environment.length);
|
| - assert(irBuilder.environment.length == elseBuilder.environment.length);
|
| - thenBuilder.environment.extend(null, thenValue);
|
| - elseBuilder.environment.extend(null, elseValue);
|
| - JumpCollector jumps = new JumpCollector(null);
|
| - jumps.addJump(thenBuilder);
|
| - jumps.addJump(elseBuilder);
|
| - ir.Continuation joinContinuation =
|
| - irBuilder.createJoin(irBuilder.environment.length + 1, jumps);
|
| -
|
| - // Build the term
|
| - // let cont join(x, ..., result) = [] in
|
| - // let cont then() = [[thenPart]]; join(v, ...) in
|
| - // let cont else() = [[elsePart]]; join(v, ...) in
|
| - // if condition (then, else)
|
| - ir.Continuation thenContinuation = new ir.Continuation([]);
|
| - ir.Continuation elseContinuation = new ir.Continuation([]);
|
| - thenContinuation.body = thenBuilder._root;
|
| - elseContinuation.body = elseBuilder._root;
|
| - irBuilder.add(new ir.LetCont(joinContinuation,
|
| - new ir.LetCont(thenContinuation,
|
| - new ir.LetCont(elseContinuation,
|
| - new ir.Branch(new ir.IsTrue(condition),
|
| - thenContinuation,
|
| - elseContinuation)))));
|
| - return (thenValue == elseValue)
|
| - ? thenValue
|
| - : joinContinuation.parameters.last;
|
| + return irBuilder.buildConditional(
|
| + visit(node.condition),
|
| + build(node.thenExpression),
|
| + build(node.elseExpression));
|
| }
|
|
|
| // For all simple literals:
|
|
|