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 code_generator; | 5 library code_generator; |
6 | 6 |
7 import 'glue.dart'; | 7 import 'glue.dart'; |
8 | 8 |
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; | 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; |
10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; | 10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator; |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 js.Expression visitCreateInvocationMirror( | 607 js.Expression visitCreateInvocationMirror( |
608 tree_ir.CreateInvocationMirror node) { | 608 tree_ir.CreateInvocationMirror node) { |
609 js.Expression name = js.string(node.selector.name); | 609 js.Expression name = js.string(node.selector.name); |
610 js.Expression internalName = js.string(glue.invocationName(node.selector)); | 610 js.Expression internalName = js.string(glue.invocationName(node.selector)); |
611 js.Expression kind = js.number(node.selector.invocationMirrorKind); | 611 js.Expression kind = js.number(node.selector.invocationMirrorKind); |
612 js.Expression arguments = new js.ArrayInitializer( | 612 js.Expression arguments = new js.ArrayInitializer( |
613 visitExpressionList(node.arguments)); | 613 visitExpressionList(node.arguments)); |
614 js.Expression argumentNames = new js.ArrayInitializer( | 614 js.Expression argumentNames = new js.ArrayInitializer( |
615 node.selector.namedArguments.map(js.string).toList(growable: false)); | 615 node.selector.namedArguments.map(js.string).toList(growable: false)); |
616 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, | 616 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, |
617 [name, internalName, kind, arguments, argumentNames]); | 617 <js.Expression>[name, internalName, kind, arguments, argumentNames]); |
618 } | 618 } |
619 | 619 |
620 @override | 620 @override |
621 js.Expression visitGetField(tree_ir.GetField node) { | 621 js.Expression visitGetField(tree_ir.GetField node) { |
622 return new js.PropertyAccess.field( | 622 return new js.PropertyAccess.field( |
623 visitExpression(node.object), | 623 visitExpression(node.object), |
624 glue.instanceFieldPropertyName(node.field)); | 624 glue.instanceFieldPropertyName(node.field)); |
625 } | 625 } |
626 | 626 |
627 @override | 627 @override |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 [visitExpression(node.target), index]); | 693 [visitExpression(node.target), index]); |
694 } | 694 } |
695 } | 695 } |
696 | 696 |
697 @override | 697 @override |
698 js.Expression visitTypeExpression(tree_ir.TypeExpression node) { | 698 js.Expression visitTypeExpression(tree_ir.TypeExpression node) { |
699 List<js.Expression> arguments = visitExpressionList(node.arguments); | 699 List<js.Expression> arguments = visitExpressionList(node.arguments); |
700 return glue.generateTypeRepresentation(node.dartType, arguments); | 700 return glue.generateTypeRepresentation(node.dartType, arguments); |
701 } | 701 } |
702 | 702 |
| 703 js.Node handleForeignCode(tree_ir.ForeignCode node) { |
| 704 registry.registerStaticUse(node.dependency); |
| 705 return node.codeTemplate.instantiate(visitExpressionList(node.arguments)); |
| 706 } |
| 707 |
| 708 @override |
| 709 js.Expression visitForeignExpression(tree_ir.ForeignExpression node) { |
| 710 return handleForeignCode(node); |
| 711 } |
| 712 |
| 713 @override |
| 714 visitForeignStatement(tree_ir.ForeignStatement node) { |
| 715 return handleForeignCode(node); |
| 716 } |
| 717 |
703 @override | 718 @override |
704 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) { | 719 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) { |
705 List<js.Expression> args = visitExpressionList(node.arguments); | 720 List<js.Expression> args = visitExpressionList(node.arguments); |
706 switch (node.operator) { | 721 switch (node.operator) { |
707 case BuiltinOperator.NumAdd: | 722 case BuiltinOperator.NumAdd: |
708 return new js.Binary('+', args[0], args[1]); | 723 return new js.Binary('+', args[0], args[1]); |
709 case BuiltinOperator.NumSubtract: | 724 case BuiltinOperator.NumSubtract: |
710 return new js.Binary('-', args[0], args[1]); | 725 return new js.Binary('-', args[0], args[1]); |
711 case BuiltinOperator.NumMultiply: | 726 case BuiltinOperator.NumMultiply: |
712 return new js.Binary('*', args[0], args[1]); | 727 return new js.Binary('*', args[0], args[1]); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 return js.js("typeof # === 'number' && Math.floor(#) === #", args); | 759 return js.js("typeof # === 'number' && Math.floor(#) === #", args); |
745 } | 760 } |
746 } | 761 } |
747 | 762 |
748 visitFunctionExpression(tree_ir.FunctionExpression node) { | 763 visitFunctionExpression(tree_ir.FunctionExpression node) { |
749 // FunctionExpressions are currently unused. | 764 // FunctionExpressions are currently unused. |
750 // We might need them if we want to emit raw JS nested functions. | 765 // We might need them if we want to emit raw JS nested functions. |
751 throw 'FunctionExpressions should not be used'; | 766 throw 'FunctionExpressions should not be used'; |
752 } | 767 } |
753 } | 768 } |
OLD | NEW |