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

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

Issue 10795064: dart2dart: Introduce Renamer that is used by renaming unparser (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 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 /** 5 /**
6 * Dart backend helper for converting program IR back to source code. 6 * Dart backend helper for converting program IR back to source code.
7 */ 7 */
8 class Emitter { 8 class Emitter {
9 9
10 final Compiler compiler; 10 final Compiler compiler;
11 final StringBuffer sb; 11 final StringBuffer sb;
12 final Renamer renamer;
12 13
13 Emitter(this.compiler) : sb = new StringBuffer(); 14 Emitter(Compiler compiler) :
15 this.compiler = compiler,
16 sb = new StringBuffer(),
17 renamer = new ConflictingRenamer(compiler);
14 18
15 /** 19 /**
16 * Outputs given class element with selected inner elements. 20 * Outputs given class element with selected inner elements.
17 */ 21 */
18 void outputClass(ClassElement classElement, Set<Element> innerElements) { 22 void outputClass(ClassElement classElement, Set<Element> innerElements) {
23 Unparser unparser = new Unparser(renamer);
24 renamer.setContext(classElement.getCompilationUnit());
19 ClassNode classNode = classElement.parseNode(compiler); 25 ClassNode classNode = classElement.parseNode(compiler);
20 sb.add(classElement.beginToken.slowToString()); // 'class' or 'interface'. 26 sb.add(classElement.beginToken.slowToString()); // 'class' or 'interface'.
21 sb.add(' '); 27 sb.add(' ');
22 sb.add(classNode.name.unparse()); 28 sb.add(renamer.renameType(classElement.type));
23 if (classNode.typeParameters !== null) { 29 if (classNode.typeParameters !== null) {
24 sb.add(classNode.typeParameters.unparse()); 30 sb.add(unparser.unparse(classNode.typeParameters));
25 } 31 }
26 if (classNode.extendsKeyword !== null) { 32 if (classNode.extendsKeyword !== null) {
27 sb.add(' '); 33 sb.add(' ');
28 classNode.extendsKeyword.value.printOn(sb); 34 classNode.extendsKeyword.value.printOn(sb);
29 sb.add(' '); 35 sb.add(' ');
30 sb.add(classNode.superclass.unparse()); 36 sb.add(renamer.renameType(classElement.supertype));
31 } 37 }
32 if (!classNode.interfaces.isEmpty()) { 38 if (!classNode.interfaces.isEmpty()) {
33 sb.add(classElement.isInterface() ? ' extends ' : ' implements '); 39 sb.add(classElement.isInterface() ? ' extends ' : ' implements ');
34 classNode.interfaces.nodes.printOn(sb, classNode.interfaces.delimiter); 40 Link<Node> interfaceNodes = classNode.interfaces.nodes;
41 sb.add(interfaceNodes.head);
Anton Muhin 2012/07/23 17:01:27 shouldn't you rename those types?
Roman 2012/07/23 17:38:33 Done.
42 for (Link link = interfaceNodes.tail; !link.isEmpty(); link = link.tail) {
43 sb.add(classNode.interfaces.delimiter);
44 sb.add(link.head);
45 }
35 } 46 }
36 if (classNode.defaultClause !== null) { 47 if (classNode.defaultClause !== null) {
37 sb.add(' default '); 48 sb.add(' default ');
38 sb.add(classNode.defaultClause.unparse()); 49 sb.add(unparser.unparse(classNode.defaultClause));
39 } 50 }
40 sb.add('{'); 51 sb.add('{');
41 innerElements.forEach((element) { 52 innerElements.forEach((element) {
42 // TODO(smok): Filter out default constructors here. 53 // TODO(smok): Filter out default constructors here.
43 outputElement(element); 54 outputElement(element);
44 }); 55 });
45 sb.add('}'); 56 sb.add('}');
46 } 57 }
47 58
48 void outputElement(Element element) { 59 void outputElement(Element element) {
60 Unparser unparser = new Unparser(renamer);
61 renamer.setContext(element);
49 // TODO(smok): Figure out why AbstractFieldElement appears here, 62 // TODO(smok): Figure out why AbstractFieldElement appears here,
50 // we have used getters/setters resolved instead of it. 63 // we have used getters/setters resolved instead of it.
51 if (element is SynthesizedConstructorElement 64 if (element is SynthesizedConstructorElement
52 || element is AbstractFieldElement) return; 65 || element is AbstractFieldElement) return;
53 if (element.isField()) { 66 if (element.isField()) {
54 assert(element is VariableElement); 67 assert(element is VariableElement);
55 sb.add(element.variables.parseNode(compiler).unparse()); 68 sb.add(unparser.unparse(element.variables.parseNode(compiler)));
56 } else { 69 } else {
57 sb.add(element.parseNode(compiler).unparse()); 70 sb.add(unparser.unparse(element.parseNode(compiler)));
58 } 71 }
59 } 72 }
60 73
61 String toString() => sb.toString(); 74 String toString() => sb.toString();
62 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698