| 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 Printer implements NodeVisitor { | 5 class Printer implements NodeVisitor { |
| 6 final bool shouldCompressOutput = false; | 6 final bool shouldCompressOutput = false; |
| 7 leg.Compiler compiler; | 7 leg.Compiler compiler; |
| 8 var positionElement; | 8 var positionElement; |
| 9 leg.CodeBuffer outBuffer; | 9 leg.CodeBuffer outBuffer; |
| 10 int indentLevel = 0; | 10 int indentLevel = 0; |
| 11 bool inForInit = false; | 11 bool inForInit = false; |
| 12 bool atStatementBegin = false; | 12 bool atStatementBegin = false; |
| 13 final DanglingElseVisitor danglingElseVisitor; | 13 final DanglingElseVisitor danglingElseVisitor; |
| 14 | 14 |
| 15 Printer(leg.Compiler compiler, this.positionElement) | 15 Printer(leg.Compiler compiler, this.positionElement) |
| 16 : this.compiler = compiler, | 16 : this.compiler = compiler, |
| 17 outBuffer = new leg.CodeBuffer(), | 17 outBuffer = new leg.CodeBuffer(), |
| 18 danglingElseVisitor = new DanglingElseVisitor(compiler); | 18 danglingElseVisitor = new DanglingElseVisitor(compiler); |
| 19 | 19 |
| 20 void spaceOut() { | 20 void spaceOut() { |
| 21 if (!shouldCompressOutput) out(" "); | 21 if (!shouldCompressOutput) out(" "); |
| 22 } | 22 } |
| 23 void lineOut() { | 23 void lineOut() { |
| 24 if (!shouldCompressOutput) out("\n"); | 24 if (!shouldCompressOutput) out("\n"); |
| 25 } | 25 } |
| 26 | 26 |
| 27 String lastAddedString = null; | 27 String lastAddedString = null; |
| 28 int get lastCharCode() { | 28 int get lastCharCode { |
| 29 if (lastAddedString == null) return 0; | 29 if (lastAddedString == null) return 0; |
| 30 assert(lastAddedString.length != ""); | 30 assert(lastAddedString.length != ""); |
| 31 return lastAddedString.charCodeAt(lastAddedString.length - 1); | 31 return lastAddedString.charCodeAt(lastAddedString.length - 1); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void out(String str) { | 34 void out(String str) { |
| 35 if (str != "") { | 35 if (str != "") { |
| 36 outBuffer.add(str); | 36 outBuffer.add(str); |
| 37 lastAddedString = str; | 37 lastAddedString = str; |
| 38 } | 38 } |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 } | 817 } |
| 818 | 818 |
| 819 | 819 |
| 820 leg.CodeBuffer prettyPrint(Node node, | 820 leg.CodeBuffer prettyPrint(Node node, |
| 821 leg.Compiler compiler, | 821 leg.Compiler compiler, |
| 822 Dynamic positionElement) { | 822 Dynamic positionElement) { |
| 823 Printer printer = new Printer(compiler, positionElement); | 823 Printer printer = new Printer(compiler, positionElement); |
| 824 printer.visit(node); | 824 printer.visit(node); |
| 825 return printer.outBuffer; | 825 return printer.outBuffer; |
| 826 } | 826 } |
| OLD | NEW |