| Index: pkg/compiler/lib/src/io/code_output.dart
|
| diff --git a/pkg/compiler/lib/src/io/code_output.dart b/pkg/compiler/lib/src/io/code_output.dart
|
| index 8566f23c21f99de5abaf69b893efed585ebcaac7..1b4075da61454b089f09f0e540131096ff0f6370 100644
|
| --- a/pkg/compiler/lib/src/io/code_output.dart
|
| +++ b/pkg/compiler/lib/src/io/code_output.dart
|
| @@ -8,13 +8,6 @@ import 'dart:async';
|
|
|
| import 'source_information.dart';
|
|
|
| -class CodeOutputMarker {
|
| - final int offsetDelta;
|
| - final SourceLocation sourcePosition;
|
| -
|
| - CodeOutputMarker(this.offsetDelta, this.sourcePosition);
|
| -}
|
| -
|
| abstract class CodeOutputListener {
|
| void onText(String text);
|
| void onDone(int length);
|
| @@ -41,8 +34,8 @@ abstract class CodeOutput {
|
| /// Closes the output. Further writes will cause a [StateError].
|
| void close();
|
|
|
| - /// Sets the [sourcePosition] for the code next added to this output.
|
| - void setSourceLocation(SourceLocation sourcePosition);
|
| + /// Adds a [sourceLocation] at the specified [targetOffset] in the buffer.
|
| + void addSourceLocation(int targetOffset, SourceLocation sourcePosition);
|
|
|
| /// Applies [f] to every marker in this output.
|
| void forEachSourceLocation(void f(int targetOffset,
|
| @@ -50,9 +43,7 @@ abstract class CodeOutput {
|
| }
|
|
|
| abstract class AbstractCodeOutput extends CodeOutput {
|
| - List<CodeOutputMarker> markers = new List<CodeOutputMarker>();
|
| - int lastBufferOffset = 0;
|
| - int mappedRangeCounter = 0;
|
| + Map<int, List<SourceLocation>> markers = <int, List<SourceLocation>>{};
|
| bool isClosed = false;
|
|
|
| void _addInternal(String text);
|
| @@ -62,22 +53,17 @@ abstract class AbstractCodeOutput extends CodeOutput {
|
| if (isClosed) {
|
| throw new StateError("Code output is closed. Trying to write '$text'.");
|
| }
|
| - if (mappedRangeCounter == 0) setSourceLocation(null);
|
| _addInternal(text);
|
| }
|
|
|
| @override
|
| void addBuffer(CodeBuffer other) {
|
| if (other.markers.length > 0) {
|
| - CodeOutputMarker firstMarker = other.markers[0];
|
| - int offsetDelta =
|
| - length + firstMarker.offsetDelta - lastBufferOffset;
|
| - markers.add(new CodeOutputMarker(offsetDelta,
|
| - firstMarker.sourcePosition));
|
| - for (int i = 1; i < other.markers.length; ++i) {
|
| - markers.add(other.markers[i]);
|
| - }
|
| - lastBufferOffset = length + other.lastBufferOffset;
|
| + other.markers.forEach(
|
| + (int targetOffset, List<SourceLocation> sourceLocations) {
|
| + markers.putIfAbsent(length + targetOffset, () => <SourceLocation>[])
|
| + .addAll(sourceLocations);
|
| + });
|
| }
|
| if (!other.isClosed) {
|
| other.close();
|
| @@ -85,29 +71,19 @@ abstract class AbstractCodeOutput extends CodeOutput {
|
| _addInternal(other.getText());
|
| }
|
|
|
| - void beginMappedRange() {
|
| - ++mappedRangeCounter;
|
| - }
|
| -
|
| - void endMappedRange() {
|
| - assert(mappedRangeCounter > 0);
|
| - --mappedRangeCounter;
|
| + void addSourceLocation(int targetOffset,
|
| + SourceLocation sourceLocation) {
|
| + assert(targetOffset <= length);
|
| + List<SourceLocation> sourceLocations =
|
| + markers.putIfAbsent(targetOffset, () => <SourceLocation>[]);
|
| + sourceLocations.add(sourceLocation);
|
| }
|
|
|
| - void setSourceLocation(SourceLocation sourcePosition) {
|
| - if (sourcePosition == null) {
|
| - if (markers.length > 0 && markers.last.sourcePosition == null) return;
|
| - }
|
| - int offsetDelta = length - lastBufferOffset;
|
| - markers.add(new CodeOutputMarker(offsetDelta, sourcePosition));
|
| - lastBufferOffset = length;
|
| - }
|
| -
|
| - void forEachSourceLocation(void f(int targetOffset, var sourcePosition)) {
|
| - int targetOffset = 0;
|
| - markers.forEach((marker) {
|
| - targetOffset += marker.offsetDelta;
|
| - f(targetOffset, marker.sourcePosition);
|
| + void forEachSourceLocation(void f(int targetOffset, var sourceLocation)) {
|
| + markers.forEach((int targetOffset, List<SourceLocation> sourceLocations) {
|
| + for (SourceLocation sourceLocation in sourceLocations) {
|
| + f(targetOffset, sourceLocation);
|
| + }
|
| });
|
| }
|
|
|
|
|