| 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 | 12 |
| 13 Emitter(this.compiler) : sb = new StringBuffer(); | 13 Emitter(this.compiler) : sb = new StringBuffer(); |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Outputs given class element with selected inner elements. | 16 * Outputs given class element with selected inner elements. |
| 17 */ | 17 */ |
| 18 void outputClass(ClassElement classElement, Set<Element> innerElements) { | 18 void outputClass(ClassElement classElement, Set<Element> innerElements) { |
| 19 // TODO(smok): Very soon properly print out correct class declaration with | 19 // TODO(smok): Very soon properly print out correct class declaration with |
| 20 // extends, implements, etc. | 20 // extends, implements, etc. |
| 21 sb.add(classElement.beginToken.slowToString()); // 'class' or 'interface'. | 21 sb.add(classElement.beginToken.slowToString()); // 'class' or 'interface'. |
| 22 sb.add(' '); | 22 sb.add(' '); |
| 23 sb.add(classElement.name.slowToString()); | 23 sb.add(classElement.name.slowToString()); |
| 24 if (classElement.isInterface() && classElement.defaultClause !== null) { |
| 25 sb.add(' default '); |
| 26 sb.add(classElement.defaultClause.unparse()); |
| 27 } |
| 28 if (!classElement.interfaces.isEmpty()) { |
| 29 sb.add(' implements '); |
| 30 classElement.interfaces.printOn(sb, ','); |
| 31 } |
| 24 sb.add('{'); | 32 sb.add('{'); |
| 25 innerElements.forEach((element) { | 33 innerElements.forEach((element) { |
| 26 // TODO(smok): Filter out default constructors here. | 34 // TODO(smok): Filter out default constructors here. |
| 27 outputElement(element); | 35 outputElement(element); |
| 28 }); | 36 }); |
| 29 sb.add('}'); | 37 sb.add('}'); |
| 30 } | 38 } |
| 31 | 39 |
| 32 void outputElement(Element element) { | 40 void outputElement(Element element) { |
| 33 // TODO(smok): Figure out why AbstractFieldElement appears here, | 41 // TODO(smok): Figure out why AbstractFieldElement appears here, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 // but unparse initializer manually. | 58 // but unparse initializer manually. |
| 51 sb.add(element.parseNode(compiler).unparse()); | 59 sb.add(element.parseNode(compiler).unparse()); |
| 52 sb.add(';'); | 60 sb.add(';'); |
| 53 } else { | 61 } else { |
| 54 sb.add(element.parseNode(compiler).unparse()); | 62 sb.add(element.parseNode(compiler).unparse()); |
| 55 } | 63 } |
| 56 } | 64 } |
| 57 | 65 |
| 58 String toString() => sb.toString(); | 66 String toString() => sb.toString(); |
| 59 } | 67 } |
| OLD | NEW |