Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: pkg/compiler/lib/src/io/code_output.dart

Issue 1081313003: Improve precision of JS printer callbacks (2nd try) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/dump_info.dart ('k') | pkg/compiler/lib/src/io/source_information.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+ }
});
}
« no previous file with comments | « pkg/compiler/lib/src/dump_info.dart ('k') | pkg/compiler/lib/src/io/source_information.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698