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

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

Issue 10701090: Some enhancements of PrettyPrinter for NodeList, LiteralList. (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/tree/prettyprint.dart
diff --git a/lib/compiler/implementation/tree/prettyprint.dart b/lib/compiler/implementation/tree/prettyprint.dart
index 3baa3926c40c4aa288ce0929c25eacbb451eef9e..2ea1a11d832493239d0ccab0c31f03f89b7f83d7 100644
--- a/lib/compiler/implementation/tree/prettyprint.dart
+++ b/lib/compiler/implementation/tree/prettyprint.dart
@@ -70,7 +70,14 @@ class PrettyPrinter implements Visitor {
sb.add("${type}");
if (params != null) {
// TODO(smok): Escape doublequotes in values.
- params.forEach((k, v) => sb.add(' $k="$v"'));
+ params.forEach((k, v) {
+ sb.add(' $k=');
+ if (v !== null) {
+ sb.add('"$v"');
+ } else {
+ sb.add('null');
+ }
+ });
}
}
@@ -192,8 +199,21 @@ class PrettyPrinter implements Visitor {
visitLiteral(node, "LiteralInt");
}
+ /** Returns token string value or [null] if token is [null]. */
+ tokenToStringOrNull(Token token) {
+ if (token == null) {
Anton Muhin 2012/07/06 10:19:07 nit: === instead of == and single line: if (token
Roman 2012/07/06 11:28:32 Done.
+ return null;
+ }
+ return token.stringValue;
+ }
+
visitLiteralList(LiteralList node) {
- visitNodeWithChildren(node, "LiteralList");
+ openNode("LiteralList", {
+ "constKeyword" : tokenToStringOrNull(node.constKeyword)
+ });
+ visitWithPrefix(node.type, "type:");
+ visitWithPrefix(node.elements, "elements:");
+ closeNode("LiteralList");
}
visitLiteralMap(LiteralMap node) {
@@ -225,10 +245,16 @@ class PrettyPrinter implements Visitor {
}
visitNodeList(NodeList node) {
+ var params = {
+ "delimiter" : node.delimiter != null ? node.delimiter.stringValue : null,
Anton Muhin 2012/07/06 10:19:07 nit: !== And apparently you can use your function
Roman 2012/07/06 11:28:32 Done. delimiter is a SourceString, not a Token.
+ "beginToken" : tokenToStringOrNull(node.beginToken),
+ "endToken" : tokenToStringOrNull(node.endToken)};
if (node.nodes.toList().length == 0) {
- openAndCloseNode("NodeList");
+ openAndCloseNode("NodeList", params);
} else {
- visitNodeWithChildren(node, "NodeList");
+ openNode("NodeList", params);
+ node.visitChildren(this);
+ closeNode("NodeList");
}
}
@@ -245,7 +271,7 @@ class PrettyPrinter implements Visitor {
node.beginToken !== null ? node.beginToken.stringValue : "null";
var endToken = node.endToken !== null ? node.endToken.stringValue : "null";
openNode("Return", {"beginToken" : beginToken, "endToken" : endToken});
- if (node.hasExpression) visitWithPrefix(node.expression, "expression:");
+ visitWithPrefix(node.expression, "expression:");
closeNode("Return");
}
@@ -255,8 +281,10 @@ class PrettyPrinter implements Visitor {
/** Custom helper to visit given node and print its type with prefix. */
visitWithPrefix(Node node, String prefix) {
- nextTypePrefix = prefix;
- node.accept(this);
+ if (node !== null) {
Anton Muhin 2012/07/06 10:19:07 another option: if (node === null) return;
Roman 2012/07/06 11:28:32 Done.
+ nextTypePrefix = prefix;
+ node.accept(this);
+ }
}
openSendNodeWithFields(Send node, String type) {
@@ -265,10 +293,9 @@ class PrettyPrinter implements Visitor {
"isPostfix" : "${node.isPostfix}",
"isIndex" : "${node.isIndex}"
});
- if (node.receiver !== null) visitWithPrefix(node.receiver, "receiver:");
- if (node.selector !== null) visitWithPrefix(node.selector, "selector:");
- if (node.argumentsNode !== null)
- visitWithPrefix(node.argumentsNode, "argumentsNode:");
+ visitWithPrefix(node.receiver, "receiver:");
+ visitWithPrefix(node.selector, "selector:");
+ visitWithPrefix(node.argumentsNode, "argumentsNode:");
}
visitSend(Send node) {
@@ -278,8 +305,7 @@ class PrettyPrinter implements Visitor {
visitSendSet(SendSet node) {
openSendNodeWithFields(node, "SendSet");
- if (node.assignmentOperator !== null)
- visitWithPrefix(node.assignmentOperator, "assignmentOperator:");
+ visitWithPrefix(node.assignmentOperator, "assignmentOperator:");
closeNode("SendSet");
}
@@ -324,7 +350,14 @@ class PrettyPrinter implements Visitor {
}
visitVariableDefinitions(VariableDefinitions node) {
- visitNodeWithChildren(node, "VariableDefinitions");
+ openNode("VariableDefinitions", {
+ "beginToken" : "${node.getBeginToken().stringValue}",
+ "endToken" : "${node.endToken.stringValue}"
Anton Muhin 2012/07/06 10:19:07 that applies to the diff above as well: I believe
Roman 2012/07/06 11:28:32 Done. Changed everywhere.
+ });
+ visitWithPrefix(node.type, "type:");
+ visitWithPrefix(node.modifiers, "modifiers:");
+ visitWithPrefix(node.definitions, "definitions:");
+ closeNode("VariableDefinitions");
}
visitWhile(While node) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698