OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.source_information; | 5 library dart2js.source_information; |
6 | 6 |
| 7 import 'package:kernel/ast.dart' show Location; |
7 import '../common.dart'; | 8 import '../common.dart'; |
8 import '../elements/elements.dart' | 9 import '../elements/elements.dart' |
9 show | 10 show |
10 AstElement, | 11 AstElement, |
11 CompilationUnitElement, | 12 CompilationUnitElement, |
12 LocalElement, | 13 LocalElement, |
13 ResolvedAst, | 14 ResolvedAst, |
14 ResolvedAstKind; | 15 ResolvedAstKind; |
15 import '../js/js.dart' show JavaScriptNodeSourceInformation; | 16 import '../js/js.dart' show JavaScriptNodeSourceInformation; |
16 import '../script.dart'; | 17 import '../script.dart'; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 196 |
196 String toString() { | 197 String toString() { |
197 // Use 1-based line/column info to match usual dart tool output. | 198 // Use 1-based line/column info to match usual dart tool output. |
198 return '${sourceUri}:[${line + 1},${column + 1}]'; | 199 return '${sourceUri}:[${line + 1},${column + 1}]'; |
199 } | 200 } |
200 } | 201 } |
201 | 202 |
202 /// A location in a source file. | 203 /// A location in a source file. |
203 abstract class AbstractSourceLocation extends SourceLocation { | 204 abstract class AbstractSourceLocation extends SourceLocation { |
204 final SourceFile _sourceFile; | 205 final SourceFile _sourceFile; |
205 int _line; | 206 Location _location; |
206 | 207 |
207 AbstractSourceLocation(this._sourceFile) { | 208 AbstractSourceLocation(this._sourceFile) { |
208 assert(invariant(new SourceSpan(sourceUri, 0, 0), isValid, | 209 assert(invariant(new SourceSpan(sourceUri, 0, 0), isValid, |
209 message: "Invalid source location in ${sourceUri}: " | 210 message: "Invalid source location in ${sourceUri}: " |
210 "offset=$offset, length=${_sourceFile.length}.")); | 211 "offset=$offset, length=${_sourceFile.length}.")); |
211 } | 212 } |
212 | 213 |
213 /// The absolute URI of the source file of this source location. | 214 /// The absolute URI of the source file of this source location. |
214 Uri get sourceUri => _sourceFile.uri; | 215 Uri get sourceUri => _sourceFile.uri; |
215 | 216 |
216 /// The character offset of the this source location into the source file. | 217 /// The character offset of the this source location into the source file. |
217 int get offset; | 218 int get offset; |
218 | 219 |
219 /// The 0-based line number of the [offset]. | 220 /// The 0-based line number of the [offset]. |
220 int get line { | 221 int get line { |
221 if (_line == null) _line = _sourceFile.getLine(offset); | 222 _location ??= _sourceFile.getLocation(offset); |
222 return _line; | 223 return _location.line - 1; |
223 } | 224 } |
224 | 225 |
225 /// The 0-base column number of the [offset] with its line. | 226 /// The 0-base column number of the [offset] with its line. |
226 int get column => _sourceFile.getColumn(line, offset); | 227 int get column { |
| 228 _location ??= _sourceFile.getLocation(offset); |
| 229 return _location.column - 1; |
| 230 } |
227 | 231 |
228 /// The name associated with this source location, if any. | 232 /// The name associated with this source location, if any. |
229 String get sourceName; | 233 String get sourceName; |
230 | 234 |
231 /// `true` if the offset within the length of the source file. | 235 /// `true` if the offset within the length of the source file. |
232 bool get isValid => offset < _sourceFile.length; | 236 bool get isValid => offset < _sourceFile.length; |
233 | 237 |
234 String get shortText { | 238 String get shortText { |
235 // Use 1-based line/column info to match usual dart tool output. | 239 // Use 1-based line/column info to match usual dart tool output. |
236 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]'; | 240 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]'; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 @override | 338 @override |
335 int get line => null; | 339 int get line => null; |
336 | 340 |
337 @override | 341 @override |
338 int get offset => null; | 342 int get offset => null; |
339 | 343 |
340 String get shortName => '<no-location>'; | 344 String get shortName => '<no-location>'; |
341 | 345 |
342 String toString() => '<no-location>'; | 346 String toString() => '<no-location>'; |
343 } | 347 } |
OLD | NEW |