Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: lib/compiler/implementation/dart_backend/emitter.dart

Issue 10694151: dart2dart introduce "emitter" that that generates source code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/dart_backend/dart_backend.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart_backend/emitter.dart
diff --git a/lib/compiler/implementation/dart_backend/emitter.dart b/lib/compiler/implementation/dart_backend/emitter.dart
new file mode 100644
index 0000000000000000000000000000000000000000..caa521969b62eb0561d2a99ec78cbfaa3a613fae
--- /dev/null
+++ b/lib/compiler/implementation/dart_backend/emitter.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/**
+ * Dart backend helper for converting program IR back to source code.
+ */
+class Emitter {
+
+ final DiagnosticListener listener;
+ final StringBuffer sb;
+
+ Emitter(this.listener) : sb = new StringBuffer();
+
+ /**
+ * Outputs given class element with selected inner elements.
+ */
+ void outputClass(ClassElement classElement, Set<Element> innerElements) {
+ // TODO(smok): Very soon properly print out correct class declaration with
+ // extends, implements, etc.
+ sb.add('class ');
+ sb.add(classElement.name.slowToString());
+ sb.add('{');
+ innerElements.forEach((element) {
+ // TODO(smok): Filter out default constructors here.
+ outputElement(element);
+ });
+ sb.add('}');
+ }
+
+ void outputElement(Element element) {
+ // TODO(smok): Figure out why AbstractFieldElement appears here,
+ // we have used getters/setters resolved instead of it.
+ if (element is SynthesizedConstructorElement
+ || element is AbstractFieldElement) return;
+ if (element.isField()) {
+ // Add modifiers first.
+ sb.add(element.modifiers.toString());
+ sb.add(' ');
+ // Figure out type.
+ if (element is VariableElement) {
+ VariableListElement variables = element.variables;
+ if (variables.type !== null) {
+ sb.add(variables.type);
+ sb.add(' ');
+ }
+ }
+ // TODO(smok): Maybe not rely on node unparsing,
+ // but unparse initializer manually.
+ sb.add(element.parseNode(listener).unparse());
+ sb.add(';');
+ } else {
+ if (element.isSetter()) {
+ sb.add('set ');
+ } else if (element.isGetter()) {
+ sb.add('get ');
+ }
+ sb.add(element.parseNode(listener).unparse());
+ }
+ }
+
+ String toString() => sb.toString();
+}
« no previous file with comments | « lib/compiler/implementation/dart_backend/dart_backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698