Chromium Code Reviews| Index: lib/compiler/implementation/source_map_builder.dart |
| diff --git a/lib/compiler/implementation/source_map_builder.dart b/lib/compiler/implementation/source_map_builder.dart |
| index 729991458dea9fa5a1801f68e9881dae1444196e..75399ab847a137ce21b52301cbf428aba6d1d4f0 100644 |
| --- a/lib/compiler/implementation/source_map_builder.dart |
| +++ b/lib/compiler/implementation/source_map_builder.dart |
| @@ -6,6 +6,7 @@ |
| #import('dart:json'); |
| +#import('scanner/scannerlib.dart'); |
| #import('source_file.dart'); |
| class SourceMapBuilder { |
| @@ -48,9 +49,8 @@ class SourceMapBuilder { |
| firstEntryInLine = true; |
| } |
| - void addMapping(SourceFile sourceFile, int sourceOffset, String sourceName, |
| - int targetOffset) { |
| - entries.add(new _Entry(sourceFile, sourceOffset, sourceName, targetOffset)); |
| + void addMapping(int targetOffset, SourceFileLocation sourceLocation) { |
| + entries.add(new _Entry(sourceLocation, targetOffset)); |
| } |
| String build(SourceFile targetFile) { |
| @@ -72,18 +72,6 @@ class SourceMapBuilder { |
| void writeEntry(_Entry entry, SourceFile targetFile, StringBuffer output) { |
| int targetLine = targetFile.getLine(entry.targetOffset); |
| int targetColumn = targetFile.getColumn(targetLine, entry.targetOffset); |
| - String sourceUrl; |
| - int sourceLine; |
| - int sourceColumn; |
| - SourceFile sourceFile = entry.sourceFile; |
| - // TODO(podivilov): make sure entries are always associated with the right |
| - // source file. |
| - if (sourceFile != null && entry.sourceOffset < sourceFile.text.length) { |
| - sourceUrl = sourceFile.filename; |
| - sourceLine = sourceFile.getLine(entry.sourceOffset); |
| - sourceColumn = sourceFile.getColumn(sourceLine, entry.sourceOffset); |
| - } |
| - String sourceName = entry.sourceName; |
| if (targetLine > previousTargetLine) { |
| for (int i = previousTargetLine; i < targetLine; ++i) { |
| @@ -102,9 +90,12 @@ class SourceMapBuilder { |
| encodeVLQ(output, targetColumn - previousTargetColumn); |
| previousTargetColumn = targetColumn; |
| - if (sourceUrl === null) { |
| - return; |
| - } |
| + if (entry.sourceLocation === null) return; |
| + |
| + String sourceUrl = entry.sourceLocation.getSourceUrl(); |
| + int sourceLine = entry.sourceLocation.getLine(); |
| + int sourceColumn = entry.sourceLocation.getColumn(); |
| + String sourceName = entry.sourceLocation.getSourceName(); |
| int sourceUrlIndex = indexOf(sourceUrlList, sourceUrl, sourceUrlMap); |
| encodeVLQ(output, sourceUrlIndex - previousSourceUrlIndex); |
| @@ -152,10 +143,32 @@ class SourceMapBuilder { |
| } |
| class _Entry { |
|
ahe
2012/09/08 08:55:50
Why is this class private?
podivilov
2012/09/10 11:13:23
Done.
|
| - SourceFile sourceFile; |
| - int sourceOffset; |
| - String sourceName; |
| + SourceFileLocation sourceLocation; |
| int targetOffset; |
| - _Entry(this.sourceFile, this.sourceOffset, this.sourceName, |
| - this.targetOffset); |
| + |
| + _Entry(this.sourceLocation, this.targetOffset); |
| +} |
| + |
| +class SourceFileLocation { |
| + SourceFile sourceFile; |
| + Token token; |
| + int line; |
| + |
| + SourceFileLocation(this.sourceFile, this.token) { |
| + assert(token.charOffset < sourceFile.text.length); |
| + } |
| + |
| + String getSourceUrl() => sourceFile.filename; |
| + |
| + int getLine() { |
| + if (line == null) line = sourceFile.getLine(token.charOffset); |
| + return line; |
| + } |
| + |
| + int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); |
| + |
| + String getSourceName() { |
| + if (token.kind === IDENTIFIER_TOKEN) return token.slowToString(); |
|
ahe
2012/09/08 08:55:50
This should be isIdentifier(token) which is define
podivilov
2012/09/10 11:13:23
Done.
|
| + return null; |
| + } |
| } |