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

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

Issue 1196433002: Create and test source mapping for invocations. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased Created 5 years, 6 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/io/position_information.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/source_file.dart
diff --git a/pkg/compiler/lib/src/io/source_file.dart b/pkg/compiler/lib/src/io/source_file.dart
index 8fd28ffbe664fd87caefb2cf2dfd52c23ed732c8..d799a9bfaba0048f0420919e5e3ad5d6db3a934a 100644
--- a/pkg/compiler/lib/src/io/source_file.dart
+++ b/pkg/compiler/lib/src/io/source_file.dart
@@ -115,6 +115,9 @@ abstract class SourceFile implements LineColumnProvider {
return position - lineStarts[line];
}
+ /// Returns the offset for 0-based [line] and [column] numbers.
+ int getOffset(int line, int column) => lineStarts[line] + column;
+
String slowSubstring(int start, int end);
/**
@@ -145,13 +148,7 @@ abstract class SourceFile implements LineColumnProvider {
buf.write('\n$message\n');
if (start != end && includeSourceLine) {
- String textLine;
- // +1 for 0-indexing, +1 again to avoid the last line of the file
- if ((line + 2) < lineStarts.length) {
- textLine = slowSubstring(lineStarts[line], lineStarts[line+1]);
- } else {
- textLine = '${slowSubstring(lineStarts[line], length)}\n';
- }
+ String textLine = getLineText(line);
int toColumn = min(column + (end-start), textLine.length);
buf.write(textLine.substring(0, column));
@@ -170,6 +167,20 @@ abstract class SourceFile implements LineColumnProvider {
return buf.toString();
}
+
+ int get lines => lineStarts.length - 1;
+
+ /// Returns the text of line at the 0-based [index] within this source file.
+ String getLineText(int index) {
+ // +1 for 0-indexing, +1 again to avoid the last line of the file
+ if ((index + 2) < lineStarts.length) {
+ return slowSubstring(lineStarts[index], lineStarts[index+1]);
+ } else if ((index + 1) < lineStarts.length) {
+ return '${slowSubstring(lineStarts[index], length)}\n';
+ } else {
+ throw new ArgumentError("Line index $index is out of bounds.");
+ }
+ }
}
List<int> _zeroTerminateIfNecessary(List<int> bytes) {
@@ -212,7 +223,7 @@ class Utf8BytesSourceFile extends SourceFile {
int get length {
if (lengthCache == -1) {
// During scanning the length is not yet assigned, so we use a slow path.
- length = slowText().length;
+ lengthCache = slowText().length;
}
return lengthCache;
}
« no previous file with comments | « pkg/compiler/lib/src/io/position_information.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