| 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.optimization.statement_rewriter; | 5 library tree_ir.optimization.statement_rewriter; |
| 6 | 6 |
| 7 import 'optimization.dart' show Pass; | 7 import 'optimization.dart' show Pass; |
| 8 import '../tree_ir_nodes.dart'; | 8 import '../tree_ir_nodes.dart'; |
| 9 import '../../io/source_information.dart'; | 9 import '../../io/source_information.dart'; |
| 10 import '../../elements/elements.dart'; |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * Translates to direct-style. | 13 * Translates to direct-style. |
| 13 * | 14 * |
| 14 * In addition to the general IR constraints (see [CheckTreeIntegrity]), | 15 * In addition to the general IR constraints (see [CheckTreeIntegrity]), |
| 15 * the input is assumed to satisfy the following criteria: | 16 * the input is assumed to satisfy the following criteria: |
| 16 * | 17 * |
| 17 * All expressions other than those nested in [Assign] or [ExpressionStatement] | 18 * All expressions other than those nested in [Assign] or [ExpressionStatement] |
| 18 * must be simple. A [VariableUse] and [This] is a simple expression. | 19 * must be simple. A [VariableUse] and [This] is a simple expression. |
| 19 * The right-hand of an [Assign] may not be an [Assign]. | 20 * The right-hand of an [Assign] may not be an [Assign]. |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 inEmptyEnvironment(() { | 507 inEmptyEnvironment(() { |
| 507 _rewriteList(node.arguments); | 508 _rewriteList(node.arguments); |
| 508 }); | 509 }); |
| 509 node.receiver = visitExpression(node.receiver); | 510 node.receiver = visitExpression(node.receiver); |
| 510 } | 511 } |
| 511 return node; | 512 return node; |
| 512 } | 513 } |
| 513 | 514 |
| 514 Expression visitInvokeMethodDirectly(InvokeMethodDirectly node) { | 515 Expression visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 515 _rewriteList(node.arguments); | 516 _rewriteList(node.arguments); |
| 516 node.receiver = visitExpression(node.receiver); | 517 // The target function might not exist before the enclosing class has been |
| 518 // instantitated for the first time. If the receiver might be the first |
| 519 // instantiation of its class, we cannot propgate it into the receiver |
| 520 // expression, because the target function is evaluated before the receiver. |
| 521 // Calls to constructor bodies are compiled so that the receiver is |
| 522 // evaluated first, so they are safe. |
| 523 if (node.target is! ConstructorBodyElement) { |
| 524 inEmptyEnvironment(() { |
| 525 node.receiver = visitExpression(node.receiver); |
| 526 }); |
| 527 } else { |
| 528 node.receiver = visitExpression(node.receiver); |
| 529 } |
| 517 return node; | 530 return node; |
| 518 } | 531 } |
| 519 | 532 |
| 520 Expression visitInvokeConstructor(InvokeConstructor node) { | 533 Expression visitInvokeConstructor(InvokeConstructor node) { |
| 521 _rewriteList(node.arguments); | 534 _rewriteList(node.arguments); |
| 522 return node; | 535 return node; |
| 523 } | 536 } |
| 524 | 537 |
| 525 Expression visitConditional(Conditional node) { | 538 Expression visitConditional(Conditional node) { |
| 526 // Conditional expressions do not exist in the input, but they are | 539 // Conditional expressions do not exist in the input, but they are |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 VariableUseVisitor(this.callback); | 1253 VariableUseVisitor(this.callback); |
| 1241 | 1254 |
| 1242 visitVariableUse(VariableUse use) => callback(use); | 1255 visitVariableUse(VariableUse use) => callback(use); |
| 1243 | 1256 |
| 1244 visitInnerFunction(FunctionDefinition node) {} | 1257 visitInnerFunction(FunctionDefinition node) {} |
| 1245 | 1258 |
| 1246 static void visit(Expression node, VariableUseCallback callback) { | 1259 static void visit(Expression node, VariableUseCallback callback) { |
| 1247 new VariableUseVisitor(callback).visitExpression(node); | 1260 new VariableUseVisitor(callback).visitExpression(node); |
| 1248 } | 1261 } |
| 1249 } | 1262 } |
| OLD | NEW |