| 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 ElementAst { | 5 class ElementAst { |
| 6 final Node ast; | 6 final Node ast; |
| 7 final TreeElements treeElements; | 7 final TreeElements treeElements; |
| 8 | 8 |
| 9 ElementAst(this.ast, this.treeElements); | 9 ElementAst(this.ast, this.treeElements); |
| 10 |
| 11 factory ElementAst.clone(ast, treeElements) { |
| 12 final cloner = new CloningVisitor(treeElements); |
| 13 return new ElementAst(cloner.visit(ast), cloner.cloneTreeElements); |
| 14 } |
| 15 |
| 10 ElementAst.forClassLike(this.ast) | 16 ElementAst.forClassLike(this.ast) |
| 11 : this.treeElements = new TreeElementMapping(); | 17 : this.treeElements = new TreeElementMapping(); |
| 12 } | 18 } |
| 13 | 19 |
| 14 class AggregatedTreeElements extends TreeElementMapping { | 20 class AggregatedTreeElements extends TreeElementMapping { |
| 15 final List<TreeElements> treeElements; | 21 final List<TreeElements> treeElements; |
| 16 | 22 |
| 17 AggregatedTreeElements() : treeElements = <TreeElements>[]; | 23 AggregatedTreeElements() : treeElements = <TreeElements>[]; |
| 18 | 24 |
| 19 Element operator[](Node node) { | 25 Element operator[](Node node) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 new ElementAst.forClassLike(parse(element))); | 170 new ElementAst.forClassLike(parse(element))); |
| 165 }; | 171 }; |
| 166 newClassElementCallback = (ClassElement classElement) { | 172 newClassElementCallback = (ClassElement classElement) { |
| 167 if (!shouldOutput(classElement)) return; | 173 if (!shouldOutput(classElement)) return; |
| 168 addClass(classElement); | 174 addClass(classElement); |
| 169 }; | 175 }; |
| 170 | 176 |
| 171 resolvedElements.forEach((element, treeElements) { | 177 resolvedElements.forEach((element, treeElements) { |
| 172 if (!shouldOutput(element)) return; | 178 if (!shouldOutput(element)) return; |
| 173 | 179 |
| 174 var elementAst = new ElementAst(parse(element), treeElements); | 180 var elementAst = new ElementAst.clone(parse(element), treeElements); |
| 175 if (element.isField()) { | 181 if (element.isField()) { |
| 176 final list = (element as VariableElement).variables; | 182 final list = (element as VariableElement).variables; |
| 177 elementAst = elementAsts.putIfAbsent( | 183 elementAst = elementAsts.putIfAbsent( |
| 178 list, () => new VariableListAst(parse(list))); | 184 list, () => new VariableListAst(parse(list))); |
| 179 (elementAst as VariableListAst).add(element, treeElements); | 185 (elementAst as VariableListAst).add(element, treeElements); |
| 180 element = list; | 186 element = list; |
| 181 } | 187 } |
| 182 | 188 |
| 183 if (element.isMember()) { | 189 if (element.isMember()) { |
| 184 ClassElement enclosingClass = element.getEnclosingClass(); | 190 ClassElement enclosingClass = element.getEnclosingClass(); |
| 185 assert(enclosingClass.isClass()); | 191 assert(enclosingClass.isClass()); |
| 186 assert(enclosingClass.isTopLevel()); | 192 assert(enclosingClass.isTopLevel()); |
| 187 assert(shouldOutput(enclosingClass)); | 193 assert(shouldOutput(enclosingClass)); |
| 188 addClass(enclosingClass); | 194 addClass(enclosingClass); |
| 189 classMembers[enclosingClass].add(element); | 195 classMembers[enclosingClass].add(element); |
| 190 processElement(element, elementAst); | 196 processElement(element, elementAst); |
| 191 } else { | 197 } else { |
| 192 if (!element.isTopLevel()) { | 198 if (!element.isTopLevel()) { |
| 193 compiler.cancel(reason: 'Cannot process $element', element: element); | 199 compiler.cancel(reason: 'Cannot process $element', element: element); |
| 194 } | 200 } |
| 195 addTopLevel(element, elementAst); | 201 addTopLevel(element, elementAst); |
| 196 } | 202 } |
| 197 }); | 203 }); |
| 198 | 204 |
| 199 // Create all necessary placeholders. | 205 // Create all necessary placeholders. |
| 200 PlaceholderCollector collector = | 206 PlaceholderCollector collector = |
| 201 new PlaceholderCollector(compiler, fixedMemberNames); | 207 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts); |
| 202 makePlaceholders(element) { | 208 makePlaceholders(element) { |
| 203 collector.collect(element, elementAsts[element].treeElements); | 209 collector.collect(element); |
| 204 if (element is ClassElement) { | 210 if (element is ClassElement) { |
| 205 classMembers[element].forEach(makePlaceholders); | 211 classMembers[element].forEach(makePlaceholders); |
| 206 } | 212 } |
| 207 } | 213 } |
| 208 topLevelElements.forEach(makePlaceholders); | 214 topLevelElements.forEach(makePlaceholders); |
| 209 | 215 |
| 210 // Create renames. | 216 // Create renames. |
| 211 Map<Node, String> renames = new Map<Node, String>(); | 217 Map<Node, String> renames = new Map<Node, String>(); |
| 212 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); | 218 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); |
| 213 renamePlaceholders( | 219 renamePlaceholders( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 325 } |
| 320 | 326 |
| 321 compareElements(e0, e1) { | 327 compareElements(e0, e1) { |
| 322 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 328 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 323 if (result != 0) return result; | 329 if (result != 0) return result; |
| 324 return compareBy((e) => e.position().charOffset)(e0, e1); | 330 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 325 } | 331 } |
| 326 | 332 |
| 327 List<Element> sortElements(Collection<Element> elements) => | 333 List<Element> sortElements(Collection<Element> elements) => |
| 328 sorted(elements, compareElements); | 334 sorted(elements, compareElements); |
| OLD | NEW |