Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
| 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
| 9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
| 10 class ElementAst { | 10 class ElementAst { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return new Block(rewriteNodeList(statements, builder.toLink())); | 115 return new Block(rewriteNodeList(statements, builder.toLink())); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 class DartBackend extends Backend { | 119 class DartBackend extends Backend { |
| 120 final List<CompilerTask> tasks; | 120 final List<CompilerTask> tasks; |
| 121 final bool forceStripTypes; | 121 final bool forceStripTypes; |
| 122 final bool stripAsserts; | 122 final bool stripAsserts; |
| 123 // TODO(antonm): make available from command-line options. | 123 // TODO(antonm): make available from command-line options. |
| 124 final bool outputAst = false; | 124 final bool outputAst = false; |
| 125 final bool mirrorHelping = false; | |
| 125 | 126 |
| 126 Map<Element, TreeElements> get resolvedElements => | 127 Map<Element, TreeElements> get resolvedElements => |
| 127 compiler.enqueuer.resolution.resolvedElements; | 128 compiler.enqueuer.resolution.resolvedElements; |
| 128 | 129 |
| 129 /** | 130 /** |
| 130 * Tells whether it is safe to remove type declarations from variables, | 131 * Tells whether it is safe to remove type declarations from variables, |
| 131 * functions parameters. It becomes not safe if: | 132 * functions parameters. It becomes not safe if: |
| 132 * 1) TypeError is used somewhere in the code, | 133 * 1) TypeError is used somewhere in the code, |
| 133 * 2) The code has typedefs in right hand side of IS checks, | 134 * 2) The code has typedefs in right hand side of IS checks, |
| 134 * 3) The code has classes which extend typedefs, have type arguments typedefs | 135 * 3) The code has classes which extend typedefs, have type arguments typedefs |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 topLevelNodes.add(elementAsts[element].ast); | 437 topLevelNodes.add(elementAsts[element].ast); |
| 437 if (element.isClass() && !element.isMixinApplication) { | 438 if (element.isClass() && !element.isMixinApplication) { |
| 438 final members = <Node>[]; | 439 final members = <Node>[]; |
| 439 for (final member in sortedClassMembers[element]) { | 440 for (final member in sortedClassMembers[element]) { |
| 440 members.add(elementAsts[member].ast); | 441 members.add(elementAsts[member].ast); |
| 441 } | 442 } |
| 442 memberNodes[elementAsts[element].ast] = members; | 443 memberNodes[elementAsts[element].ast] = members; |
| 443 } | 444 } |
| 444 } | 445 } |
| 445 | 446 |
| 447 bool mirrorLibraryIsInUse() { | |
| 448 return compiler.libraries.values.contains(compiler.mirrorsLibrary); | |
|
ahe
2013/07/31 13:16:28
This would have the same effect and be a little fa
zarah
2013/08/02 07:53:41
Done.
| |
| 449 } | |
| 450 | |
| 451 MirrorCollector mirrorCollector = | |
| 452 new MirrorCollector(renames, imports, compiler, elementAsts); | |
| 453 collectMirrorElements(element) { | |
| 454 mirrorCollector.collect(element); | |
| 455 if (element.isClass()) { | |
| 456 classMembers[element].forEach(collectMirrorElements); | |
| 457 } | |
| 458 } | |
| 459 | |
| 460 if(mirrorHelping && mirrorLibraryIsInUse()) { | |
|
ahe
2013/07/31 13:16:28
Add space after if.
zarah
2013/08/02 07:53:41
Done.
| |
| 461 topLevelElements.forEach(collectMirrorElements); | |
| 462 } | |
| 463 | |
| 446 final unparser = new EmitterUnparser(renames); | 464 final unparser = new EmitterUnparser(renames); |
| 447 emitCode(unparser, imports, topLevelNodes, memberNodes); | 465 emitCode(unparser, imports, topLevelNodes, memberNodes); |
| 448 compiler.assembledCode = unparser.result; | 466 compiler.assembledCode = unparser.result; |
| 449 | 467 |
| 450 // Output verbose info about size ratio of resulting bundle to all | 468 // Output verbose info about size ratio of resulting bundle to all |
| 451 // referenced non-platform sources. | 469 // referenced non-platform sources. |
| 452 logResultBundleSizeInfo(topLevelElements); | 470 logResultBundleSizeInfo(topLevelElements); |
| 453 } | 471 } |
| 454 | 472 |
| 455 void logResultBundleSizeInfo(Set<Element> topLevelElements) { | 473 void logResultBundleSizeInfo(Set<Element> topLevelElements) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 } | 564 } |
| 547 | 565 |
| 548 compareElements(e0, e1) { | 566 compareElements(e0, e1) { |
| 549 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); | 567 int result = compareBy((e) => e.getLibrary().canonicalUri.toString())(e0, e1); |
| 550 if (result != 0) return result; | 568 if (result != 0) return result; |
| 551 return compareBy((e) => e.position().charOffset)(e0, e1); | 569 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 552 } | 570 } |
| 553 | 571 |
| 554 List<Element> sortElements(Iterable<Element> elements) => | 572 List<Element> sortElements(Iterable<Element> elements) => |
| 555 sorted(elements, compareElements); | 573 sorted(elements, compareElements); |
| OLD | NEW |