| 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 /** | 5 /** |
| 6 * Dart backend helper for converting program IR back to source code. | 6 * Dart backend helper for converting program IR back to source code. |
| 7 */ | 7 */ |
| 8 class Emitter { | 8 class Emitter { |
| 9 | 9 |
| 10 final Compiler compiler; | 10 final Compiler compiler; |
| 11 final StringBuffer sb; | 11 final StringBuffer sb; |
| 12 final Renamer renamer; | 12 final ConflictingRenamer renamer; |
| 13 | 13 |
| 14 Emitter(Compiler compiler) : | 14 Emitter(Compiler compiler) : |
| 15 this.compiler = compiler, | 15 this.compiler = compiler, |
| 16 sb = new StringBuffer(), | 16 sb = new StringBuffer(), |
| 17 renamer = new ConflictingRenamer(compiler); | 17 renamer = new ConflictingRenamer(compiler); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Outputs given class element with selected inner elements. | 20 * Outputs given class element with selected inner elements. |
| 21 */ | 21 */ |
| 22 void outputClass(ClassElement classElement, Set<Element> innerElements) { | 22 void outputClass(ClassElement classElement, Set<Element> innerElements) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (element is SynthesizedConstructorElement | 65 if (element is SynthesizedConstructorElement |
| 66 || element is AbstractFieldElement) return; | 66 || element is AbstractFieldElement) return; |
| 67 if (element.isField()) { | 67 if (element.isField()) { |
| 68 assert(element is VariableElement); | 68 assert(element is VariableElement); |
| 69 sb.add(unparser.unparse(element.variables.parseNode(compiler))); | 69 sb.add(unparser.unparse(element.variables.parseNode(compiler))); |
| 70 } else { | 70 } else { |
| 71 sb.add(unparser.unparse(element.parseNode(compiler))); | 71 sb.add(unparser.unparse(element.parseNode(compiler))); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 String toString() => sb.toString(); | 75 String toString() { |
| 76 final result = new StringBuffer(); |
| 77 final libraries = compiler.libraries; |
| 78 for (final uri in libraries.getKeys()) { |
| 79 // Same library element may be a value for different uris as of now |
| 80 // e.g., core libraryElement is a value for both keys 'dart:core' |
| 81 // and full file name. Only care about uris with dart scheme. |
| 82 if (!uri.startsWith('dart:')) continue; |
| 83 final lib = libraries[uri]; |
| 84 if (renamer.imports.containsKey(lib)) { |
| 85 result.add('#import("$uri", prefix: "${renamer.imports[lib]}");'); |
| 86 } |
| 87 } |
| 88 result.add(sb); |
| 89 return result.toString(); |
| 90 } |
| 76 } | 91 } |
| OLD | NEW |