| 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 part of js; | 5 part of js; |
| 6 | 6 |
| 7 class Printer extends Indentation implements NodeVisitor { | 7 class Printer extends Indentation implements NodeVisitor { |
| 8 final bool shouldCompressOutput; | 8 final bool shouldCompressOutput; |
| 9 leg.Compiler compiler; | 9 leg.Compiler compiler; |
| 10 CodeBuffer outBuffer; | 10 CodeBuffer outBuffer; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 int get lastCharCode { | 51 int get lastCharCode { |
| 52 if (lastAddedString == null) return 0; | 52 if (lastAddedString == null) return 0; |
| 53 assert(lastAddedString.length != ""); | 53 assert(lastAddedString.length != ""); |
| 54 return lastAddedString.codeUnitAt(lastAddedString.length - 1); | 54 return lastAddedString.codeUnitAt(lastAddedString.length - 1); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void out(String str) { | 57 void out(String str) { |
| 58 if (str != "") { | 58 if (str != "") { |
| 59 if (pendingSemicolon) { | 59 if (pendingSemicolon) { |
| 60 if (!shouldCompressOutput) { | 60 if (!shouldCompressOutput) { |
| 61 outBuffer.write(";"); | 61 outBuffer.add(";"); |
| 62 } else if (str != "}") { | 62 } else if (str != "}") { |
| 63 // We want to output newline instead of semicolon because it makes | 63 // We want to output newline instead of semicolon because it makes |
| 64 // the raw stack traces much easier to read and it also makes line- | 64 // the raw stack traces much easier to read and it also makes line- |
| 65 // based tools like diff work much better. JavaScript will | 65 // based tools like diff work much better. JavaScript will |
| 66 // automatically insert the semicolon at the newline if it means a | 66 // automatically insert the semicolon at the newline if it means a |
| 67 // parsing error is avoided, so we can only do this trick if the | 67 // parsing error is avoided, so we can only do this trick if the |
| 68 // next line is not something that can be glued onto a valid | 68 // next line is not something that can be glued onto a valid |
| 69 // expression to make a new valid expression. | 69 // expression to make a new valid expression. |
| 70 | 70 |
| 71 // If we're using the new emitter where most pretty printed code | 71 // If we're using the new emitter where most pretty printed code |
| 72 // is escaped in strings, it is a lot easier to deal with semicolons | 72 // is escaped in strings, it is a lot easier to deal with semicolons |
| 73 // than newlines because the former doesn't need escaping. | 73 // than newlines because the former doesn't need escaping. |
| 74 if (USE_NEW_EMITTER || expressionContinuationRegExp.hasMatch(str)) { | 74 if (USE_NEW_EMITTER || expressionContinuationRegExp.hasMatch(str)) { |
| 75 outBuffer.write(";"); | 75 outBuffer.add(";"); |
| 76 } else { | 76 } else { |
| 77 outBuffer.write("\n"); | 77 outBuffer.add("\n"); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 if (pendingSpace && | 81 if (pendingSpace && |
| 82 (!shouldCompressOutput || identifierCharacterRegExp.hasMatch(str))) { | 82 (!shouldCompressOutput || identifierCharacterRegExp.hasMatch(str))) { |
| 83 outBuffer.write(" "); | 83 outBuffer.add(" "); |
| 84 } | 84 } |
| 85 pendingSpace = false; | 85 pendingSpace = false; |
| 86 pendingSemicolon = false; | 86 pendingSemicolon = false; |
| 87 outBuffer.write(str); | 87 outBuffer.add(str); |
| 88 lastAddedString = str; | 88 lastAddedString = str; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 void outLn(String str) { | 92 void outLn(String str) { |
| 93 out(str); | 93 out(str); |
| 94 lineOut(); | 94 lineOut(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void outSemicolonLn() { | 97 void outSemicolonLn() { |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); | 1168 codes.add(nthLetter((n ~/ nameSpaceSize) % LETTERS)); |
| 1169 } | 1169 } |
| 1170 codes.add(charCodes.$0 + digit); | 1170 codes.add(charCodes.$0 + digit); |
| 1171 newName = new String.fromCharCodes(codes); | 1171 newName = new String.fromCharCodes(codes); |
| 1172 } | 1172 } |
| 1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); | 1173 assert(new RegExp(r'[a-zA-Z][a-zA-Z0-9]*').hasMatch(newName)); |
| 1174 maps.last[oldName] = newName; | 1174 maps.last[oldName] = newName; |
| 1175 return newName; | 1175 return newName; |
| 1176 } | 1176 } |
| 1177 } | 1177 } |
| OLD | NEW |