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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Pretty-prints Node tree in XML-like format. 6 * Pretty-prints Node tree in XML-like format.
7 * 7 *
8 * TODO(smok): Add main() to run from command-line to print out tree for given 8 * TODO(smok): Add main() to run from command-line to print out tree for given
9 * .dart file. 9 * .dart file.
10 */ 10 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void addTypeWithParams(String type, [Map params]) { 65 void addTypeWithParams(String type, [Map params]) {
66 if (nextTypePrefix !== null) { 66 if (nextTypePrefix !== null) {
67 sb.add(nextTypePrefix); 67 sb.add(nextTypePrefix);
68 nextTypePrefix = null; 68 nextTypePrefix = null;
69 } 69 }
70 sb.add("${type}"); 70 sb.add("${type}");
71 if (params != null) { 71 if (params != null) {
72 // TODO(smok): Escape doublequotes in values. 72 // TODO(smok): Escape doublequotes in values.
73 params.forEach((k, v) => sb.add(' $k="$v"')); 73 params.forEach((k, v) {
74 sb.add(' $k=');
75 if (v !== null) {
76 sb.add('"$v"');
77 } else {
78 sb.add('null');
79 }
80 });
74 } 81 }
75 } 82 }
76 83
77 void addCurrentIndent() { 84 void addCurrentIndent() {
78 for (int i = 0; i < depth; i++) { 85 for (int i = 0; i < depth; i++) {
79 sb.add(INDENT); 86 sb.add(INDENT);
80 } 87 }
81 } 88 }
82 89
83 /** 90 /**
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 192 }
186 193
187 visitLiteralDouble(LiteralDouble node) { 194 visitLiteralDouble(LiteralDouble node) {
188 visitLiteral(node, "LiteralDouble"); 195 visitLiteral(node, "LiteralDouble");
189 } 196 }
190 197
191 visitLiteralInt(LiteralInt node) { 198 visitLiteralInt(LiteralInt node) {
192 visitLiteral(node, "LiteralInt"); 199 visitLiteral(node, "LiteralInt");
193 } 200 }
194 201
202 /** Returns token string value or [null] if token is [null]. */
203 tokenToStringOrNull(Token token) {
204 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.
205 return null;
206 }
207 return token.stringValue;
208 }
209
195 visitLiteralList(LiteralList node) { 210 visitLiteralList(LiteralList node) {
196 visitNodeWithChildren(node, "LiteralList"); 211 openNode("LiteralList", {
212 "constKeyword" : tokenToStringOrNull(node.constKeyword)
213 });
214 visitWithPrefix(node.type, "type:");
215 visitWithPrefix(node.elements, "elements:");
216 closeNode("LiteralList");
197 } 217 }
198 218
199 visitLiteralMap(LiteralMap node) { 219 visitLiteralMap(LiteralMap node) {
200 visitNodeWithChildren(node, "LiteralMap"); 220 visitNodeWithChildren(node, "LiteralMap");
201 } 221 }
202 222
203 visitLiteralMapEntry(LiteralMapEntry node) { 223 visitLiteralMapEntry(LiteralMapEntry node) {
204 visitNodeWithChildren(node, "LiteralMapEntry"); 224 visitNodeWithChildren(node, "LiteralMapEntry");
205 } 225 }
206 226
(...skipping 11 matching lines...) Expand all
218 238
219 visitNamedArgument(NamedArgument node) { 239 visitNamedArgument(NamedArgument node) {
220 visitNodeWithChildren(node, "NamedArgument"); 240 visitNodeWithChildren(node, "NamedArgument");
221 } 241 }
222 242
223 visitNewExpression(NewExpression node) { 243 visitNewExpression(NewExpression node) {
224 visitNodeWithChildren(node, "NewExpression"); 244 visitNodeWithChildren(node, "NewExpression");
225 } 245 }
226 246
227 visitNodeList(NodeList node) { 247 visitNodeList(NodeList node) {
248 var params = {
249 "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.
250 "beginToken" : tokenToStringOrNull(node.beginToken),
251 "endToken" : tokenToStringOrNull(node.endToken)};
228 if (node.nodes.toList().length == 0) { 252 if (node.nodes.toList().length == 0) {
229 openAndCloseNode("NodeList"); 253 openAndCloseNode("NodeList", params);
230 } else { 254 } else {
231 visitNodeWithChildren(node, "NodeList"); 255 openNode("NodeList", params);
256 node.visitChildren(this);
257 closeNode("NodeList");
232 } 258 }
233 } 259 }
234 260
235 visitOperator(Operator node) { 261 visitOperator(Operator node) {
236 openAndCloseNode("Operator", {"value" : node.token.slowToString()}); 262 openAndCloseNode("Operator", {"value" : node.token.slowToString()});
237 } 263 }
238 264
239 visitParenthesizedExpression(ParenthesizedExpression node) { 265 visitParenthesizedExpression(ParenthesizedExpression node) {
240 visitNodeWithChildren(node, "ParenthesizedExpression"); 266 visitNodeWithChildren(node, "ParenthesizedExpression");
241 } 267 }
242 268
243 visitReturn(Return node) { 269 visitReturn(Return node) {
244 var beginToken = 270 var beginToken =
245 node.beginToken !== null ? node.beginToken.stringValue : "null"; 271 node.beginToken !== null ? node.beginToken.stringValue : "null";
246 var endToken = node.endToken !== null ? node.endToken.stringValue : "null"; 272 var endToken = node.endToken !== null ? node.endToken.stringValue : "null";
247 openNode("Return", {"beginToken" : beginToken, "endToken" : endToken}); 273 openNode("Return", {"beginToken" : beginToken, "endToken" : endToken});
248 if (node.hasExpression) visitWithPrefix(node.expression, "expression:"); 274 visitWithPrefix(node.expression, "expression:");
249 closeNode("Return"); 275 closeNode("Return");
250 } 276 }
251 277
252 visitScriptTag(ScriptTag node) { 278 visitScriptTag(ScriptTag node) {
253 visitNodeWithChildren(node, "ScriptTag"); 279 visitNodeWithChildren(node, "ScriptTag");
254 } 280 }
255 281
256 /** Custom helper to visit given node and print its type with prefix. */ 282 /** Custom helper to visit given node and print its type with prefix. */
257 visitWithPrefix(Node node, String prefix) { 283 visitWithPrefix(Node node, String prefix) {
258 nextTypePrefix = prefix; 284 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.
259 node.accept(this); 285 nextTypePrefix = prefix;
286 node.accept(this);
287 }
260 } 288 }
261 289
262 openSendNodeWithFields(Send node, String type) { 290 openSendNodeWithFields(Send node, String type) {
263 openNode(type, { 291 openNode(type, {
264 "isPrefix" : "${node.isPrefix}", 292 "isPrefix" : "${node.isPrefix}",
265 "isPostfix" : "${node.isPostfix}", 293 "isPostfix" : "${node.isPostfix}",
266 "isIndex" : "${node.isIndex}" 294 "isIndex" : "${node.isIndex}"
267 }); 295 });
268 if (node.receiver !== null) visitWithPrefix(node.receiver, "receiver:"); 296 visitWithPrefix(node.receiver, "receiver:");
269 if (node.selector !== null) visitWithPrefix(node.selector, "selector:"); 297 visitWithPrefix(node.selector, "selector:");
270 if (node.argumentsNode !== null) 298 visitWithPrefix(node.argumentsNode, "argumentsNode:");
271 visitWithPrefix(node.argumentsNode, "argumentsNode:");
272 } 299 }
273 300
274 visitSend(Send node) { 301 visitSend(Send node) {
275 openSendNodeWithFields(node, "Send"); 302 openSendNodeWithFields(node, "Send");
276 closeNode("Send"); 303 closeNode("Send");
277 } 304 }
278 305
279 visitSendSet(SendSet node) { 306 visitSendSet(SendSet node) {
280 openSendNodeWithFields(node, "SendSet"); 307 openSendNodeWithFields(node, "SendSet");
281 if (node.assignmentOperator !== null) 308 visitWithPrefix(node.assignmentOperator, "assignmentOperator:");
282 visitWithPrefix(node.assignmentOperator, "assignmentOperator:");
283 closeNode("SendSet"); 309 closeNode("SendSet");
284 } 310 }
285 311
286 visitStringInterpolation(StringInterpolation node) { 312 visitStringInterpolation(StringInterpolation node) {
287 visitNodeWithChildren(node, "StringInterpolation"); 313 visitNodeWithChildren(node, "StringInterpolation");
288 } 314 }
289 315
290 visitStringInterpolationPart(StringInterpolationPart node) { 316 visitStringInterpolationPart(StringInterpolationPart node) {
291 visitNodeWithChildren(node, "StringInterpolationPart"); 317 visitNodeWithChildren(node, "StringInterpolationPart");
292 } 318 }
(...skipping 24 matching lines...) Expand all
317 343
318 visitTypedef(Typedef node) { 344 visitTypedef(Typedef node) {
319 visitNodeWithChildren(node, "Typedef"); 345 visitNodeWithChildren(node, "Typedef");
320 } 346 }
321 347
322 visitTypeVariable(TypeVariable node) { 348 visitTypeVariable(TypeVariable node) {
323 visitNodeWithChildren(node, "TypeVariable"); 349 visitNodeWithChildren(node, "TypeVariable");
324 } 350 }
325 351
326 visitVariableDefinitions(VariableDefinitions node) { 352 visitVariableDefinitions(VariableDefinitions node) {
327 visitNodeWithChildren(node, "VariableDefinitions"); 353 openNode("VariableDefinitions", {
354 "beginToken" : "${node.getBeginToken().stringValue}",
355 "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.
356 });
357 visitWithPrefix(node.type, "type:");
358 visitWithPrefix(node.modifiers, "modifiers:");
359 visitWithPrefix(node.definitions, "definitions:");
360 closeNode("VariableDefinitions");
328 } 361 }
329 362
330 visitWhile(While node) { 363 visitWhile(While node) {
331 visitNodeWithChildren(node, "While"); 364 visitNodeWithChildren(node, "While");
332 } 365 }
333 } 366 }
OLDNEW
« 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