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

Side by Side Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 11026006: Do not put renaming logic into Unparser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 | « no previous file | lib/compiler/implementation/tree/unparser.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 const bool REMOVE_ASSERTS = false; 5 const bool REMOVE_ASSERTS = false;
6 6
7 class ElementAst { 7 class ElementAst {
8 final Node ast; 8 final Node ast;
9 final TreeElements treeElements; 9 final TreeElements treeElements;
10 10
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 topLevelNodes.add(elementAsts[element].ast); 416 topLevelNodes.add(elementAsts[element].ast);
417 if (element is ClassElement) { 417 if (element is ClassElement) {
418 final members = <Node>[]; 418 final members = <Node>[];
419 for (final member in sortedClassMembers[element]) { 419 for (final member in sortedClassMembers[element]) {
420 members.add(elementAsts[member].ast); 420 members.add(elementAsts[member].ast);
421 } 421 }
422 memberNodes[elementAsts[element].ast] = members; 422 memberNodes[elementAsts[element].ast] = members;
423 } 423 }
424 } 424 }
425 425
426 final unparser = new Unparser.withRenamer((Node node) => renames[node]); 426 final unparser = new EmitterUnparser(renames);
427 emitCode(unparser, imports, topLevelNodes, memberNodes); 427 emitCode(unparser, imports, topLevelNodes, memberNodes);
428 compiler.assembledCode = unparser.result; 428 compiler.assembledCode = unparser.result;
429 429
430 // Output verbose info about size ratio of resulting bundle to all 430 // Output verbose info about size ratio of resulting bundle to all
431 // referenced non-platform sources. 431 // referenced non-platform sources.
432 logResultBundleSizeInfo(topLevelElements); 432 logResultBundleSizeInfo(topLevelElements);
433 } 433 }
434 434
435 void logResultBundleSizeInfo(Set<Element> topLevelElements) { 435 void logResultBundleSizeInfo(Set<Element> topLevelElements) {
436 Collection<LibraryElement> referencedLibraries = 436 Collection<LibraryElement> referencedLibraries =
437 compiler.libraries.getValues().filter(isUserLibrary); 437 compiler.libraries.getValues().filter(isUserLibrary);
438 // Sum total size of scripts in each referenced library. 438 // Sum total size of scripts in each referenced library.
439 int nonPlatformSize = 0; 439 int nonPlatformSize = 0;
440 for (LibraryElement lib in referencedLibraries) { 440 for (LibraryElement lib in referencedLibraries) {
441 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { 441 for (CompilationUnitElement compilationUnit in lib.compilationUnits) {
442 nonPlatformSize += compilationUnit.script.text.length; 442 nonPlatformSize += compilationUnit.script.text.length;
443 } 443 }
444 } 444 }
445 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize; 445 int percentage = compiler.assembledCode.length * 100 ~/ nonPlatformSize;
446 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' 446 log('Total used non-platform files size: ${nonPlatformSize} bytes, '
447 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)'); 447 'bundle size: ${compiler.assembledCode.length} bytes (${percentage}%)');
448 } 448 }
449 449
450 log(String message) => compiler.log('[DartBackend] $message'); 450 log(String message) => compiler.log('[DartBackend] $message');
451 } 451 }
452 452
453 class EmitterUnparser extends Unparser {
454 final Map<Node, String> renames;
455
456 EmitterUnparser(this.renames);
457
458 visit(Node node) {
459 if (node !== null && renames.containsKey(node)) {
460 sb.add(renames[node]);
461 } else {
462 super.visit(node);
463 }
464 }
465
466 unparseSendReceiver(Send node, [bool spacesNeeded=false]) {
467 // TODO(smok): Remove ugly hack for library prefices.
Roman 2012/10/02 07:55:55 prefixes ?
Anton Muhin 2012/10/02 08:48:42 O tempora, o mores! Let's wait for Peter's opinio
468 if (node.receiver !== null && renames[node.receiver] == '') return;
ahe 2012/10/02 14:27:39 I'm not sure what problem this is solving. If you
Anton Muhin 2012/10/02 14:32:15 That'd be great, Peter. The problem. Imagine you
ahe 2012/10/09 07:40:59 Anton, could you give me an example with actual co
Anton Muhin 2012/10/10 07:21:40 I assume you're asking for code being transformed.
469 super.unparseSendReceiver(node, spacesNeeded);
470 }
471 }
472
473
453 /** 474 /**
454 * Some elements are not recorded by resolver now, 475 * Some elements are not recorded by resolver now,
455 * for example, typedefs or classes which are only 476 * for example, typedefs or classes which are only
456 * used in signatures, as/is operators or in super clauses 477 * used in signatures, as/is operators or in super clauses
457 * (just to name a few). Retraverse AST to pick those up. 478 * (just to name a few). Retraverse AST to pick those up.
458 */ 479 */
459 class ReferencedElementCollector extends Visitor { 480 class ReferencedElementCollector extends Visitor {
460 final Compiler compiler; 481 final Compiler compiler;
461 final Element rootElement; 482 final Element rootElement;
462 final TreeElements treeElements; 483 final TreeElements treeElements;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 530 }
510 531
511 compareElements(e0, e1) { 532 compareElements(e0, e1) {
512 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); 533 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1);
513 if (result != 0) return result; 534 if (result != 0) return result;
514 return compareBy((e) => e.position().charOffset)(e0, e1); 535 return compareBy((e) => e.position().charOffset)(e0, e1);
515 } 536 }
516 537
517 List<Element> sortElements(Collection<Element> elements) => 538 List<Element> sortElements(Collection<Element> elements) =>
518 sorted(elements, compareElements); 539 sorted(elements, compareElements);
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/tree/unparser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698