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

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..2fe101fcb6f724efd5a980a8d4a59b2cd11cd48d 100644
--- a/lib/compiler/implementation/tree/unparser.dart
+++ b/lib/compiler/implementation/tree/unparser.dart
@@ -2,11 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+// Returns null if no need to rename a node.
+typedef String Renamer(Node node);
+
class Unparser implements Visitor {
- final Renamer renamer;
+ Renamer rename;
Anton Muhin 2012/08/08 08:27:20 why it's not final any more?
Roman 2012/08/09 05:02:35 Done.
StringBuffer sb;
- Unparser([this.renamer = const Renamer()]);
+ Unparser() : this.withRenamer((Node) => null);
+ Unparser.withRenamer(this.rename);
String unparse(Node node) {
sb = new StringBuffer();
@@ -27,7 +31,14 @@ class Unparser implements Visitor {
}
visit(Node node) {
- if (node !== null) node.accept(this);
+ if (node === null) return;
+ String renamed = rename(node);
+ if (renamed !== null) {
+ sb.add(renamed);
+ } else {
+ // Fallback.
+ node.accept(this);
+ }
}
visitBlock(Block node) {
@@ -106,20 +117,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 +130,7 @@ class Unparser implements Visitor {
}
visit(send.selector);
} else {
- if (node.name !== null) emitName(node.name);
+ if (node.name !== null) visit(node.name);
Anton Muhin 2012/08/08 08:27:20 no need in !== null check, but after rebase this d
}
visit(node.parameters);
visit(node.initializers);
@@ -237,7 +240,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 && rename(node.receiver) != '') {
visit(node.receiver);
CascadeReceiver asCascadeReceiver = node.receiver.asCascadeReceiver();
if (asCascadeReceiver !== null) {
@@ -262,14 +268,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 +318,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/08 08:27:20 what about TODO as was discussed before?
Roman 2012/08/09 05:02:35 As discussed, keeping as is.
+ visit(node.typeArguments);
}
visitTypeVariable(TypeVariable node) {

Powered by Google App Engine
This is Rietveld 408576698