Chromium Code Reviews| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 js.Expression elementAccess = glue.staticFunctionAccess(target); | 173 js.Expression elementAccess = glue.staticFunctionAccess(target); |
| 174 List<js.Expression> compiledArguments = | 174 List<js.Expression> compiledArguments = |
| 175 selector.makeArgumentsList(target.implementation, | 175 selector.makeArgumentsList(target.implementation, |
| 176 arguments, | 176 arguments, |
| 177 compileConstant); | 177 compileConstant); |
| 178 return new js.Call(elementAccess, compiledArguments); | 178 return new js.Call(elementAccess, compiledArguments); |
| 179 } | 179 } |
| 180 | 180 |
| 181 @override | 181 @override |
| 182 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { | 182 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { |
| 183 checkStaticTargetIsValid(node, node.target); | |
| 184 | |
| 183 if (node.constant != null) return giveup(node); | 185 if (node.constant != null) return giveup(node); |
| 184 registry.registerInstantiatedClass(node.target.enclosingClass); | 186 registry.registerInstantiatedClass(node.target.enclosingClass); |
| 185 return buildStaticInvoke(node.selector, | 187 return buildStaticInvoke(node.selector, |
| 186 node.target, | 188 node.target, |
| 187 visitArguments(node.arguments)); | 189 visitArguments(node.arguments)); |
| 188 } | 190 } |
| 189 | 191 |
| 190 void registerMethodInvoke(tree_ir.InvokeMethod node) { | 192 void registerMethodInvoke(tree_ir.InvokeMethod node) { |
| 191 Selector selector = node.selector; | 193 Selector selector = node.selector; |
| 192 // TODO(sigurdm): We should find a better place to register the call. | 194 // TODO(sigurdm): We should find a better place to register the call. |
| 193 Selector call = new Selector.callClosureFrom(selector); | 195 Selector call = new Selector.callClosureFrom(selector); |
| 194 registry.registerDynamicInvocation(call); | 196 registry.registerDynamicInvocation(call); |
| 195 registry.registerDynamicInvocation(selector); | 197 registry.registerDynamicInvocation(selector); |
| 196 } | 198 } |
| 197 | 199 |
| 198 @override | 200 @override |
| 199 js.Expression visitInvokeMethod(tree_ir.InvokeMethod node) { | 201 js.Expression visitInvokeMethod(tree_ir.InvokeMethod node) { |
| 200 registerMethodInvoke(node); | 202 registerMethodInvoke(node); |
| 201 return js.propertyCall(visitExpression(node.receiver), | 203 return js.propertyCall(visitExpression(node.receiver), |
| 202 glue.invocationName(node.selector), | 204 glue.invocationName(node.selector), |
| 203 visitArguments(node.arguments)); | 205 visitArguments(node.arguments)); |
| 204 } | 206 } |
| 205 | 207 |
| 208 /// Checks that the target of the static call is not an [ErroneousElement]. | |
| 209 /// | |
| 210 /// This helper should be removed and the code to generate the CPS IR for | |
| 211 /// the dart2js backend should construct a call to a helper that throw an | |
| 212 /// appropriate error message instead of the static call. | |
|
asgerf
2015/02/06 10:12:40
Agreed.
| |
| 213 /// | |
| 214 /// See [SsaBuilder.visitStaticSend] as an example how to do this. | |
| 215 void checkStaticTargetIsValid(tree_ir.Node node, Element target) { | |
| 216 if (target.isErroneous) { | |
| 217 giveup(node, 'cannot generate error handling code' | |
| 218 ' for call to unresolved target'); | |
| 219 } | |
| 220 } | |
| 221 | |
| 206 @override | 222 @override |
| 207 js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) { | 223 js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) { |
| 224 checkStaticTargetIsValid(node, node.target); | |
| 225 | |
| 208 if (node.target is! FunctionElement) { | 226 if (node.target is! FunctionElement) { |
| 209 giveup(node, 'static getters and setters are not supported.'); | 227 giveup(node, 'static getters and setters are not supported.'); |
| 210 } | 228 } |
| 211 return buildStaticInvoke(node.selector, | 229 return buildStaticInvoke(node.selector, |
| 212 node.target, | 230 node.target, |
| 213 visitArguments(node.arguments)); | 231 visitArguments(node.arguments)); |
| 214 } | 232 } |
| 215 | 233 |
| 216 @override | 234 @override |
| 217 js.Expression visitInvokeMethodDirectly(tree_ir.InvokeMethodDirectly node) { | 235 js.Expression visitInvokeMethodDirectly(tree_ir.InvokeMethodDirectly node) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 void visitSetField(tree_ir.SetField node) { | 479 void visitSetField(tree_ir.SetField node) { |
| 462 js.PropertyAccess field = | 480 js.PropertyAccess field = |
| 463 new js.PropertyAccess.field( | 481 new js.PropertyAccess.field( |
| 464 visitExpression(node.object), | 482 visitExpression(node.object), |
| 465 glue.instanceFieldPropertyName(node.field)); | 483 glue.instanceFieldPropertyName(node.field)); |
| 466 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); | 484 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); |
| 467 accumulator.add(new js.ExpressionStatement(asn)); | 485 accumulator.add(new js.ExpressionStatement(asn)); |
| 468 visitStatement(node.next); | 486 visitStatement(node.next); |
| 469 } | 487 } |
| 470 } | 488 } |
| OLD | NEW |