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

Unified Diff: lib/compiler/implementation/dart_backend/backend.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 | « no previous file | lib/compiler/implementation/dart_backend/dart_backend.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart_backend/backend.dart
diff --git a/lib/compiler/implementation/dart_backend/backend.dart b/lib/compiler/implementation/dart_backend/backend.dart
index 994eeb73faa6ad9f6110faa7a199842f516aa7ad..4058f9bf9b960a5387bf4d7a3683cf8935a22223 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -46,54 +46,6 @@ class DartBackend extends Backend {
resolvedElementsInClass.add(element);
}
- /**
- * Outputs given class element with given inner elements to a string buffer.
- */
- void outputClass(ClassElement classElement, Set<Element> innerElements,
- StringBuffer sb) {
- // 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);
- });
- sb.add('}');
- }
-
- void outputElement(Element element, StringBuffer sb) {
- // 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(compiler).unparse());
- sb.add(';');
- } else {
- if (element.isSetter()) {
- sb.add('set ');
- } else if (element.isGetter()) {
- sb.add('get ');
- }
- sb.add(element.parseNode(compiler).unparse());
- }
- }
-
void assembleProgram() {
resolvedElements.forEach((element, treeElements) {
unparseValidator.check(element);
@@ -114,7 +66,7 @@ class DartBackend extends Backend {
}
try {
- StringBuffer sb = new StringBuffer();
+ Emitter emitter = new Emitter(compiler);
resolvedElements.forEach((element, treeElements) {
if (!shouldOutput(element)) return;
if (element.isMember()) {
@@ -128,14 +80,12 @@ class DartBackend extends Backend {
bailout('Cannot process non top-level $element');
}
- outputElement(element, sb);
+ emitter.outputElement(element);
});
// Now output resolved classes with inner elements we met before.
- resolvedClassMembers.forEach((classElement, resolvedElements) {
- outputClass(classElement, resolvedElements, sb);
- });
- compiler.assembledCode = sb.toString();
+ resolvedClassMembers.forEach(emitter.outputClass);
+ compiler.assembledCode = emitter.toString();
} catch (BailoutException e) {
compiler.assembledCode = '''
main() {
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/dart_backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698