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

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
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..c717889b2723b393388dd10547df695f8517fccb 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,14 @@ 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) {
Anton Muhin 2012/07/12 07:02:51 nit: rCM.forEach(emitter.outputClass);
Roman 2012/07/12 07:44:54 Done.
- outputClass(classElement, resolvedElements, sb);
+ emitter.outputClass(classElement, resolvedElements);
});
- compiler.assembledCode = sb.toString();
+ compiler.assembledCode = emitter.toString();
} catch (BailoutException e) {
compiler.assembledCode = '''
main() {

Powered by Google App Engine
This is Rietveld 408576698