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

Unified Diff: lib/compiler/implementation/tree/unparser.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/tree/unparser.dart
diff --git a/lib/compiler/implementation/tree/unparser.dart b/lib/compiler/implementation/tree/unparser.dart
index 8b3f03ad9df71e9609fec31fcbafdd89b8f78962..67ac17745e83da2a300ad8813d3dcfe228d53e44 100644
--- a/lib/compiler/implementation/tree/unparser.dart
+++ b/lib/compiler/implementation/tree/unparser.dart
@@ -3,9 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
class Unparser implements Visitor {
+ final Renamer renamer;
StringBuffer sb;
- Unparser();
+ Unparser([this.renamer = const NoRenamer()]);
String unparse(Node node) {
sb = new StringBuffer();
@@ -117,7 +118,12 @@ class Unparser implements Visitor {
}
visitIdentifier(Identifier node) {
- add(node.token.value);
+ String newName = renamer.renameIdentifier(node);
+ if (newName == null) {
Anton Muhin 2012/07/23 17:01:27 if instead of null, renamer would have returned al
Roman 2012/07/23 17:38:33 Yes, I thought about that, but the code in both No
+ add(node.token.value);
+ } else {
+ sb.add(newName);
+ }
}
visitIf(If node) {
@@ -183,8 +189,13 @@ class Unparser implements Visitor {
* Unparses given NodeList starting from specific node.
*/
unparseNodeListFrom(NodeList node, Link<Node> from) {
+ if (from.isEmpty()) return;
String delimiter = (node.delimiter === null) ? " " : "${node.delimiter} ";
- from.printOn(sb, delimiter);
+ visit(from.head);
+ for (Link link = from.tail; !link.isEmpty(); link = link.tail) {
+ sb.add(delimiter);
+ visit(link.head);
+ }
}
visitNodeList(NodeList node) {
@@ -231,11 +242,25 @@ class Unparser implements Visitor {
}
}
- visitSend(Send node) {
+ unparseSend(Send node) {
unparseSendPart(node);
visit(node.argumentsNode);
}
+ visitSend(Send node) {
+ if (node.selector !== null && node.selector is TypeAnnotation) {
+ unparseSend(node);
Anton Muhin 2012/07/23 17:01:27 what is the case this covers?
Roman 2012/07/23 17:38:33 Thanks! I don't think it affects anything now. Rem
+ } else {
+ String newMethodName = renamer.renameSendMethod(node);
+ if (newMethodName !== null) {
+ sb.add(newMethodName);
+ visit(node.argumentsNode);
+ } else {
+ unparseSend(node);
+ }
+ }
+ }
+
/**
* Special case for assignments like "list[0] = 1".
*/
@@ -278,7 +303,14 @@ class Unparser implements Visitor {
}
visitTypeAnnotation(TypeAnnotation node) {
- node.visitChildren(this);
+ String newName = renamer.renameTypeName(node);
Anton Muhin 2012/07/23 17:01:27 ditto for null
+ if (newName !== null) {
+ sb.add(newName);
+ visit(node.typeArguments);
+ } else {
+ // Fallback to default unparse without renaming.
+ node.visitChildren(this);
+ }
}
visitTypeVariable(TypeVariable node) {

Powered by Google App Engine
This is Rietveld 408576698