| 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 TreeElements treeElements; | 6 final TreeElements treeElements; |
| 7 | 7 |
| 8 ElementAst(this.treeElements); | 8 ElementAst(this.treeElements); |
| 9 ElementAst.forClassLike() : this.treeElements = new TreeElementMapping(); | 9 ElementAst.forClassLike() : this.treeElements = new TreeElementMapping(); |
| 10 } | 10 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // Sort elements. | 210 // Sort elements. |
| 211 final sortedTopLevels = sortElements(topLevelElements); | 211 final sortedTopLevels = sortElements(topLevelElements); |
| 212 final sortedClassMembers = new Map<ClassElement, List<Element>>(); | 212 final sortedClassMembers = new Map<ClassElement, List<Element>>(); |
| 213 classMembers.forEach((classElement, members) { | 213 classMembers.forEach((classElement, members) { |
| 214 sortedClassMembers[classElement] = sortElements(members); | 214 sortedClassMembers[classElement] = sortElements(members); |
| 215 }); | 215 }); |
| 216 | 216 |
| 217 if (outputAst) { | 217 if (outputAst) { |
| 218 // TODO(antonm): Ideally XML should be a separate backend. | 218 // TODO(antonm): Ideally XML should be a separate backend. |
| 219 // TODO(antonm): obey renames and minification, at least as an option. | 219 // TODO(antonm): obey renames and minification, at least as an option. |
| 220 StringBuffer sb = new StringBuffer(); | 220 final unparser = new Unparser(); |
| 221 sb.add('<Program>\n'); | 221 outputElement(element) { unparser.unparse(element.parseNode(compiler)); } |
| 222 outputElement(element) { | |
| 223 sb.add(element.parseNode(compiler).toDebugString()); | |
| 224 } | |
| 225 | 222 |
| 226 // Emit XML for AST instead of the program. | 223 // Emit XML for AST instead of the program. |
| 227 for (final topLevel in sortedTopLevels) { | 224 for (final topLevel in sortedTopLevels) { |
| 228 if (topLevel is ClassElement) { | 225 if (topLevel is ClassElement) { |
| 229 // TODO(antonm): add some class info. | 226 // TODO(antonm): add some class info. |
| 230 sortedClassMembers[topLevel].forEach(outputElement); | 227 sortedClassMembers[topLevel].forEach(outputElement); |
| 231 } else { | 228 } else { |
| 232 outputElement(topLevel); | 229 outputElement(topLevel); |
| 233 } | 230 } |
| 234 } | 231 } |
| 235 sb.add('</Program>\n'); | 232 compiler.assembledCode = '<Program>\n${unparser.result}</Program>\n'; |
| 236 compiler.assembledCode = sb.toString(); | |
| 237 return; | 233 return; |
| 238 } | 234 } |
| 239 | 235 |
| 240 final unparser = new Unparser.withRenamer((Node node) => renames[node]); | 236 final unparser = new Unparser.withRenamer((Node node) => renames[node]); |
| 241 emitCode(compiler, unparser, imports, sortedTopLevels, sortedClassMembers); | 237 emitCode(compiler, unparser, imports, sortedTopLevels, sortedClassMembers); |
| 242 compiler.assembledCode = unparser.result; | 238 compiler.assembledCode = unparser.result; |
| 243 } | 239 } |
| 244 | 240 |
| 245 log(String message) => compiler.log('[DartBackend] $message'); | 241 log(String message) => compiler.log('[DartBackend] $message'); |
| 246 } | 242 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 299 } |
| 304 | 300 |
| 305 compareElements(e0, e1) { | 301 compareElements(e0, e1) { |
| 306 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 302 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
| 307 if (result != 0) return result; | 303 if (result != 0) return result; |
| 308 return compareBy((e) => e.position().charOffset)(e0, e1); | 304 return compareBy((e) => e.position().charOffset)(e0, e1); |
| 309 } | 305 } |
| 310 | 306 |
| 311 List<Element> sortElements(Collection<Element> elements) => | 307 List<Element> sortElements(Collection<Element> elements) => |
| 312 sorted(elements, compareElements); | 308 sorted(elements, compareElements); |
| OLD | NEW |