| 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 dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class CodeBuffer implements StringBuffer { | 7 class CodeBuffer implements StringBuffer { |
| 8 | 8 |
| 9 StringBuffer buffer = new StringBuffer(); | 9 StringBuffer buffer = new StringBuffer(); |
| 10 List<CodeBufferMarker> markers = new List<CodeBufferMarker>(); | 10 List<CodeBufferMarker> markers = new List<CodeBufferMarker>(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 void beginMappedRange() { | 97 void beginMappedRange() { |
| 98 ++mappedRangeCounter; | 98 ++mappedRangeCounter; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void endMappedRange() { | 101 void endMappedRange() { |
| 102 assert(mappedRangeCounter > 0); | 102 assert(mappedRangeCounter > 0); |
| 103 --mappedRangeCounter; | 103 --mappedRangeCounter; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void setSourceLocation(var sourcePosition) { | 106 void setSourceLocation(var sourcePosition) { |
| 107 if (sourcePosition == null) { |
| 108 if (markers.length > 0 && markers.last.sourcePosition == null) return; |
| 109 } |
| 107 int offsetDelta = buffer.length - lastBufferOffset; | 110 int offsetDelta = buffer.length - lastBufferOffset; |
| 108 markers.add(new CodeBufferMarker(offsetDelta, sourcePosition)); | 111 markers.add(new CodeBufferMarker(offsetDelta, sourcePosition)); |
| 109 lastBufferOffset = buffer.length; | 112 lastBufferOffset = buffer.length; |
| 110 } | 113 } |
| 111 | 114 |
| 112 void forEachSourceLocation(void f(int targetOffset, var sourcePosition)) { | 115 void forEachSourceLocation(void f(int targetOffset, var sourcePosition)) { |
| 113 int targetOffset = 0; | 116 int targetOffset = 0; |
| 114 markers.forEach((marker) { | 117 markers.forEach((marker) { |
| 115 targetOffset += marker.offsetDelta; | 118 targetOffset += marker.offsetDelta; |
| 116 f(targetOffset, marker.sourcePosition); | 119 f(targetOffset, marker.sourcePosition); |
| 117 }); | 120 }); |
| 118 } | 121 } |
| 119 } | 122 } |
| 120 | 123 |
| 121 class CodeBufferMarker { | 124 class CodeBufferMarker { |
| 122 final int offsetDelta; | 125 final int offsetDelta; |
| 123 final sourcePosition; | 126 final sourcePosition; |
| 124 | 127 |
| 125 CodeBufferMarker(this.offsetDelta, this.sourcePosition); | 128 CodeBufferMarker(this.offsetDelta, this.sourcePosition); |
| 126 } | 129 } |
| OLD | NEW |