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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/dart_backend/emitter.dart
diff --git a/lib/compiler/implementation/dart_backend/emitter.dart b/lib/compiler/implementation/dart_backend/emitter.dart
index 8d177aa82afbf6f4ed5f02f756afe6cace6b72a3..82c79e70d04d6559e0d2dbd7a3feb11f956e6c7d 100644
--- a/lib/compiler/implementation/dart_backend/emitter.dart
+++ b/lib/compiler/implementation/dart_backend/emitter.dart
@@ -9,33 +9,44 @@ class Emitter {
final Compiler compiler;
final StringBuffer sb;
+ final Renamer renamer;
- Emitter(this.compiler) : sb = new StringBuffer();
+ Emitter(Compiler compiler) :
+ this.compiler = compiler,
+ sb = new StringBuffer(),
+ renamer = new ConflictingRenamer(compiler);
/**
* Outputs given class element with selected inner elements.
*/
void outputClass(ClassElement classElement, Set<Element> innerElements) {
+ Unparser unparser = new Unparser(renamer);
+ renamer.setContext(classElement.getCompilationUnit());
ClassNode classNode = classElement.parseNode(compiler);
sb.add(classElement.beginToken.slowToString()); // 'class' or 'interface'.
sb.add(' ');
- sb.add(classNode.name.unparse());
+ sb.add(renamer.renameType(classElement.type));
if (classNode.typeParameters !== null) {
- sb.add(classNode.typeParameters.unparse());
+ sb.add(unparser.unparse(classNode.typeParameters));
}
if (classNode.extendsKeyword !== null) {
sb.add(' ');
classNode.extendsKeyword.value.printOn(sb);
sb.add(' ');
- sb.add(classNode.superclass.unparse());
+ sb.add(renamer.renameType(classElement.supertype));
}
if (!classNode.interfaces.isEmpty()) {
sb.add(classElement.isInterface() ? ' extends ' : ' implements ');
- classNode.interfaces.nodes.printOn(sb, classNode.interfaces.delimiter);
+ Link<Node> interfaceNodes = classNode.interfaces.nodes;
Anton Muhin 2012/07/23 17:58:54 your modified version of NodeList processing, won'
Roman 2012/07/24 08:22:49 Unfortunately, unparse() for NodeList first prints
Anton Muhin 2012/07/24 08:43:58 Shouldn't that be fixed?
Roman 2012/07/24 08:58:04 It is not clear that it's a bug. Usually node list
Roman 2012/07/24 08:58:54 For a case of whitespaces there is no beginToken I
Anton Muhin 2012/07/24 09:00:10 I think it should be fixed even if (for now) we'll
Roman 2012/07/24 10:37:04 I was wrong, 'extends' or 'implements' is not part
Anton Muhin 2012/07/24 10:46:50 thanks a lot! On 2012/07/24 10:37:04, Roman wrote
+ sb.add(unparser.unparse(interfaceNodes.head));
+ for (Link link = interfaceNodes.tail; !link.isEmpty(); link = link.tail) {
+ sb.add(classNode.interfaces.delimiter);
+ sb.add(unparser.unparse(link.head));
+ }
}
if (classNode.defaultClause !== null) {
sb.add(' default ');
- sb.add(classNode.defaultClause.unparse());
+ sb.add(unparser.unparse(classNode.defaultClause));
}
sb.add('{');
innerElements.forEach((element) {
@@ -46,15 +57,17 @@ class Emitter {
}
void outputElement(Element element) {
+ Unparser unparser = new Unparser(renamer);
+ renamer.setContext(element);
// TODO(smok): Figure out why AbstractFieldElement appears here,
// we have used getters/setters resolved instead of it.
if (element is SynthesizedConstructorElement
|| element is AbstractFieldElement) return;
if (element.isField()) {
assert(element is VariableElement);
- sb.add(element.variables.parseNode(compiler).unparse());
+ sb.add(unparser.unparse(element.variables.parseNode(compiler)));
} else {
- sb.add(element.parseNode(compiler).unparse());
+ sb.add(unparser.unparse(element.parseNode(compiler)));
}
}

Powered by Google App Engine
This is Rietveld 408576698