Chromium Code Reviews| 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 = ''' |