| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library tree_ir_builder; | 5 library tree_ir_builder; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' as dart2js; | 7 import '../dart2jslib.dart' as dart2js; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 Builder createInnerBuilder() { | 76 Builder createInnerBuilder() { |
| 77 return new Builder(internalError, this); | 77 return new Builder(internalError, this); |
| 78 } | 78 } |
| 79 | 79 |
| 80 /// Variable used in [buildPhiAssignments] as a temporary when swapping | 80 /// Variable used in [buildPhiAssignments] as a temporary when swapping |
| 81 /// variables. | 81 /// variables. |
| 82 Variable phiTempVar; | 82 Variable phiTempVar; |
| 83 | 83 |
| 84 Variable addMutableVariable(cps_ir.MutableVariable irVariable) { | 84 Variable addMutableVariable(cps_ir.MutableVariable irVariable) { |
| 85 if (irVariable.host != currentElement) { | 85 assert(irVariable.host == currentElement); |
| 86 return parent.addMutableVariable(irVariable); | |
| 87 } | |
| 88 assert(!local2mutable.containsKey(irVariable)); | 86 assert(!local2mutable.containsKey(irVariable)); |
| 89 Variable variable = new Variable(currentElement, irVariable.hint); | 87 Variable variable = new Variable(currentElement, irVariable.hint); |
| 90 local2mutable[irVariable] = variable; | 88 local2mutable[irVariable] = variable; |
| 91 return variable; | 89 return variable; |
| 92 } | 90 } |
| 93 | 91 |
| 94 Variable getMutableVariable(cps_ir.MutableVariable mutableVariable) { | 92 Variable getMutableVariable(cps_ir.MutableVariable mutableVariable) { |
| 95 if (mutableVariable.host != currentElement) { | 93 if (mutableVariable.host != currentElement) { |
| 96 return parent.getMutableVariable(mutableVariable); | 94 return parent.getMutableVariable(mutableVariable)..isCaptured = true; |
| 97 } | 95 } |
| 98 return local2mutable[mutableVariable]; | 96 return local2mutable[mutableVariable]; |
| 99 } | 97 } |
| 100 | 98 |
| 101 VariableUse getMutableVariableUse( | 99 VariableUse getMutableVariableUse( |
| 102 cps_ir.Reference<cps_ir.MutableVariable> reference) { | 100 cps_ir.Reference<cps_ir.MutableVariable> reference) { |
| 103 Variable variable = getMutableVariable(reference.definition); | 101 Variable variable = getMutableVariable(reference.definition); |
| 104 return new VariableUse(variable); | 102 return new VariableUse(variable); |
| 105 } | 103 } |
| 106 | 104 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 Function nextBuilder = cont.hasExactlyOneUse ? | 471 Function nextBuilder = cont.hasExactlyOneUse ? |
| 474 () => visit(cont.body) : () => new Break(labels[cont]); | 472 () => visit(cont.body) : () => new Break(labels[cont]); |
| 475 return buildContinuationAssignment(cont.parameters.single, expression, | 473 return buildContinuationAssignment(cont.parameters.single, expression, |
| 476 nextBuilder); | 474 nextBuilder); |
| 477 } | 475 } |
| 478 } | 476 } |
| 479 | 477 |
| 480 Statement visitLetMutable(cps_ir.LetMutable node) { | 478 Statement visitLetMutable(cps_ir.LetMutable node) { |
| 481 Variable variable = addMutableVariable(node.variable); | 479 Variable variable = addMutableVariable(node.variable); |
| 482 Expression value = getVariableUse(node.value); | 480 Expression value = getVariableUse(node.value); |
| 483 return new Assign(variable, value, visit(node.body), isDeclaration: true); | 481 Statement body = visit(node.body); |
| 482 // If the variable was captured by an inner function in the body, this |
| 483 // must be declared here so we assign to a fresh copy of the variable. |
| 484 bool needsDeclaration = variable.isCaptured; |
| 485 return new Assign(variable, value, body, isDeclaration: needsDeclaration); |
| 484 } | 486 } |
| 485 | 487 |
| 486 Expression visitGetMutableVariable(cps_ir.GetMutableVariable node) { | 488 Expression visitGetMutableVariable(cps_ir.GetMutableVariable node) { |
| 487 return getMutableVariableUse(node.variable); | 489 return getMutableVariableUse(node.variable); |
| 488 } | 490 } |
| 489 | 491 |
| 490 Statement visitSetMutableVariable(cps_ir.SetMutableVariable node) { | 492 Statement visitSetMutableVariable(cps_ir.SetMutableVariable node) { |
| 491 Variable variable = getMutableVariable(node.variable.definition); | 493 Variable variable = getMutableVariable(node.variable.definition); |
| 492 Expression value = getVariableUse(node.value); | 494 Expression value = getVariableUse(node.value); |
| 493 return new Assign(variable, value, visit(node.body)); | 495 return new Assign(variable, value, visit(node.body)); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 640 } |
| 639 | 641 |
| 640 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { | 642 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { |
| 641 return new ReifyRuntimeType(getVariableUse(node.value)); | 643 return new ReifyRuntimeType(getVariableUse(node.value)); |
| 642 } | 644 } |
| 643 | 645 |
| 644 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { | 646 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { |
| 645 return new ReadTypeVariable(node.variable, getVariableUse(node.target)); | 647 return new ReadTypeVariable(node.variable, getVariableUse(node.target)); |
| 646 } | 648 } |
| 647 } | 649 } |
| OLD | NEW |