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 library source_map_builder; | 5 library source_map_builder; |
6 | 6 |
7 | 7 |
8 import 'util/util.dart'; | 8 import 'util/util.dart'; |
9 import 'scanner/scannerlib.dart' show Token; | 9 import 'scanner/scannerlib.dart' show Token; |
10 import 'source_file.dart'; | 10 import 'source_file.dart'; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 class SourceMapEntry { | 169 class SourceMapEntry { |
170 SourceFileLocation sourceLocation; | 170 SourceFileLocation sourceLocation; |
171 int targetOffset; | 171 int targetOffset; |
172 | 172 |
173 SourceMapEntry(this.sourceLocation, this.targetOffset); | 173 SourceMapEntry(this.sourceLocation, this.targetOffset); |
174 } | 174 } |
175 | 175 |
176 class SourceFileLocation { | 176 abstract class SourceFileLocation { |
177 SourceFile sourceFile; | 177 SourceFile sourceFile; |
178 Token token; | 178 |
| 179 SourceFileLocation(this.sourceFile) { |
| 180 assert(isValid()); |
| 181 } |
| 182 |
179 int line; | 183 int line; |
180 | 184 |
181 SourceFileLocation(this.sourceFile, this.token) { | 185 int get offset; |
182 assert(isValid()); | |
183 } | |
184 | 186 |
185 String getSourceUrl() => sourceFile.filename; | 187 String getSourceUrl() => sourceFile.filename; |
186 | 188 |
187 int getLine() { | 189 int getLine() { |
188 if (line == null) line = sourceFile.getLine(token.charOffset); | 190 if (line == null) line = sourceFile.getLine(offset); |
189 return line; | 191 return line; |
190 } | 192 } |
191 | 193 |
192 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); | 194 int getColumn() => sourceFile.getColumn(getLine(), offset); |
| 195 |
| 196 String getSourceName(); |
| 197 |
| 198 bool isValid() => offset < sourceFile.length; |
| 199 } |
| 200 |
| 201 class TokenSourceFileLocation extends SourceFileLocation { |
| 202 final Token token; |
| 203 |
| 204 TokenSourceFileLocation(SourceFile sourceFile, this.token) |
| 205 : super(sourceFile); |
| 206 |
| 207 int get offset => token.charOffset; |
193 | 208 |
194 String getSourceName() { | 209 String getSourceName() { |
195 if (token.isIdentifier()) return token.value; | 210 if (token.isIdentifier()) return token.value; |
196 return null; | 211 return null; |
197 } | 212 } |
| 213 } |
198 | 214 |
199 bool isValid() => token.charOffset < sourceFile.length; | 215 class OffsetSourceFileLocation extends SourceFileLocation { |
| 216 final int offset; |
| 217 final String sourceName; |
| 218 OffsetSourceFileLocation(SourceFile sourceFile, this.offset, |
| 219 [this.sourceName]) : super(sourceFile); |
| 220 |
| 221 String getSourceName() => sourceName; |
200 } | 222 } |
OLD | NEW |