| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } else { | 352 } else { |
| 353 return new Assign(variable, definition, visit(node.body)); | 353 return new Assign(variable, definition, visit(node.body)); |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 Statement visitRunnableBody(cps_ir.RunnableBody node) { | 357 Statement visitRunnableBody(cps_ir.RunnableBody node) { |
| 358 return visit(node.body); | 358 return visit(node.body); |
| 359 } | 359 } |
| 360 | 360 |
| 361 Statement visitLetCont(cps_ir.LetCont node) { | 361 Statement visitLetCont(cps_ir.LetCont node) { |
| 362 Label label; | 362 // Introduce labels for continuations that need them. |
| 363 if (node.continuation.hasMultipleUses) { | 363 for (cps_ir.Continuation continuation in node.continuations) { |
| 364 label = new Label(); | 364 if (continuation.hasMultipleUses) { |
| 365 labels[node.continuation] = label; | 365 labels[continuation] = new Label(); |
| 366 } |
| 366 } | 367 } |
| 367 Statement body = visit(node.body); | 368 Statement body = visit(node.body); |
| 368 // The continuation's body is not always translated directly here because | 369 // Continuations are bound at the same level, but they have to be |
| 369 // it may have been already translated: | 370 // translated as if nested. This is because the body can invoke any |
| 371 // of them from anywhere, so it must be nested inside all of them. |
| 372 // |
| 373 // The continuation bodies are not always translated directly here because |
| 374 // they may have been already translated: |
| 370 // * For singly-used continuations, the continuation's body is | 375 // * For singly-used continuations, the continuation's body is |
| 371 // translated at the site of the continuation invocation. | 376 // translated at the site of the continuation invocation. |
| 372 // * For recursive continuations, there is a single non-recursive | 377 // * For recursive continuations, there is a single non-recursive |
| 373 // invocation. The continuation's body is translated at the site | 378 // invocation. The continuation's body is translated at the site |
| 374 // of the non-recursive continuation invocation. | 379 // of the non-recursive continuation invocation. |
| 375 // See visitInvokeContinuation for the implementation. | 380 // See visitInvokeContinuation for the implementation. |
| 376 if (label == null || node.continuation.isRecursive) return body; | 381 Statement current = body; |
| 377 return new LabeledStatement(label, body, visit(node.continuation.body)); | 382 for (cps_ir.Continuation continuation in node.continuations.reversed) { |
| 383 Label label = labels[continuation]; |
| 384 if (label != null && !continuation.isRecursive) { |
| 385 current = |
| 386 new LabeledStatement(label, current, visit(continuation.body)); |
| 387 } |
| 388 } |
| 389 return current; |
| 378 } | 390 } |
| 379 | 391 |
| 380 Statement visitInvokeStatic(cps_ir.InvokeStatic node) { | 392 Statement visitInvokeStatic(cps_ir.InvokeStatic node) { |
| 381 // Calls are translated to direct style. | 393 // Calls are translated to direct style. |
| 382 List<Expression> arguments = translateArguments(node.arguments); | 394 List<Expression> arguments = translateArguments(node.arguments); |
| 383 Expression invoke = new InvokeStatic(node.target, node.selector, arguments); | 395 Expression invoke = new InvokeStatic(node.target, node.selector, arguments); |
| 384 return continueWithExpression(node.continuation, invoke); | 396 return continueWithExpression(node.continuation, invoke); |
| 385 } | 397 } |
| 386 | 398 |
| 387 Statement visitInvokeMethod(cps_ir.InvokeMethod node) { | 399 Statement visitInvokeMethod(cps_ir.InvokeMethod node) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // visited. | 570 // visited. |
| 559 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node.'); | 571 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node.'); |
| 560 return null; | 572 return null; |
| 561 } | 573 } |
| 562 | 574 |
| 563 Expression visitIsTrue(cps_ir.IsTrue node) { | 575 Expression visitIsTrue(cps_ir.IsTrue node) { |
| 564 return getVariableReference(node.value); | 576 return getVariableReference(node.value); |
| 565 } | 577 } |
| 566 } | 578 } |
| 567 | 579 |
| OLD | NEW |