| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 void checkStaticTargetIsValid(tree_ir.Node node, Element target) { | 250 void checkStaticTargetIsValid(tree_ir.Node node, Element target) { |
| 251 if (target.isErroneous) { | 251 if (target.isErroneous) { |
| 252 giveup(node, 'cannot generate error handling code' | 252 giveup(node, 'cannot generate error handling code' |
| 253 ' for call to unresolved target'); | 253 ' for call to unresolved target'); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 @override | 257 @override |
| 258 js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) { | 258 js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) { |
| 259 checkStaticTargetIsValid(node, node.target); | 259 checkStaticTargetIsValid(node, node.target); |
| 260 | 260 Selector selector = node.selector; |
| 261 if (node.target is! FunctionElement) { | 261 if (node.target is FunctionElement) { |
| 262 giveup(node, 'static getters and setters are not supported.'); | 262 assert(selector.isGetter || selector.isSetter || selector.isCall); |
| 263 FunctionElement target = node.target; |
| 264 List<js.Expression> arguments = visitArguments(node.arguments); |
| 265 return buildStaticInvoke(selector, target, arguments, |
| 266 sourceInformation: node.sourceInformation); |
| 267 } else { |
| 268 assert(selector.isGetter || selector.isSetter); |
| 269 FieldElement target = node.target; |
| 270 registry.registerStaticUse(target); |
| 271 js.Expression field = glue.staticFieldAccess(target); |
| 272 if (selector.isGetter) { |
| 273 assert(node.arguments.isEmpty); |
| 274 return field; |
| 275 } else { |
| 276 assert(node.arguments.length == 1); |
| 277 js.Expression value = visitExpression(node.arguments.first); |
| 278 return new js.Assignment(field, value); |
| 279 } |
| 263 } | 280 } |
| 264 Selector selector = node.selector; | |
| 265 FunctionElement target = node.target; | |
| 266 List<js.Expression> arguments = visitArguments(node.arguments); | |
| 267 return buildStaticInvoke(selector, target, arguments, | |
| 268 sourceInformation: node.sourceInformation); | |
| 269 } | 281 } |
| 270 | 282 |
| 271 @override | 283 @override |
| 272 js.Expression visitInvokeMethodDirectly(tree_ir.InvokeMethodDirectly node) { | 284 js.Expression visitInvokeMethodDirectly(tree_ir.InvokeMethodDirectly node) { |
| 273 registry.registerDirectInvocation(node.target.declaration); | 285 registry.registerDirectInvocation(node.target.declaration); |
| 274 if (node.target is ConstructorBodyElement) { | 286 if (node.target is ConstructorBodyElement) { |
| 275 // A constructor body cannot be overriden or intercepted, so we can | 287 // A constructor body cannot be overriden or intercepted, so we can |
| 276 // use the short form for this invocation. | 288 // use the short form for this invocation. |
| 277 return js.js('#.#(#)', | 289 return js.js('#.#(#)', |
| 278 [visitExpression(node.receiver), | 290 [visitExpression(node.receiver), |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 580 |
| 569 @override | 581 @override |
| 570 visitSuperInitializer(tree_ir.SuperInitializer node) { | 582 visitSuperInitializer(tree_ir.SuperInitializer node) { |
| 571 return errorUnsupportedNode(node); | 583 return errorUnsupportedNode(node); |
| 572 } | 584 } |
| 573 | 585 |
| 574 errorUnsupportedNode(tree_ir.DartSpecificNode node) { | 586 errorUnsupportedNode(tree_ir.DartSpecificNode node) { |
| 575 throw "Unsupported node in JS backend: $node"; | 587 throw "Unsupported node in JS backend: $node"; |
| 576 } | 588 } |
| 577 } | 589 } |
| OLD | NEW |