Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 861093002: Support intercepted getters, setters and index operations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Only reject instance members that need interceptors and disable a test that we do not support yet. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 js.Expression buildStaticInvoke(Selector selector, 169 js.Expression buildStaticInvoke(Selector selector,
170 Element target, 170 Element target,
171 List<js.Expression> arguments) { 171 List<js.Expression> arguments) {
172 registry.registerStaticInvocation(target.declaration); 172 registry.registerStaticInvocation(target.declaration);
173 js.Expression elementAccess = glue.staticFunctionAccess(target); 173 if (target == glue.getInterceptorMethod) {
174 List<js.Expression> compiledArguments = 174 // This generates a call to the specialized interceptor function, which
175 selector.makeArgumentsList(target.implementation, 175 // does not have a specialized element yet, but is emitted as a stub from
176 arguments, 176 // the emitter in [InterceptorStubGenerator].
177 compileConstant); 177 // TODO(karlklose): Either change [InvokeStatic] to take an [Entity]
178 return new js.Call(elementAccess, compiledArguments); 178 // instead of an [Element] and model the getInterceptor functions as
179 // [Entity]s or add a specialized Tree-IR node for interceptor calls.
180 registry.registerUseInterceptor();
181 js.VariableUse interceptorLibrary = glue.getInterceptorLibrary();
182 return js.propertyCall(interceptorLibrary, selector.name, arguments);
183 } else {
184 js.Expression elementAccess = glue.staticFunctionAccess(target);
185 List<js.Expression> compiledArguments =
186 selector.makeArgumentsList(target.implementation,
187 arguments,
188 compileConstant);
189 return new js.Call(elementAccess, compiledArguments);
190 }
179 } 191 }
180 192
181 @override 193 @override
182 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) { 194 js.Expression visitInvokeConstructor(tree_ir.InvokeConstructor node) {
183 if (node.constant != null) return giveup(node); 195 if (node.constant != null) return giveup(node);
184 registry.registerInstantiatedClass(node.target.enclosingClass); 196 registry.registerInstantiatedClass(node.target.enclosingClass);
185 return buildStaticInvoke(node.selector, 197 return buildStaticInvoke(node.selector,
186 node.target, 198 node.target,
187 visitArguments(node.arguments)); 199 visitArguments(node.arguments));
188 } 200 }
189 201
190 void registerMethodInvoke(tree_ir.InvokeMethod node) { 202 void registerMethodInvoke(tree_ir.InvokeMethod node) {
191 Selector selector = node.selector; 203 Selector selector = node.selector;
192 // TODO(sigurdm): We should find a better place to register the call. 204 if (selector.isGetter) {
193 Selector call = new Selector.callClosureFrom(selector); 205 registry.registerDynamicGetter(selector);
194 registry.registerDynamicInvocation(call); 206 } else if (selector.isSetter) {
195 registry.registerDynamicInvocation(selector); 207 registry.registerDynamicSetter(selector);
208 } else {
209 assert(invariant(CURRENT_ELEMENT_SPANNABLE,
210 selector.isCall || selector.isOperator || selector.isIndex,
211 message: 'unexpected kind ${selector.kind}'));
212 // TODO(sigurdm): We should find a better place to register the call.
213 Selector call = new Selector.callClosureFrom(selector);
214 registry.registerDynamicInvocation(call);
215 registry.registerDynamicInvocation(selector);
216 }
196 } 217 }
197 218
198 @override 219 @override
199 js.Expression visitInvokeMethod(tree_ir.InvokeMethod node) { 220 js.Expression visitInvokeMethod(tree_ir.InvokeMethod node) {
200 registerMethodInvoke(node); 221 registerMethodInvoke(node);
201 return js.propertyCall(visitExpression(node.receiver), 222 return js.propertyCall(visitExpression(node.receiver),
202 glue.invocationName(node.selector), 223 glue.invocationName(node.selector),
203 visitArguments(node.arguments)); 224 visitArguments(node.arguments));
204 } 225 }
205 226
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 void visitSetField(tree_ir.SetField node) { 482 void visitSetField(tree_ir.SetField node) {
462 js.PropertyAccess field = 483 js.PropertyAccess field =
463 new js.PropertyAccess.field( 484 new js.PropertyAccess.field(
464 visitExpression(node.object), 485 visitExpression(node.object),
465 glue.instanceFieldPropertyName(node.field)); 486 glue.instanceFieldPropertyName(node.field));
466 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); 487 js.Assignment asn = new js.Assignment(field, visitExpression(node.value));
467 accumulator.add(new js.ExpressionStatement(asn)); 488 accumulator.add(new js.ExpressionStatement(asn));
468 visitStatement(node.next); 489 visitStatement(node.next);
469 } 490 }
470 } 491 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698