OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Dart backend helper for converting program IR back to source code. |
| 7 */ |
| 8 class Emitter { |
| 9 |
| 10 final DiagnosticListener listener; |
| 11 final StringBuffer sb; |
| 12 |
| 13 Emitter(this.listener) : sb = new StringBuffer(); |
| 14 |
| 15 /** |
| 16 * Outputs given class element with selected inner elements. |
| 17 */ |
| 18 void outputClass(ClassElement classElement, Set<Element> innerElements) { |
| 19 // TODO(smok): Very soon properly print out correct class declaration with |
| 20 // extends, implements, etc. |
| 21 sb.add('class '); |
| 22 sb.add(classElement.name.slowToString()); |
| 23 sb.add('{'); |
| 24 innerElements.forEach((element) { |
| 25 // TODO(smok): Filter out default constructors here. |
| 26 outputElement(element); |
| 27 }); |
| 28 sb.add('}'); |
| 29 } |
| 30 |
| 31 void outputElement(Element element) { |
| 32 // TODO(smok): Figure out why AbstractFieldElement appears here, |
| 33 // we have used getters/setters resolved instead of it. |
| 34 if (element is SynthesizedConstructorElement |
| 35 || element is AbstractFieldElement) return; |
| 36 if (element.isField()) { |
| 37 // Add modifiers first. |
| 38 sb.add(element.modifiers.toString()); |
| 39 sb.add(' '); |
| 40 // Figure out type. |
| 41 if (element is VariableElement) { |
| 42 VariableListElement variables = element.variables; |
| 43 if (variables.type !== null) { |
| 44 sb.add(variables.type); |
| 45 sb.add(' '); |
| 46 } |
| 47 } |
| 48 // TODO(smok): Maybe not rely on node unparsing, |
| 49 // but unparse initializer manually. |
| 50 sb.add(element.parseNode(listener).unparse()); |
| 51 sb.add(';'); |
| 52 } else { |
| 53 if (element.isSetter()) { |
| 54 sb.add('set '); |
| 55 } else if (element.isGetter()) { |
| 56 sb.add('get '); |
| 57 } |
| 58 sb.add(element.parseNode(listener).unparse()); |
| 59 } |
| 60 } |
| 61 |
| 62 String toString() => sb.toString(); |
| 63 } |
OLD | NEW |