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

Side by Side Diff: frog/leg/emitter.dart

Issue 9414010: Allow method-calls to getters (assuming they contain closures). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and update status file. Created 8 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
« no previous file with comments | « frog/leg/compiler.dart ('k') | frog/leg/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Generates the code for all used classes in the program. Static fields (even 6 * Generates the code for all used classes in the program. Static fields (even
7 * in classes) are ignored, since they can be treated as non-class elements. 7 * in classes) are ignored, since they can be treated as non-class elements.
8 * 8 *
9 * The code for the containing (used) methods must exist in the [:universe:]. 9 * The code for the containing (used) methods must exist in the [:universe:].
10 */ 10 */
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (member.kind == ElementKind.FUNCTION) { 363 if (member.kind == ElementKind.FUNCTION) {
364 if (compiler.universe.invokedGetters.contains(member.name)) { 364 if (compiler.universe.invokedGetters.contains(member.name)) {
365 emitDynamicFunctionGetter(buffer, currentClass, member); 365 emitDynamicFunctionGetter(buffer, currentClass, member);
366 } 366 }
367 } 367 }
368 } 368 }
369 } 369 }
370 } 370 }
371 } 371 }
372 372
373 void emitCallStubForGetter(StringBuffer buffer,
374 ClassElement enclosingClass,
375 Element member,
376 Set<Selector> selectors) {
377 String prototype =
378 "${namer.isolatePropertyAccess(enclosingClass)}.prototype";
379 String getter;
380 if (member.kind == ElementKind.GETTER) {
381 getter = "this.${namer.getterName(member.name)}()";
382 } else {
383 getter = "this.${namer.instanceFieldName(member.name)}";
384 }
385 for (Selector selector in selectors) {
386 String invocationName =
387 namer.instanceMethodInvocationName(member.name, selector);
388 SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
389 String closureCallName =
390 namer.instanceMethodInvocationName(callName, selector);
391 List<String> arguments = <String>[];
392 for (int i = 0; i < selector.argumentCount; i++) {
393 arguments.add("arg$i");
394 }
395 String joined = Strings.join(arguments, ", ");
396 buffer.add("$prototype.$invocationName = function($joined) {\n");
397 buffer.add(" return $getter.$closureCallName($joined);\n");
398 buffer.add("};\n");
399 }
400 }
401
402 void emitCallStubForGetters(StringBuffer buffer) {
403 for (ClassElement classElement in compiler.universe.instantiatedClasses) {
404 for (ClassElement currentClass = classElement;
405 currentClass !== null;
406 currentClass = currentClass.superclass) {
407 // TODO(floitsch): we don't need to deal with members that have been
408 // overwritten by subclasses.
409 for (Element member in currentClass.members) {
410 if (!member.isInstanceMember()) continue;
411 if (member.kind == ElementKind.GETTER ||
412 member.kind == ElementKind.FIELD) {
413 Set<Selector> selectors =
414 compiler.universe.invokedNames[member.name];
415 if (selectors == null || selectors.isEmpty()) continue;
416 emitCallStubForGetter(buffer, currentClass, member, selectors);
417 }
418 }
419 }
420 }
421 }
422
373 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { 423 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) {
374 // Adds initializations inside the Isolate constructor. 424 // Adds initializations inside the Isolate constructor.
375 // Example: 425 // Example:
376 // function Isolate() { 426 // function Isolate() {
377 // this.staticNonFinal = Isolate.prototype.someVal; 427 // this.staticNonFinal = Isolate.prototype.someVal;
378 // ... 428 // ...
379 // } 429 // }
380 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; 430 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler;
381 List<VariableElement> staticNonFinalFields = 431 List<VariableElement> staticNonFinalFields =
382 constants.getStaticNonFinalFieldsForEmission(); 432 constants.getStaticNonFinalFieldsForEmission();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 measure(() { 506 measure(() {
457 StringBuffer buffer = new StringBuffer(); 507 StringBuffer buffer = new StringBuffer();
458 buffer.add('function ${namer.ISOLATE}() {'); 508 buffer.add('function ${namer.ISOLATE}() {');
459 emitStaticNonFinalFieldInitializations(buffer); 509 emitStaticNonFinalFieldInitializations(buffer);
460 buffer.add('}\n\n'); 510 buffer.add('}\n\n');
461 emitClasses(buffer); 511 emitClasses(buffer);
462 emitNoSuchMethodCalls(buffer); 512 emitNoSuchMethodCalls(buffer);
463 emitStaticFunctions(buffer); 513 emitStaticFunctions(buffer);
464 emitStaticFunctionGetters(buffer); 514 emitStaticFunctionGetters(buffer);
465 emitDynamicFunctionGetters(buffer); 515 emitDynamicFunctionGetters(buffer);
516 emitCallStubForGetters(buffer);
466 emitStaticFinalFieldInitializations(buffer); 517 emitStaticFinalFieldInitializations(buffer);
467 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 518 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
468 Element main = compiler.mainApp.find(Compiler.MAIN); 519 Element main = compiler.mainApp.find(Compiler.MAIN);
469 buffer.add('${namer.isolateAccess(main)}();\n'); 520 buffer.add('${namer.isolateAccess(main)}();\n');
470 compiler.assembledCode = buffer.toString(); 521 compiler.assembledCode = buffer.toString();
471 }); 522 });
472 return compiler.assembledCode; 523 return compiler.assembledCode;
473 } 524 }
474 } 525 }
OLDNEW
« no previous file with comments | « frog/leg/compiler.dart ('k') | frog/leg/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698