OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
6 * Support for generating code to be extended with source location mapping. | 6 * Support for generating code to be extended with source location mapping. |
7 */ | 7 */ |
8 class CodeWriter { | 8 class CodeWriter { |
9 static final INDENTATION = ' '; | 9 static final INDENTATION = ' '; |
10 | 10 |
11 static final int INC_INDENT = +1; | 11 static final int INC_INDENT = +1; |
12 static final int DEC_INDENT = -1; | 12 static final int DEC_INDENT = -1; |
13 static final NEWLINE = null; // Anything but an int, String or List. | 13 static final NEWLINE = const Newline(); |
14 | 14 |
15 List _buf; | 15 List _buf; |
16 bool writeComments = true; | 16 bool writeComments = true; |
17 | 17 |
18 CodeWriter(): _buf = []; | 18 CodeWriter(): _buf = []; |
19 | 19 |
20 bool get isEmpty() => _buf.length == 0; | 20 bool get isEmpty() => _buf.length == 0; |
21 | 21 |
22 String get text() { | 22 String get text() { |
23 StringBuffer sb = new StringBuffer(); | 23 StringBuffer sb = new StringBuffer(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 writeln(text); | 101 writeln(text); |
102 } | 102 } |
103 | 103 |
104 /** Switch to an adjacent block in one line, e.g. "} else if (...) {" */ | 104 /** Switch to an adjacent block in one line, e.g. "} else if (...) {" */ |
105 nextBlock(String text) { | 105 nextBlock(String text) { |
106 _buf.add(DEC_INDENT); | 106 _buf.add(DEC_INDENT); |
107 writeln(text); | 107 writeln(text); |
108 _buf.add(INC_INDENT); | 108 _buf.add(INC_INDENT); |
109 } | 109 } |
110 } | 110 } |
| 111 |
| 112 class Newline { |
| 113 const Newline(); |
| 114 } |
OLD | NEW |