| Index: sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart
|
| diff --git a/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart b/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart
|
| index 13933850fa144f0b396bb9a6f38f35de4144037a..3b660fed4946fb82f11d0e93214a527a10de2777 100644
|
| --- a/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart
|
| +++ b/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart
|
| @@ -355,6 +355,56 @@ class IrBuilder {
|
| state.constantSystem.createString(new ast.DartString.literal(value)));
|
| }
|
|
|
| + /// Creates a conditional expression with the provided [condition] where the
|
| + /// then and else expression are created through the [buildThenExpression] and
|
| + /// [buildElseExpression] functions, respectively.
|
| + ir.Primitive buildConditional(
|
| + ir.Primitive condition,
|
| + ir.Primitive buildThenExpression(IrBuilder builder),
|
| + ir.Primitive buildElseExpression(IrBuilder builder)) {
|
| +
|
| + assert(isOpen);
|
| +
|
| + // The then and else expressions are delimited.
|
| + IrBuilder thenBuilder = new IrBuilder.delimited(this);
|
| + IrBuilder elseBuilder = new IrBuilder.delimited(this);
|
| + ir.Primitive thenValue = buildThenExpression(thenBuilder);
|
| + ir.Primitive elseValue = buildElseExpression(elseBuilder);
|
| +
|
| + // 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(environment.length == thenBuilder.environment.length);
|
| + assert(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 =
|
| + createJoin(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;
|
| + 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;
|
| +
|
| + }
|
| +
|
| /// Create a get access of [local].
|
| ir.Primitive buildLocalGet(Element local) {
|
| assert(isOpen);
|
| @@ -447,7 +497,7 @@ class IrBuilder {
|
| }
|
|
|
| /// Creates an if-then-else statement with the provided [condition] where the
|
| - /// then and else branches are created throught the [buildThenPart] and
|
| + /// then and else branches are created through the [buildThenPart] and
|
| /// [buildElsePart] functions, respectively.
|
| ///
|
| /// An if-then statement is created if [buildElsePart] is a no-op.
|
|
|