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

Side by Side Diff: lib/compiler/implementation/emitter.dart

Issue 10310040: Sort the output (for now just the classes and instance members). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 8 years, 7 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) 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 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 buffer.add('"${fields[i]}"'); 419 buffer.add('"${fields[i]}"');
420 } 420 }
421 buffer.add(']'); 421 buffer.add(']');
422 } 422 }
423 buffer.add(', {\n'); 423 buffer.add(', {\n');
424 424
425 void defineInstanceMember(String name, String value) { 425 void defineInstanceMember(String name, String value) {
426 buffer.add(' $name: $value,\n'); 426 buffer.add(' $name: $value,\n');
427 } 427 }
428 428
429 List<Element> instanceMembers = <Element>[];
429 classElement.forEachMember(includeBackendMembers: true, 430 classElement.forEachMember(includeBackendMembers: true,
430 f: (ClassElement enclosing, Element member) { 431 f: (ClassElement enclosing, Element member) {
431 if (member.isInstanceMember()) { 432 if (member.isInstanceMember()) {
432 addInstanceMember(member, defineInstanceMember); 433 instanceMembers.add(member);
433 } 434 }
434 }); 435 });
436 instanceMembers.sort((Element member1, Element member2) {
437 return member1.compareTo(member2);
ngeoffray 2012/05/08 07:58:02 Should the list already be sorted? After all, thes
floitsch 2012/05/09 10:55:07 Removed sorting of instance members.
438 });
439 for (Element member in instanceMembers) {
440 addInstanceMember(member, defineInstanceMember);
441 }
435 442
436 generateTypeTests(classElement, (Element other) { 443 generateTypeTests(classElement, (Element other) {
437 if (nativeEmitter.requiresNativeIsCheck(other)) { 444 if (nativeEmitter.requiresNativeIsCheck(other)) {
438 defineInstanceMember(namer.operatorIs(other), 445 defineInstanceMember(namer.operatorIs(other),
439 'function() { return true; }'); 446 'function() { return true; }');
440 } else { 447 } else {
441 defineInstanceMember(namer.operatorIs(other), 'true'); 448 defineInstanceMember(namer.operatorIs(other), 'true');
442 } 449 }
443 }); 450 });
444 451
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 Set<ClassElement> neededClasses = 487 Set<ClassElement> neededClasses =
481 new Set<ClassElement>.from(instantiatedClasses); 488 new Set<ClassElement>.from(instantiatedClasses);
482 for (ClassElement element in instantiatedClasses) { 489 for (ClassElement element in instantiatedClasses) {
483 for (ClassElement superclass = element.superclass; 490 for (ClassElement superclass = element.superclass;
484 superclass !== null; 491 superclass !== null;
485 superclass = superclass.superclass) { 492 superclass = superclass.superclass) {
486 if (neededClasses.contains(superclass)) break; 493 if (neededClasses.contains(superclass)) break;
487 neededClasses.add(superclass); 494 neededClasses.add(superclass);
488 } 495 }
489 } 496 }
490 for (ClassElement element in neededClasses) { 497 List<ClassElement> sortedClasses =
498 new List<ClassElement>.from(neededClasses);
499 sortedClasses.sort((ClassElement class1, ClassElement class2) {
ngeoffray 2012/05/08 07:58:02 I guess this one is hard to sort eagerly. How abou
floitsch 2012/05/09 10:55:07 Done.
500 return class1.compareTo(class2);
501 });
502 for (ClassElement element in sortedClasses) {
491 generateClass(element, buffer); 503 generateClass(element, buffer);
492 } 504 }
493 505
494 // The closure class could have become necessary because of the generation 506 // The closure class could have become necessary because of the generation
495 // of stubs. 507 // of stubs.
496 ClassElement closureClass = compiler.closureClass; 508 ClassElement closureClass = compiler.closureClass;
497 if (needsClosureClass && !instantiatedClasses.contains(closureClass)) { 509 if (needsClosureClass && !instantiatedClasses.contains(closureClass)) {
498 generateClass(closureClass, buffer); 510 generateClass(closureClass, buffer);
499 } 511 }
500 } 512 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 // BoundClosure499(this.self); 575 // BoundClosure499(this.self);
564 // $call3(x, y, z) { return self.foo(x, y, z); } 576 // $call3(x, y, z) { return self.foo(x, y, z); }
565 // } 577 // }
566 578
567 // TODO(floitsch): share the closure classes with other classes 579 // TODO(floitsch): share the closure classes with other classes
568 // if they share methods with the same signature. 580 // if they share methods with the same signature.
569 581
570 // The closure class. 582 // The closure class.
571 SourceString name = const SourceString("BoundClosure"); 583 SourceString name = const SourceString("BoundClosure");
572 ClassElement closureClassElement = 584 ClassElement closureClassElement =
573 new ClosureClassElement(compiler, member.getCompilationUnit()); 585 new ClosureClassElement(compiler,
586 member.getCompilationUnit(),
587 member.position());
ngeoffray 2012/05/08 07:58:02 Maybe a FunctionElement should contain a list of c
floitsch 2012/05/09 10:55:07 change reverted.
574 String mangledName = namer.getName(closureClassElement); 588 String mangledName = namer.getName(closureClassElement);
575 String superName = namer.getName(closureClassElement.superclass); 589 String superName = namer.getName(closureClassElement.superclass);
576 needsClosureClass = true; 590 needsClosureClass = true;
577 591
578 // Define the constructor with a name so that Object.toString can 592 // Define the constructor with a name so that Object.toString can
579 // find the class name of the closure class. 593 // find the class name of the closure class.
580 boundClosureBuffer.add("$defineClassName('$mangledName', '$superName', "); 594 boundClosureBuffer.add("$defineClassName('$mangledName', '$superName', ");
581 boundClosureBuffer.add("function $name(self) { this.self = self; }, {\n"); 595 boundClosureBuffer.add("function $name(self) { this.self = self; }, {\n");
582 596
583 // Now add the methods on the closure class. The instance method does not 597 // Now add the methods on the closure class. The instance method does not
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 mainBuffer.add('function init() {\n'); 912 mainBuffer.add('function init() {\n');
899 mainBuffer.add(' $isolateProperties = {};\n'); 913 mainBuffer.add(' $isolateProperties = {};\n');
900 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); 914 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer);
901 emitFinishIsolateConstructor(mainBuffer); 915 emitFinishIsolateConstructor(mainBuffer);
902 mainBuffer.add('}\n'); 916 mainBuffer.add('}\n');
903 compiler.assembledCode = mainBuffer.toString(); 917 compiler.assembledCode = mainBuffer.toString();
904 }); 918 });
905 return compiler.assembledCode; 919 return compiler.assembledCode;
906 } 920 }
907 } 921 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/scanner/byte_strings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698