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

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..349846914fd6294ce8b6c2b57401ead7a254fb37 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,48 @@ class DartBackend extends Backend {
Collection<LibraryElement> libraries) {
}
+ /**
+ * Adds given class element with its inner element to resolved classes
Anton Muhin 2012/07/10 11:31:40 inner should probably be something like member, it
Roman 2012/07/10 11:53:40 Done.
+ * collections.
+ */
+ void addResolvedElementForClass(Element element, ClassElement classElement) {
+ // ${element} should have ${classElement} as enclosing.
+ assert(element.enclosingElement == classElement);
+ List<Element> resolvedElementsInClass = resolvedClassMembers.putIfAbsent(
Anton Muhin 2012/07/10 11:31:40 nit: even as rCM.putIfAbsent(classElement, () =>
Roman 2012/07/10 11:53:40 Done.
+ classElement, () => new List<Element>());
+ resolvedElementsInClass.add(element);
+ }
+
+ /**
+ * Resolves enclosing class for given element and adds to a collection of
+ * resolved class members.
+ */
+ void resolveMember(Element element) {
Anton Muhin 2012/07/10 11:31:40 again, it's not resolving. If anything, it's proc
Roman 2012/07/10 11:53:40 Done.
+ // We should not resolve classes for top-level elements.
+ assert(!element.isTopLevel());
+ assert(element.isMember());
Anton Muhin 2012/07/10 11:31:40 I don't think you may have element.isMember() && e
Roman 2012/07/10 11:53:40 removed isTopLevel() assert
+ var enclosingClass = element.enclosingElement;
+ assert(enclosingClass.isTopLevel());
+ addResolvedElementForClass(element, enclosingClass);
+ }
+
+ /**
+ * 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 +99,10 @@ class DartBackend extends Backend {
StringBuffer sb = new StringBuffer();
resolvedElements.forEach((element, treeElements) {
if (!shouldOutput(element)) return;
+ if (element.isMember()) {
+ resolveMember(element);
+ return;
+ }
if (!element.isTopLevel()) {
bailout('Cannot process non top-level $element');
}
@@ -79,6 +127,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