| OLD | NEW |
| 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 class Unparser implements Visitor { | 5 class Unparser implements Visitor { |
| 6 StringBuffer sb; | 6 StringBuffer sb; |
| 7 final bool printDebugInfo; | |
| 8 | 7 |
| 9 Unparser([this.printDebugInfo = false]); | 8 Unparser(); |
| 10 | 9 |
| 11 String unparse(Node node) { | 10 String unparse(Node node) { |
| 12 sb = new StringBuffer(); | 11 sb = new StringBuffer(); |
| 13 visit(node); | 12 visit(node); |
| 14 return sb.toString(); | 13 return sb.toString(); |
| 15 } | 14 } |
| 16 | 15 |
| 17 void add(SourceString string) { | 16 void add(SourceString string) { |
| 18 string.printOn(sb); | 17 string.printOn(sb); |
| 19 } | 18 } |
| 20 | 19 |
| 21 visit(Node node) { | 20 visit(Node node) { |
| 22 if (node !== null) { | 21 if (node !== null) node.accept(this); |
| 23 if (printDebugInfo) sb.add('[${node.getObjectDescription()}: '); | |
| 24 node.accept(this); | |
| 25 if (printDebugInfo) sb.add(']'); | |
| 26 } else if (printDebugInfo) { | |
| 27 sb.add('[null]'); | |
| 28 } | |
| 29 } | 22 } |
| 30 | 23 |
| 31 visitBlock(Block node) { | 24 visitBlock(Block node) { |
| 32 visit(node.statements); | 25 visit(node.statements); |
| 33 } | 26 } |
| 34 | 27 |
| 35 visitCascade(Cascade node) { | 28 visitCascade(Cascade node) { |
| 36 visit(node.expression); | 29 visit(node.expression); |
| 37 } | 30 } |
| 38 | 31 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 sb.add(' '); | 431 sb.add(' '); |
| 439 } | 432 } |
| 440 visit(node.name); | 433 visit(node.name); |
| 441 if (node.typeParameters !== null) { | 434 if (node.typeParameters !== null) { |
| 442 visit(node.typeParameters); | 435 visit(node.typeParameters); |
| 443 } | 436 } |
| 444 visit(node.formals); | 437 visit(node.formals); |
| 445 add(node.endToken.value); | 438 add(node.endToken.value); |
| 446 } | 439 } |
| 447 } | 440 } |
| OLD | NEW |