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

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

Issue 10905019: Separate Dart backend specific logic from basic Unparser. (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 class EmitterUnparser extends Unparser {
6 final Map<Node, String> renames;
7
8 EmitterUnparser(this.renames);
9
10 visit(Node node) {
11 if (node !== null && renames.containsKey(node)) {
12 sb.add(renames[node]);
13 } else {
14 super.visit(node);
15 }
16 }
17
18 unparseSendReceiver(Send node, [bool spacesNeeded=false]) {
19 // TODO(smok): Remove ugly hack for library preferences.
Roman 2012/10/01 14:10:34 library prefixes?
20 // Check that renamer does not want to omit receiver at all,
21 // in that case we don't need spaces or dot.
22 if (node.receiver !== null && renames[node.receiver] == '') return;
23 super.unparseSendReceiver(node, spacesNeeded);
24 }
25 }
26
5 String emitCode( 27 String emitCode(
6 Compiler compiler, 28 Compiler compiler,
7 Unparser unparser, 29 Map<Node, String> renames,
8 Map<LibraryElement, String> imports, 30 Map<LibraryElement, String> imports,
9 Collection<Element> topLevelElements, 31 Collection<Element> topLevelElements,
10 Map<ClassElement, Collection<Element>> classMembers) { 32 Map<ClassElement, Collection<Element>> classMembers) {
11 final sb = new StringBuffer(); 33 final sb = new StringBuffer();
34 final unparser = new EmitterUnparser(renames);
12 final processedVariableLists = new Set<VariableListElement>(); 35 final processedVariableLists = new Set<VariableListElement>();
13 36
14 void outputElement(Element element) { 37 void outputElement(Element element) {
15 if (element is SynthesizedConstructorElement) return; 38 if (element is SynthesizedConstructorElement) return;
16 if (element.isField()) { 39 if (element.isField()) {
17 assert(element is VariableElement); 40 assert(element is VariableElement);
18 // Different VariableElement's may refer to the same VariableListElement. 41 // Different VariableElement's may refer to the same VariableListElement.
19 // Output this list only once. 42 // Output this list only once.
20 // TODO: only emit used variables. 43 // TODO: only emit used variables.
21 VariableElement variableElement = element; 44 VariableElement variableElement = element;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 for (final element in topLevelElements) { 102 for (final element in topLevelElements) {
80 if (element is ClassElement) { 103 if (element is ClassElement) {
81 outputClass(element, classMembers[element]); 104 outputClass(element, classMembers[element]);
82 } else { 105 } else {
83 outputElement(element); 106 outputElement(element);
84 } 107 }
85 } 108 }
86 109
87 return sb.toString(); 110 return sb.toString();
88 } 111 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/backend.dart ('k') | lib/compiler/implementation/tree/unparser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698