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

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

Issue 10690110: dart2dart support for instantiatin simple top-level class: (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 | tests/compiler/dart2js/unparser_test.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 e945053271390603a7c9c4f74382329020eadcc0..9153b22623231e1e244c05b4a39252020ff9c1fe 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -14,10 +14,12 @@ class DartBackend extends Backend {
Map<Element, TreeElements> get resolvedElements() =>
compiler.enqueuer.resolution.resolvedElements;
+ Map<ClassElement, Set<Element>> resolvedClassMembers;
DartBackend(Compiler compiler, [bool validateUnparse = false])
: tasks = <CompilerTask>[],
unparseValidator = new UnparseValidator(compiler, validateUnparse),
+ resolvedClassMembers = new Map<ClassElement, Set<Element>>(),
super(compiler) {
tasks.add(unparseValidator);
}
@@ -32,6 +34,35 @@ class DartBackend extends Backend {
Collection<LibraryElement> libraries) {
}
+ /**
+ * Adds given class element with its member element to resolved classes
+ * collections.
+ */
+ void addMemberToClass(Element element, ClassElement classElement) {
+ // ${element} should have ${classElement} as enclosing.
+ assert(element.enclosingElement == classElement);
+ List<Element> resolvedElementsInClass =
+ resolvedClassMembers.putIfAbsent(classElement, () => <Element>[]);
+ resolvedElementsInClass.add(element);
+ }
+
+ /**
+ * Outputs given class element with given inner elements to a string buffer.
+ */
+ void outputClass(ClassElement classElement, List<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.
+ sb.add(element.parseNode(compiler).unparse());
+ });
+ sb.add('}');
+ }
+
void assembleProgram() {
resolvedElements.forEach((element, treeElements) {
unparseValidator.check(element);
@@ -55,6 +86,12 @@ class DartBackend extends Backend {
StringBuffer sb = new StringBuffer();
resolvedElements.forEach((element, treeElements) {
if (!shouldOutput(element)) return;
+ if (element.isMember()) {
+ var enclosingClass = element.enclosingElement;
+ assert(enclosingClass.isTopLevel());
Anton Muhin 2012/07/10 12:07:29 you may want to add an assert that it's a class.
Roman 2012/07/10 12:18:02 Done.
+ addMemberToClass(element, enclosingClass);
+ return;
+ }
if (!element.isTopLevel()) {
bailout('Cannot process non top-level $element');
}
@@ -79,6 +116,11 @@ class DartBackend extends Backend {
sb.add(element.parseNode(compiler).unparse());
}
});
+
+ // Now output resolved classes with inner elements we met before.
+ resolvedClassMembers.forEach((classElement, resolvedElements) {
+ outputClass(classElement, resolvedElements, sb);
+ });
compiler.assembledCode = sb.toString();
} catch (BailoutException e) {
compiler.assembledCode = '''
« no previous file with comments | « no previous file | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698