| 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 '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 10 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
| 10 import 'tree_ir_nodes.dart'; | 11 import 'tree_ir_nodes.dart'; |
| 11 | 12 |
| 12 /** | 13 /** |
| 13 * Builder translates from CPS-based IR to direct-style Tree. | 14 * Builder translates from CPS-based IR to direct-style Tree. |
| 14 * | 15 * |
| 15 * A call `Invoke(fun, cont, args)`, where cont is a singly-referenced | 16 * A call `Invoke(fun, cont, args)`, where cont is a singly-referenced |
| 16 * non-exit continuation `Cont(v, body)` is translated into a direct-style call | 17 * non-exit continuation `Cont(v, body)` is translated into a direct-style call |
| 17 * whose value is bound in the continuation body: | 18 * whose value is bound in the continuation body: |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 translateArguments(node.keys), | 433 translateArguments(node.keys), |
| 433 translateArguments(node.values)); | 434 translateArguments(node.values)); |
| 434 } | 435 } |
| 435 | 436 |
| 436 FunctionDefinition makeSubFunction(cps_ir.FunctionDefinition function) { | 437 FunctionDefinition makeSubFunction(cps_ir.FunctionDefinition function) { |
| 437 return new Builder.inner(this).build(function); | 438 return new Builder.inner(this).build(function); |
| 438 } | 439 } |
| 439 | 440 |
| 440 Node visitCreateFunction(cps_ir.CreateFunction node) { | 441 Node visitCreateFunction(cps_ir.CreateFunction node) { |
| 441 FunctionDefinition def = makeSubFunction(node.definition); | 442 FunctionDefinition def = makeSubFunction(node.definition); |
| 442 FunctionSignature signature = node.definition.element.functionSignature; | 443 FunctionType type = node.definition.element.type; |
| 443 bool hasReturnType = !signature.type.returnType.treatAsDynamic; | 444 bool hasReturnType = !type.returnType.treatAsDynamic; |
| 444 if (hasReturnType) { | 445 if (hasReturnType) { |
| 445 // This function cannot occur in expression context. | 446 // This function cannot occur in expression context. |
| 446 // The successor will be filled in by visitLetPrim. | 447 // The successor will be filled in by visitLetPrim. |
| 447 return new FunctionDeclaration(getVariable(node), def, null); | 448 return new FunctionDeclaration(getVariable(node), def, null); |
| 448 } else { | 449 } else { |
| 449 return new FunctionExpression(def); | 450 return new FunctionExpression(def); |
| 450 } | 451 } |
| 451 } | 452 } |
| 452 | 453 |
| 453 Expression visitParameter(cps_ir.Parameter node) { | 454 Expression visitParameter(cps_ir.Parameter node) { |
| 454 // Continuation parameters are not visited (continuations themselves are | 455 // Continuation parameters are not visited (continuations themselves are |
| 455 // not visited yet). | 456 // not visited yet). |
| 456 compiler.internalError(compiler.currentElement, 'Unexpected IR node.'); | 457 compiler.internalError(compiler.currentElement, 'Unexpected IR node.'); |
| 457 return null; | 458 return null; |
| 458 } | 459 } |
| 459 | 460 |
| 460 Expression visitContinuation(cps_ir.Continuation node) { | 461 Expression visitContinuation(cps_ir.Continuation node) { |
| 461 // Until continuations with multiple uses are supported, they are not | 462 // Until continuations with multiple uses are supported, they are not |
| 462 // visited. | 463 // visited. |
| 463 compiler.internalError(compiler.currentElement, 'Unexpected IR node.'); | 464 compiler.internalError(compiler.currentElement, 'Unexpected IR node.'); |
| 464 return null; | 465 return null; |
| 465 } | 466 } |
| 466 | 467 |
| 467 Expression visitIsTrue(cps_ir.IsTrue node) { | 468 Expression visitIsTrue(cps_ir.IsTrue node) { |
| 468 return getVariableReference(node.value); | 469 return getVariableReference(node.value); |
| 469 } | 470 } |
| 470 } | 471 } |
| 471 | 472 |
| OLD | NEW |