| 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 CodeBuffer implements StringBuffer { | 5 class CodeBuffer implements StringBuffer { |
| 6 StringBuffer buffer; | 6 StringBuffer buffer; |
| 7 List<SourceLocation> sourceLocations; | 7 List<SourceLocation> sourceLocations; |
| 8 int lastBufferOffset = 0; | 8 int lastBufferOffset = 0; |
| 9 | 9 |
| 10 CodeBuffer() | 10 CodeBuffer() |
| 11 : buffer = new StringBuffer(), | 11 : buffer = new StringBuffer(), |
| 12 sourceLocations = new List<SourceLocation>(); | 12 sourceLocations = new List<SourceLocation>(); |
| 13 | 13 |
| 14 int get length() { | 14 int get length() => buffer.length; |
| 15 return buffer.length; | |
| 16 } | |
| 17 | 15 |
| 18 bool isEmpty() { | 16 bool isEmpty() { |
| 19 return buffer.isEmpty(); | 17 return buffer.isEmpty(); |
| 20 } | 18 } |
| 21 | 19 |
| 22 /** | 20 /** |
| 23 * Converts [object] to a string and adds it to the buffer. If [object] is a | 21 * Converts [object] to a string and adds it to the buffer. If [object] is a |
| 24 * [CodeBuffer], adds its source locations to [sourceLocations]. | 22 * [CodeBuffer], adds its source locations to [sourceLocations]. |
| 25 */ | 23 */ |
| 26 CodeBuffer add(var object) { | 24 CodeBuffer add(var object) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 firstMapping.token, | 38 firstMapping.token, |
| 41 offsetDelta)); | 39 offsetDelta)); |
| 42 for (int i = 1; i < other.sourceLocations.length; ++i) { | 40 for (int i = 1; i < other.sourceLocations.length; ++i) { |
| 43 sourceLocations.add(other.sourceLocations[i]); | 41 sourceLocations.add(other.sourceLocations[i]); |
| 44 } | 42 } |
| 45 lastBufferOffset = buffer.length + other.lastBufferOffset; | 43 lastBufferOffset = buffer.length + other.lastBufferOffset; |
| 46 } | 44 } |
| 47 buffer.add(other.toString()); | 45 buffer.add(other.toString()); |
| 48 } | 46 } |
| 49 | 47 |
| 48 CodeBuffer addAll(Collection<Object> objects) { |
| 49 for (Object obj in objects) { |
| 50 add(obj); |
| 51 } |
| 52 return this; |
| 53 } |
| 54 |
| 50 CodeBuffer addCharCode(int charCode) { | 55 CodeBuffer addCharCode(int charCode) { |
| 51 return add(new String.fromCharCodes([charCode])); | 56 return add(new String.fromCharCodes([charCode])); |
| 52 } | 57 } |
| 53 | 58 |
| 54 CodeBuffer clear() { | 59 CodeBuffer clear() { |
| 55 buffer.clear(); | 60 buffer.clear(); |
| 56 sourceLocations.clear(); | 61 sourceLocations.clear(); |
| 57 lastBufferOffset = 0; | 62 lastBufferOffset = 0; |
| 58 return this; | 63 return this; |
| 59 } | 64 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 void forEachSourceLocation(void f(Element element, Token token, int offset)) { | 76 void forEachSourceLocation(void f(Element element, Token token, int offset)) { |
| 72 int offset = 0; | 77 int offset = 0; |
| 73 sourceLocations.forEach((sourceLocation) { | 78 sourceLocations.forEach((sourceLocation) { |
| 74 offset += sourceLocation.offsetDelta; | 79 offset += sourceLocation.offsetDelta; |
| 75 f(sourceLocation.element, sourceLocation.token, offset); | 80 f(sourceLocation.element, sourceLocation.token, offset); |
| 76 }); | 81 }); |
| 77 } | 82 } |
| 78 } | 83 } |
| 79 | 84 |
| 80 class SourceLocation { | 85 class SourceLocation { |
| 81 Element element; | 86 final Element element; |
| 82 Token token; | 87 final Token token; |
| 83 int offsetDelta; | 88 final int offsetDelta; |
| 84 SourceLocation(this.element, this.token, this.offsetDelta); | 89 SourceLocation(this.element, this.token, this.offsetDelta); |
| 85 } | 90 } |
| OLD | NEW |