| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 @override | 159 @override |
| 160 js.Expression visitFunctionExpression(tree_ir.FunctionExpression node) { | 160 js.Expression visitFunctionExpression(tree_ir.FunctionExpression node) { |
| 161 return giveup(node); | 161 return giveup(node); |
| 162 // TODO: implement visitFunctionExpression | 162 // TODO: implement visitFunctionExpression |
| 163 } | 163 } |
| 164 | 164 |
| 165 js.Expression compileConstant(ParameterElement parameter) { | 165 js.Expression compileConstant(ParameterElement parameter) { |
| 166 return buildConstant(glue.getConstantForVariable(parameter).value); | 166 return buildConstant(glue.getConstantForVariable(parameter).value); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // TODO(karlklose): get rid of the selector argument. |
| 169 js.Expression buildStaticInvoke(Selector selector, | 170 js.Expression buildStaticInvoke(Selector selector, |
| 170 Element target, | 171 Element target, |
| 171 List<js.Expression> arguments) { | 172 List<js.Expression> arguments) { |
| 172 registry.registerStaticInvocation(target.declaration); | 173 registry.registerStaticInvocation(target.declaration); |
| 173 if (target == glue.getInterceptorMethod) { | 174 if (target == glue.getInterceptorMethod) { |
| 174 // This generates a call to the specialized interceptor function, which | 175 // This generates a call to the specialized interceptor function, which |
| 175 // does not have a specialized element yet, but is emitted as a stub from | 176 // does not have a specialized element yet, but is emitted as a stub from |
| 176 // the emitter in [InterceptorStubGenerator]. | 177 // the emitter in [InterceptorStubGenerator]. |
| 177 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity] | 178 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity] |
| 178 // instead of an [Element] and model the getInterceptor functions as | 179 // instead of an [Element] and model the getInterceptor functions as |
| 179 // [Entity]s or add a specialized Tree-IR node for interceptor calls. | 180 // [Entity]s or add a specialized Tree-IR node for interceptor calls. |
| 180 registry.registerUseInterceptor(); | 181 registry.registerUseInterceptor(); |
| 181 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary(); | 182 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary(); |
| 182 return js.propertyCall(interceptorLibrary, selector.name, arguments); | 183 return js.propertyCall(interceptorLibrary, selector.name, arguments); |
| 183 } else { | 184 } else { |
| 184 js.Expression elementAccess = glue.staticFunctionAccess(target); | 185 js.Expression elementAccess = glue.staticFunctionAccess(target); |
| 185 List<js.Expression> compiledArguments = | 186 return new js.Call(elementAccess, arguments); |
| 186 selector.makeArgumentsList(target.implementation, | |
| 187 arguments, | |
| 188 compileConstant); | |
| 189 return new js.Call(elementAccess, compiledArguments); | |
| 190 } | 187 } |
| 191 } | 188 } |
| 192 | 189 |
| 190 List<js.Expression> compileStaticArgumentList( |
| 191 Selector selector, |
| 192 Element target, /* TODO(karlklose): this should be the signature. */ |
| 193 List<tree_ir.Expression> arguments) { |
| 194 return selector.makeArgumentsList( |
| 195 target.implementation, |
| 196 visitArguments(arguments), |
| 197 compileConstant); |
| 198 } |
| 199 |
| 193 @override | 200 @override |
| 194 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { | 201 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { |
| 195 if (node.constant != null) return giveup(node); | 202 if (node.constant != null) return giveup(node); |
| 196 registry.registerInstantiatedClass(node.target.enclosingClass); | 203 registry.registerInstantiatedClass(node.target.enclosingClass); |
| 197 return buildStaticInvoke(node.selector, | 204 Selector selector = node.selector; |
| 198 node.target, | 205 FunctionElement target = node.target; |
| 199 visitArguments(node.arguments)); | 206 List<js.Expression> arguments = |
| 207 compileStaticArgumentList(selector, target, node.arguments); |
| 208 return buildStaticInvoke(selector, target, arguments); |
| 200 } | 209 } |
| 201 | 210 |
| 202 void registerMethodInvoke(tree_ir.InvokeMethod node) { | 211 void registerMethodInvoke(tree_ir.InvokeMethod node) { |
| 203 Selector selector = node.selector; | 212 Selector selector = node.selector; |
| 204 if (selector.isGetter) { | 213 if (selector.isGetter) { |
| 205 registry.registerDynamicGetter(selector); | 214 registry.registerDynamicGetter(selector); |
| 206 } else if (selector.isSetter) { | 215 } else if (selector.isSetter) { |
| 207 registry.registerDynamicSetter(selector); | 216 registry.registerDynamicSetter(selector); |
| 208 } else { | 217 } else { |
| 209 assert(invariant(CURRENT_ELEMENT_SPANNABLE, | 218 assert(invariant(CURRENT_ELEMENT_SPANNABLE, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 222 return js.propertyCall(visitExpression(node.receiver), | 231 return js.propertyCall(visitExpression(node.receiver), |
| 223 glue.invocationName(node.selector), | 232 glue.invocationName(node.selector), |
| 224 visitArguments(node.arguments)); | 233 visitArguments(node.arguments)); |
| 225 } | 234 } |
| 226 | 235 |
| 227 @override | 236 @override |
| 228 js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) { | 237 js.Expression visitInvokeStatic(tree_ir.InvokeStatic node) { |
| 229 if (node.target is! FunctionElement) { | 238 if (node.target is! FunctionElement) { |
| 230 giveup(node, 'static getters and setters are not supported.'); | 239 giveup(node, 'static getters and setters are not supported.'); |
| 231 } | 240 } |
| 232 return buildStaticInvoke(node.selector, | 241 Selector selector = node.selector; |
| 233 node.target, | 242 FunctionElement target = node.target; |
| 234 visitArguments(node.arguments)); | 243 List<js.Expression> arguments = |
| 244 compileStaticArgumentList(selector, target, node.arguments); |
| 245 return buildStaticInvoke(selector, target, arguments); |
| 235 } | 246 } |
| 236 | 247 |
| 237 @override | 248 @override |
| 238 js.Expression visitInvokeMethodDirectly(tree_ir.InvokeMethodDirectly node) { | 249 js.Expression visitInvokeMethodDirectly(tree_ir.InvokeMethodDirectly node) { |
| 239 registry.registerDirectInvocation(node.target.declaration); | 250 registry.registerDirectInvocation(node.target.declaration); |
| 240 if (node.target is ConstructorBodyElement) { | 251 if (node.target is ConstructorBodyElement) { |
| 241 // A constructor body cannot be overriden or intercepted, so we can | 252 // A constructor body cannot be overriden or intercepted, so we can |
| 242 // use the short form for this invocation. | 253 // use the short form for this invocation. |
| 243 // TODO(asgerf): prevent name clash between constructor bodies. | 254 // TODO(asgerf): prevent name clash between constructor bodies. |
| 244 return js.js('#.#(#)', | 255 return js.js('#.#(#)', |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 void visitSetField(tree_ir.SetField node) { | 493 void visitSetField(tree_ir.SetField node) { |
| 483 js.PropertyAccess field = | 494 js.PropertyAccess field = |
| 484 new js.PropertyAccess.field( | 495 new js.PropertyAccess.field( |
| 485 visitExpression(node.object), | 496 visitExpression(node.object), |
| 486 glue.instanceFieldPropertyName(node.field)); | 497 glue.instanceFieldPropertyName(node.field)); |
| 487 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); | 498 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); |
| 488 accumulator.add(new js.ExpressionStatement(asn)); | 499 accumulator.add(new js.ExpressionStatement(asn)); |
| 489 visitStatement(node.next); | 500 visitStatement(node.next); |
| 490 } | 501 } |
| 491 } | 502 } |
| OLD | NEW |