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

Unified Diff: lib/compiler/implementation/tree/unparser.dart

Issue 10836128: A visitor that builds a map from node to "Usage". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 2140a2a2d807e859d6e0e3d87c710534e1402fe2..8fea4240a58db9f3feeb7a466241be87bf610e4b 100644
--- a/lib/compiler/implementation/tree/unparser.dart
+++ b/lib/compiler/implementation/tree/unparser.dart
@@ -27,7 +27,14 @@ class Unparser implements Visitor {
}
visit(Node node) {
- if (node !== null) node.accept(this);
+ if (node === null) return;
+ String renamed = renamer.rename(node);
+ if (renamed !== null) {
+ sb.add(renamed);
+ } else {
+ // Fallback.
+ node.accept(this);
+ }
}
visitBlock(Block node) {
@@ -106,20 +113,12 @@ class Unparser implements Visitor {
// names are modelled with Send and it emits operator[] as only
// operator, without [] which are expected to be emitted with
// arguments.
- emitName(Identifier name) {
- final newName = renamer.renameIdentifier(name);
- if (newName === null) {
- visit(name);
- } else {
- sb.add(newName);
- }
- }
if (node.name is Send) {
Send send = node.name;
assert(send is !SendSet);
if (!send.isOperator) {
// Looks like a factory method.
- emitName(send.receiver);
+ visit(send.receiver);
sb.add('.');
} else {
visit(send.receiver);
@@ -127,7 +126,7 @@ class Unparser implements Visitor {
}
visit(send.selector);
} else {
- if (node.name !== null) emitName(node.name);
+ if (node.name !== null) visit(node.name);
}
visit(node.parameters);
visit(node.initializers);
@@ -237,7 +236,10 @@ class Unparser implements Visitor {
if (node.isPrefix) {
visit(node.selector);
}
- if (node.receiver !== null) {
+ // TODO(smok): Remove ugly hack for library preferences.
+ // Check that renamer does not want to omit receiver at all,
+ // in that case we don't need spaces or dot.
+ if (node.receiver !== null && renamer.rename(node.receiver) != '') {
visit(node.receiver);
CascadeReceiver asCascadeReceiver = node.receiver.asCascadeReceiver();
if (asCascadeReceiver !== null) {
@@ -262,14 +264,8 @@ class Unparser implements Visitor {
}
visitSend(Send node) {
- String newMethodName = renamer.renameSendMethod(node);
- if (newMethodName !== null) {
- sb.add(newMethodName);
- visit(node.argumentsNode);
- } else {
- unparseSendPart(node);
- visit(node.argumentsNode);
- }
+ unparseSendPart(node);
+ visit(node.argumentsNode);
}
/**
@@ -318,14 +314,8 @@ class Unparser implements Visitor {
}
visitTypeAnnotation(TypeAnnotation node) {
- String newName = renamer.renameTypeName(node);
- if (newName !== null) {
- sb.add(newName);
- visit(node.typeArguments);
- } else {
- // Fallback to default unparse without renaming.
- node.visitChildren(this);
- }
+ visit(node.typeName);
Anton Muhin 2012/08/07 12:32:11 visitChildren?
Roman 2012/08/07 15:44:03 The problem here is the nature of visitChildren(it
Anton Muhin 2012/08/07 16:24:08 TODO here and a fix for visitChildren in a separat
+ visit(node.typeArguments);
}
visitTypeVariable(TypeVariable node) {

Powered by Google App Engine
This is Rietveld 408576698