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

Side by Side Diff: lib/compiler/implementation/dart_backend/emitter.dart

Issue 10916053: Get rid of duplication of class node unparsing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 String emitCode( 5 String emitCode(
6 Compiler compiler, 6 Compiler compiler,
7 Unparser unparser, 7 Unparser unparser,
8 Map<LibraryElement, String> imports, 8 Map<LibraryElement, String> imports,
9 Collection<Element> topLevelElements, 9 Collection<Element> topLevelElements,
10 Map<ClassElement, Collection<Element>> classMembers) { 10 Map<ClassElement, Collection<Element>> classMembers) {
(...skipping 11 matching lines...) Expand all
22 if (!processedVariableLists.contains(variableList)) { 22 if (!processedVariableLists.contains(variableList)) {
23 processedVariableLists.add(variableList); 23 processedVariableLists.add(variableList);
24 unparser.unparse(variableList.parseNode(compiler)); 24 unparser.unparse(variableList.parseNode(compiler));
25 } 25 }
26 } else { 26 } else {
27 unparser.unparse(element.parseNode(compiler)); 27 unparser.unparse(element.parseNode(compiler));
28 } 28 }
29 } 29 }
30 30
31 void outputClass(ClassElement classElement, Collection<Element> members) { 31 void outputClass(ClassElement classElement, Collection<Element> members) {
32 ClassNode classNode = classElement.parseNode(compiler); 32 unparser.unparseClassWithBody(classElement.parseNode(compiler), () {
33 // classElement.beginToken is 'class', 'interface', or 'abstract'. 33 members.forEach((element) {
34 unparser.addToken(classNode.beginToken); 34 // TODO(smok): Filter out default constructors here.
35 if (classNode.beginToken.stringValue == 'abstract') { 35 outputElement(element);
36 unparser.addToken(classNode.beginToken.next); 36 });
37 }
38 unparser.unparse(classNode.name);
39 if (classNode.typeParameters !== null) {
40 unparser.unparse(classNode.typeParameters);
41 }
42 if (classNode.extendsKeyword !== null) {
43 unparser.addString(' ');
44 unparser.addToken(classNode.extendsKeyword);
45 unparser.unparse(classNode.superclass);
46 }
47 if (!classNode.interfaces.isEmpty()) {
48 unparser.addString(' ');
49 unparser.unparse(classNode.interfaces);
50 }
51 if (classNode.defaultClause !== null) {
52 unparser.addString(' default ');
53 unparser.unparse(classNode.defaultClause);
54 }
55 unparser.addString('{');
56 members.forEach((element) {
57 // TODO(smok): Filter out default constructors here.
58 outputElement(element);
59 }); 37 });
60 unparser.addString('}');
61 } 38 }
62 39
63 imports.forEach((libraryElement, prefix) { 40 imports.forEach((libraryElement, prefix) {
64 unparser.addString('#import("${libraryElement.uri}",prefix:"$prefix");'); 41 unparser.addString('#import("${libraryElement.uri}",prefix:"$prefix");');
65 }); 42 });
66 43
67 for (final element in topLevelElements) { 44 for (final element in topLevelElements) {
68 if (element is ClassElement) { 45 if (element is ClassElement) {
69 outputClass(element, classMembers[element]); 46 outputClass(element, classMembers[element]);
70 } else { 47 } else {
71 outputElement(element); 48 outputElement(element);
72 } 49 }
73 } 50 }
74 } 51 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/tree/unparser.dart » ('j') | lib/compiler/implementation/tree/unparser.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698