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

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: Address Anton comments 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..f691e9fcc9a96558a6cbcf27cfe7209a52d3d534 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,16 @@ class PrettyPrinter implements Visitor {
visitLiteral(node, "LiteralInt");
}
+ /** Returns token string value or [null] if token is [null]. */
+ tokenToStringOrNull(Token token) => token === null ? null : 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 +240,17 @@ class PrettyPrinter implements Visitor {
}
visitNodeList(NodeList node) {
+ var params = {
+ "delimiter" :
+ node.delimiter !== null ? node.delimiter.stringValue : null,
+ "beginToken" : tokenToStringOrNull(node.getBeginToken()),
+ "endToken" : tokenToStringOrNull(node.getEndToken())};
if (node.nodes.toList().length == 0) {
- openAndCloseNode("NodeList");
+ openAndCloseNode("NodeList", params);
} else {
- visitNodeWithChildren(node, "NodeList");
+ openNode("NodeList", params);
+ node.visitChildren(this);
+ closeNode("NodeList");
}
}
@@ -241,11 +263,12 @@ class PrettyPrinter implements Visitor {
}
visitReturn(Return node) {
- var beginToken =
- node.beginToken !== null ? node.beginToken.stringValue : "null";
- var endToken = node.endToken !== null ? node.endToken.stringValue : "null";
+ var beginToken = node.getBeginToken() !== null
+ ? node.getBeginToken().stringValue : "null";
+ var endToken = node.getEndToken() !== null
+ ? node.getEndToken().stringValue : "null";
openNode("Return", {"beginToken" : beginToken, "endToken" : endToken});
- if (node.hasExpression) visitWithPrefix(node.expression, "expression:");
+ visitWithPrefix(node.expression, "expression:");
closeNode("Return");
}
@@ -255,6 +278,7 @@ class PrettyPrinter implements Visitor {
/** Custom helper to visit given node and print its type with prefix. */
visitWithPrefix(Node node, String prefix) {
+ if (node === null) return;
nextTypePrefix = prefix;
node.accept(this);
}
@@ -265,10 +289,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 +301,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 +346,14 @@ class PrettyPrinter implements Visitor {
}
visitVariableDefinitions(VariableDefinitions node) {
- visitNodeWithChildren(node, "VariableDefinitions");
+ openNode("VariableDefinitions", {
+ "beginToken" : "${node.getBeginToken().stringValue}",
+ "endToken" : "${node.getEndToken().stringValue}"
+ });
+ 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