| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 sb.add(' '); | 418 sb.add(' '); |
| 426 } | 419 } |
| 427 visit(node.name); | 420 visit(node.name); |
| 428 if (node.typeParameters !== null) { | 421 if (node.typeParameters !== null) { |
| 429 visit(node.typeParameters); | 422 visit(node.typeParameters); |
| 430 } | 423 } |
| 431 visit(node.formals); | 424 visit(node.formals); |
| 432 add(node.endToken.value); | 425 add(node.endToken.value); |
| 433 } | 426 } |
| 434 } | 427 } |
| OLD | NEW |