| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } else { | 199 } else { |
| 200 js.Expression elementAccess = glue.staticFunctionAccess(target); | 200 js.Expression elementAccess = glue.staticFunctionAccess(target); |
| 201 return new js.Call(elementAccess, arguments, | 201 return new js.Call(elementAccess, arguments, |
| 202 sourceInformation: sourceInformation); | 202 sourceInformation: sourceInformation); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 @override | 206 @override |
| 207 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { | 207 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { |
| 208 checkStaticTargetIsValid(node, node.target); | 208 checkStaticTargetIsValid(node, node.target); |
| 209 if (node.constant != null) return giveup(node); |
| 209 | 210 |
| 210 if (node.constant != null) return giveup(node); | 211 ClassElement instantiatedClass = node.target.enclosingClass; |
| 211 registry.registerInstantiatedClass(node.target.enclosingClass); | 212 registry.registerInstantiatedClass(instantiatedClass); |
| 212 Selector selector = node.selector; | 213 Selector selector = node.selector; |
| 213 FunctionElement target = node.target; | 214 FunctionElement target = node.target; |
| 214 List<js.Expression> arguments = visitArguments(node.arguments); | 215 List<js.Expression> arguments = visitArguments(node.arguments); |
| 215 return buildStaticInvoke(selector, target, arguments); | 216 return buildStaticInvoke(selector, target, arguments); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void registerMethodInvoke(tree_ir.InvokeMethod node) { | 219 void registerMethodInvoke(tree_ir.InvokeMethod node) { |
| 219 Selector selector = node.selector; | 220 Selector selector = node.selector; |
| 220 if (selector.isGetter) { | 221 if (selector.isGetter) { |
| 221 registry.registerDynamicGetter(selector); | 222 registry.registerDynamicGetter(selector); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 return giveup(node); | 494 return giveup(node); |
| 494 } | 495 } |
| 495 | 496 |
| 496 @override | 497 @override |
| 497 js.Expression visitCreateBox(tree_ir.CreateBox node) { | 498 js.Expression visitCreateBox(tree_ir.CreateBox node) { |
| 498 return new js.ObjectInitializer([]); | 499 return new js.ObjectInitializer([]); |
| 499 } | 500 } |
| 500 | 501 |
| 501 @override | 502 @override |
| 502 js.Expression visitCreateInstance(tree_ir.CreateInstance node) { | 503 js.Expression visitCreateInstance(tree_ir.CreateInstance node) { |
| 503 registry.registerInstantiatedClass(node.classElement); | 504 ClassElement cls = node.classElement; |
| 504 return new js.New(glue.constructorAccess(node.classElement), | 505 registry.registerInstantiatedClass(cls); |
| 505 node.arguments.map(visitExpression).toList()); | 506 js.Expression instance = new js.New( |
| 507 glue.constructorAccess(cls), |
| 508 node.arguments.map(visitExpression).toList()); |
| 509 |
| 510 List<tree_ir.Expression> typeInformation = node.typeInformation; |
| 511 assert(typeInformation.isEmpty || |
| 512 typeInformation.length == cls.typeVariables.length); |
| 513 if (typeInformation.isNotEmpty) { |
| 514 FunctionElement helper = glue.getAddRuntimeTypeInformation(); |
| 515 js.Expression typeArguments = new js.ArrayInitializer( |
| 516 typeInformation.map(visitExpression).toList()); |
| 517 return buildStaticHelperInvocation(helper, |
| 518 <js.Expression>[instance, typeArguments]); |
| 519 } else { |
| 520 return instance; |
| 521 } |
| 506 } | 522 } |
| 507 | 523 |
| 508 @override | 524 @override |
| 509 js.Expression visitGetField(tree_ir.GetField node) { | 525 js.Expression visitGetField(tree_ir.GetField node) { |
| 510 return new js.PropertyAccess.field( | 526 return new js.PropertyAccess.field( |
| 511 visitExpression(node.object), | 527 visitExpression(node.object), |
| 512 glue.instanceFieldPropertyName(node.field)); | 528 glue.instanceFieldPropertyName(node.field)); |
| 513 } | 529 } |
| 514 | 530 |
| 515 @override | 531 @override |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 return buildStaticHelperInvocation( | 564 return buildStaticHelperInvocation( |
| 549 glue.getTypeArgumentWithSubstitution(), | 565 glue.getTypeArgumentWithSubstitution(), |
| 550 [visitExpression(node.target), substitution, index]); | 566 [visitExpression(node.target), substitution, index]); |
| 551 } else { | 567 } else { |
| 552 return buildStaticHelperInvocation( | 568 return buildStaticHelperInvocation( |
| 553 glue.getTypeArgumentByIndex(), | 569 glue.getTypeArgumentByIndex(), |
| 554 [visitExpression(node.target), index]); | 570 [visitExpression(node.target), index]); |
| 555 } | 571 } |
| 556 } | 572 } |
| 557 | 573 |
| 574 @override |
| 575 js.Expression visitTypeExpression(tree_ir.TypeExpression node) { |
| 576 List<js.Expression> arguments = |
| 577 node.arguments.map(visitExpression).toList(growable: false); |
| 578 return glue.generateTypeRepresentation(node.dartType, arguments); |
| 579 } |
| 558 | 580 |
| 559 // Dart-specific IR nodes | 581 // Dart-specific IR nodes |
| 560 | 582 |
| 561 @override | 583 @override |
| 562 visitReifyTypeVar(tree_ir.ReifyTypeVar node) { | 584 visitReifyTypeVar(tree_ir.ReifyTypeVar node) { |
| 563 return errorUnsupportedNode(node); | 585 return errorUnsupportedNode(node); |
| 564 } | 586 } |
| 565 | 587 |
| 566 @override | 588 @override |
| 567 visitFunctionExpression(tree_ir.FunctionExpression node) { | 589 visitFunctionExpression(tree_ir.FunctionExpression node) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 580 | 602 |
| 581 @override | 603 @override |
| 582 visitSuperInitializer(tree_ir.SuperInitializer node) { | 604 visitSuperInitializer(tree_ir.SuperInitializer node) { |
| 583 return errorUnsupportedNode(node); | 605 return errorUnsupportedNode(node); |
| 584 } | 606 } |
| 585 | 607 |
| 586 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 608 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
| 587 throw "Unsupported node in JS backend: $node"; | 609 throw "Unsupported node in JS backend: $node"; |
| 588 } | 610 } |
| 589 } | 611 } |
| OLD | NEW |