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 '../../js/js.dart' as js; | 10 import '../../js/js.dart' as js; |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 js.Expression visitCreateInvocationMirror( | 602 js.Expression visitCreateInvocationMirror( |
603 tree_ir.CreateInvocationMirror node) { | 603 tree_ir.CreateInvocationMirror node) { |
604 js.Expression name = js.string(node.selector.name); | 604 js.Expression name = js.string(node.selector.name); |
605 js.Expression internalName = js.string(glue.invocationName(node.selector)); | 605 js.Expression internalName = js.string(glue.invocationName(node.selector)); |
606 js.Expression kind = js.number(node.selector.invocationMirrorKind); | 606 js.Expression kind = js.number(node.selector.invocationMirrorKind); |
607 js.Expression arguments = new js.ArrayInitializer( | 607 js.Expression arguments = new js.ArrayInitializer( |
608 visitExpressionList(node.arguments)); | 608 visitExpressionList(node.arguments)); |
609 js.Expression argumentNames = new js.ArrayInitializer( | 609 js.Expression argumentNames = new js.ArrayInitializer( |
610 node.selector.namedArguments.map(js.string).toList(growable: false)); | 610 node.selector.namedArguments.map(js.string).toList(growable: false)); |
611 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, | 611 return buildStaticHelperInvocation(glue.createInvocationMirrorMethod, |
612 [name, internalName, kind, arguments, argumentNames]); | 612 <js.Expression>[name, internalName, kind, arguments, argumentNames]); |
613 } | 613 } |
614 | 614 |
615 @override | 615 @override |
616 js.Expression visitGetField(tree_ir.GetField node) { | 616 js.Expression visitGetField(tree_ir.GetField node) { |
617 return new js.PropertyAccess.field( | 617 return new js.PropertyAccess.field( |
618 visitExpression(node.object), | 618 visitExpression(node.object), |
619 glue.instanceFieldPropertyName(node.field)); | 619 glue.instanceFieldPropertyName(node.field)); |
620 } | 620 } |
621 | 621 |
622 @override | 622 @override |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 [visitExpression(node.target), index]); | 688 [visitExpression(node.target), index]); |
689 } | 689 } |
690 } | 690 } |
691 | 691 |
692 @override | 692 @override |
693 js.Expression visitTypeExpression(tree_ir.TypeExpression node) { | 693 js.Expression visitTypeExpression(tree_ir.TypeExpression node) { |
694 List<js.Expression> arguments = visitExpressionList(node.arguments); | 694 List<js.Expression> arguments = visitExpressionList(node.arguments); |
695 return glue.generateTypeRepresentation(node.dartType, arguments); | 695 return glue.generateTypeRepresentation(node.dartType, arguments); |
696 } | 696 } |
697 | 697 |
| 698 js.Node handleForeignCode(tree_ir.ForeignCode node) { |
| 699 registry.registerStaticUse(node.dependency); |
| 700 return node.codeTemplate.instantiate(visitExpressionList(node.arguments)); |
| 701 } |
| 702 |
| 703 @override |
| 704 js.Expression visitForeignExpression(tree_ir.ForeignExpression node) { |
| 705 return handleForeignCode(node); |
| 706 } |
| 707 |
| 708 @override |
| 709 visitForeignStatement(tree_ir.ForeignStatement node) { |
| 710 return handleForeignCode(node); |
| 711 } |
| 712 |
698 visitFunctionExpression(tree_ir.FunctionExpression node) { | 713 visitFunctionExpression(tree_ir.FunctionExpression node) { |
699 // FunctionExpressions are currently unused. | 714 // FunctionExpressions are currently unused. |
700 // We might need them if we want to emit raw JS nested functions. | 715 // We might need them if we want to emit raw JS nested functions. |
701 throw 'FunctionExpressions should not be used'; | 716 throw 'FunctionExpressions should not be used'; |
702 } | 717 } |
703 } | 718 } |
OLD | NEW |