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

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

Powered by Google App Engine
This is Rietveld 408576698