| 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 class DartBackend extends Backend { | 5 class DartBackend extends Backend { |
| 6 final List<CompilerTask> tasks; | 6 final List<CompilerTask> tasks; |
| 7 | 7 |
| 8 Map<Element, TreeElements> get resolvedElements() => | 8 Map<Element, TreeElements> get resolvedElements() => |
| 9 compiler.enqueuer.resolution.resolvedElements; | 9 compiler.enqueuer.resolution.resolvedElements; |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && | 31 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && |
| 32 !isDartCoreLib(compiler, element.getLibrary()) && | 32 !isDartCoreLib(compiler, element.getLibrary()) && |
| 33 element is !AbstractFieldElement; | 33 element is !AbstractFieldElement; |
| 34 | 34 |
| 35 final emptyTreeElements = new TreeElementMapping(); | 35 final emptyTreeElements = new TreeElementMapping(); |
| 36 | 36 |
| 37 Set<Element> topLevelElements = new Set<Element>(); | 37 Set<Element> topLevelElements = new Set<Element>(); |
| 38 Map<ClassElement, Set<Element>> classMembers = | 38 Map<ClassElement, Set<Element>> classMembers = |
| 39 new Map<ClassElement, Set<Element>>(); | 39 new Map<ClassElement, Set<Element>>(); |
| 40 | 40 |
| 41 PlaceholderCollector collector = new PlaceholderCollector(compiler); | 41 // Build all top level elements to emit and necessary class members. |
| 42 var newTypedefElementCallback, newClassElementCallback; | 42 var newTypedefElementCallback, newClassElementCallback; |
| 43 | 43 |
| 44 processElement(element, treeElements) { | 44 processElement(element, treeElements) { |
| 45 collector.collect(element, treeElements); | |
| 46 new ReferencedElementCollector( | 45 new ReferencedElementCollector( |
| 47 compiler, | 46 compiler, |
| 48 element, treeElements, | 47 element, treeElements, |
| 49 newTypedefElementCallback, newClassElementCallback).collect(); | 48 newTypedefElementCallback, newClassElementCallback).collect(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 addTopLevel(element, treeElements) { | 51 addTopLevel(element, treeElements) { |
| 53 if (topLevelElements.contains(element)) return; | 52 if (topLevelElements.contains(element)) return; |
| 54 topLevelElements.add(element); | 53 topLevelElements.add(element); |
| 55 processElement(element, treeElements); | 54 processElement(element, treeElements); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 80 classMembers[enclosingClass].add(element); | 79 classMembers[enclosingClass].add(element); |
| 81 processElement(element, treeElements); | 80 processElement(element, treeElements); |
| 82 } else { | 81 } else { |
| 83 if (!element.isTopLevel()) { | 82 if (!element.isTopLevel()) { |
| 84 compiler.cancel(reason: 'Cannot process $element', element: element); | 83 compiler.cancel(reason: 'Cannot process $element', element: element); |
| 85 } | 84 } |
| 86 addTopLevel(element, treeElements); | 85 addTopLevel(element, treeElements); |
| 87 } | 86 } |
| 88 }); | 87 }); |
| 89 | 88 |
| 89 // Create all necessary placeholders. |
| 90 PlaceholderCollector collector = new PlaceholderCollector(compiler); |
| 91 makePlaceholders(element) { |
| 92 TreeElements treeElements = resolvedElements[element]; |
| 93 if (treeElements === null) treeElements = emptyTreeElements; |
| 94 collector.collect(element, treeElements); |
| 95 if (element is ClassElement) { |
| 96 classMembers[element].forEach(makePlaceholders); |
| 97 } |
| 98 } |
| 99 topLevelElements.forEach(makePlaceholders); |
| 100 |
| 101 // Create renames. |
| 90 Map<Node, String> renames = new Map<Node, String>(); | 102 Map<Node, String> renames = new Map<Node, String>(); |
| 91 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); | 103 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); |
| 92 renamePlaceholders(compiler, collector, renames, imports); | 104 renamePlaceholders(compiler, collector, renames, imports); |
| 93 | 105 |
| 94 // Sort elements. | 106 // Sort elements. |
| 95 compareElements(e0, e1) { | 107 compareElements(e0, e1) { |
| 96 compareBy(x, y, f) => f(x).compareTo(f(y)); | 108 compareBy(x, y, f) => f(x).compareTo(f(y)); |
| 97 int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString()); | 109 int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString()); |
| 98 if (result != 0) return result; | 110 if (result != 0) return result; |
| 99 return compareBy(e0, e1, (e) => e.position().charOffset); | 111 return compareBy(e0, e1, (e) => e.position().charOffset); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (typeElement.isClass()) newClassElementCallback(typeElement); | 184 if (typeElement.isClass()) newClassElementCallback(typeElement); |
| 173 typeAnnotation.visitChildren(this); | 185 typeAnnotation.visitChildren(this); |
| 174 } | 186 } |
| 175 | 187 |
| 176 void collect() { | 188 void collect() { |
| 177 compiler.withCurrentElement(rootElement, () { | 189 compiler.withCurrentElement(rootElement, () { |
| 178 rootElement.parseNode(compiler).accept(this); | 190 rootElement.parseNode(compiler).accept(this); |
| 179 }); | 191 }); |
| 180 } | 192 } |
| 181 } | 193 } |
| OLD | NEW |