| 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; | 6 final bool shouldCompressOutput; |
| 7 leg.Compiler compiler; | 7 leg.Compiler compiler; |
| 8 var positionElement; | |
| 9 leg.CodeBuffer outBuffer; | 8 leg.CodeBuffer outBuffer; |
| 10 int indentLevel = 0; | 9 int indentLevel = 0; |
| 11 bool inForInit = false; | 10 bool inForInit = false; |
| 12 bool atStatementBegin = false; | 11 bool atStatementBegin = false; |
| 13 final DanglingElseVisitor danglingElseVisitor; | 12 final DanglingElseVisitor danglingElseVisitor; |
| 14 | 13 |
| 15 Printer(leg.Compiler compiler, this.positionElement) | 14 Printer(leg.Compiler compiler) |
| 16 : shouldCompressOutput = compiler.enableMinification, | 15 : shouldCompressOutput = compiler.enableMinification, |
| 17 this.compiler = compiler, | 16 this.compiler = compiler, |
| 18 outBuffer = new leg.CodeBuffer(), | 17 outBuffer = new leg.CodeBuffer(), |
| 19 danglingElseVisitor = new DanglingElseVisitor(compiler); | 18 danglingElseVisitor = new DanglingElseVisitor(compiler); |
| 20 | 19 |
| 21 void spaceOut() { | 20 void spaceOut() { |
| 22 if (!shouldCompressOutput) out(" "); | 21 if (!shouldCompressOutput) out(" "); |
| 23 } | 22 } |
| 24 void lineOut() { | 23 void lineOut() { |
| 25 if (!shouldCompressOutput) out("\n"); | 24 if (!shouldCompressOutput) out("\n"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 void outIndent(String str) { indent(); out(str); } | 46 void outIndent(String str) { indent(); out(str); } |
| 48 void outIndentLn(String str) { indent(); outLn(str); } | 47 void outIndentLn(String str) { indent(); outLn(str); } |
| 49 void indent() { | 48 void indent() { |
| 50 if (!shouldCompressOutput) { | 49 if (!shouldCompressOutput) { |
| 51 for (int i = 0; i < indentLevel; i++) out(" "); | 50 for (int i = 0; i < indentLevel; i++) out(" "); |
| 52 } | 51 } |
| 53 } | 52 } |
| 54 | 53 |
| 55 void recordSourcePosition(var position) { | 54 void recordSourcePosition(var position) { |
| 56 if (position != null) { | 55 if (position != null) { |
| 57 outBuffer.setSourceLocation(positionElement, position); | 56 outBuffer.setSourceLocation(position); |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 visit(Node node) { | 60 visit(Node node) { |
| 62 if (node.sourcePosition != null) outBuffer.beginMappedRange(); | 61 if (node.sourcePosition != null) outBuffer.beginMappedRange(); |
| 63 recordSourcePosition(node.sourcePosition); | 62 recordSourcePosition(node.sourcePosition); |
| 64 node.accept(this); | 63 node.accept(this); |
| 65 recordSourcePosition(node.endSourcePosition); | 64 recordSourcePosition(node.endSourcePosition); |
| 66 if (node.sourcePosition != null) outBuffer.endMappedRange(); | 65 if (node.sourcePosition != null) outBuffer.endMappedRange(); |
| 67 } | 66 } |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 bool visitFunctionDeclaration(FunctionDeclaration node) => false; | 813 bool visitFunctionDeclaration(FunctionDeclaration node) => false; |
| 815 bool visitLabeledStatement(LabeledStatement node) | 814 bool visitLabeledStatement(LabeledStatement node) |
| 816 => node.body.accept(this); | 815 => node.body.accept(this); |
| 817 bool visitLiteralStatement(LiteralStatement node) => true; | 816 bool visitLiteralStatement(LiteralStatement node) => true; |
| 818 | 817 |
| 819 bool visitExpression(Expression node) => false; | 818 bool visitExpression(Expression node) => false; |
| 820 } | 819 } |
| 821 | 820 |
| 822 | 821 |
| 823 leg.CodeBuffer prettyPrint(Node node, | 822 leg.CodeBuffer prettyPrint(Node node, |
| 824 leg.Compiler compiler, | 823 leg.Compiler compiler) { |
| 825 Dynamic positionElement) { | 824 Printer printer = new Printer(compiler); |
| 826 Printer printer = new Printer(compiler, positionElement); | |
| 827 printer.visit(node); | 825 printer.visit(node); |
| 828 return printer.outBuffer; | 826 return printer.outBuffer; |
| 829 } | 827 } |
| OLD | NEW |