Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Dart classes representing the souce spans and source files. | 5 /// Dart classes representing the souce spans and source files. |
| 6 library source_maps.span; | 6 library source_maps.span; |
| 7 | 7 |
| 8 import 'dart:utf' show stringToCodepoints; | 8 import 'dart:utf' show stringToCodepoints; |
| 9 import 'dart:math' show min, max; | 9 import 'dart:math' show min, max; |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 String get formatLocation => start.formatString; | 62 String get formatLocation => start.formatString; |
| 63 | 63 |
| 64 String getLocationMessage(String message, | 64 String getLocationMessage(String message, |
| 65 {bool useColors: false, String color}) { | 65 {bool useColors: false, String color}) { |
| 66 return '$formatLocation: $message'; | 66 return '$formatLocation: $message'; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool operator ==(Span other) => | 69 bool operator ==(Span other) => |
| 70 sourceUrl == other.sourceUrl && start == other.start && end == other.end; | 70 sourceUrl == other.sourceUrl && start == other.start && end == other.end; |
| 71 | 71 |
| 72 int get hashCode => sourceUrl.hashCode + start + (31 * (end - start)); | 72 int get hashCode => sourceUrl.hashCode + start.offset + (31 * length); |
|
justinfagnani
2013/07/26 00:44:22
length includes information from start.offset alre
Siggi Cherem (dart-lang)
2013/07/26 00:50:12
I could argue the opposite: end.offset is always >
| |
| 73 | 73 |
| 74 String toString() => '<$runtimeType: $start $end $formatLocation $text>'; | 74 String toString() => '<$runtimeType: $start $end $formatLocation $text>'; |
| 75 } | 75 } |
| 76 | 76 |
| 77 /// A location in the source text | 77 /// A location in the source text |
| 78 abstract class Location implements Comparable { | 78 abstract class Location implements Comparable { |
| 79 /// Url of the source containing this span. | 79 /// Url of the source containing this span. |
| 80 String get sourceUrl; | 80 String get sourceUrl; |
| 81 | 81 |
| 82 /// The offset of this location, 0-based. | 82 /// The offset of this location, 0-based. |
| 83 final int offset; | 83 final int offset; |
| 84 | 84 |
| 85 /// The 0-based line in the source of this location. | 85 /// The 0-based line in the source of this location. |
| 86 int get line; | 86 int get line; |
| 87 | 87 |
| 88 /// The 0-based column in the source of this location. | 88 /// The 0-based column in the source of this location. |
| 89 int get column; | 89 int get column; |
| 90 | 90 |
| 91 Location(this.offset); | 91 Location(this.offset); |
| 92 | 92 |
| 93 /// Compares two locations. If the locations are not in the same source, this | 93 /// Compares two locations. If the locations are not in the same source, this |
| 94 /// method generates an error. | 94 /// method generates an error. |
| 95 int compareTo(Location other) { | 95 int compareTo(Location other) { |
| 96 if (sourceUrl != other.sourceUrl) { | 96 if (sourceUrl != other.sourceUrl) { |
| 97 throw new ArgumentError('can only compare locations of the same source'); | 97 throw new ArgumentError('can only compare locations of the same source'); |
| 98 } | 98 } |
| 99 return offset - other.offset; | 99 return offset - other.offset; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool operator ==(Location other) => | |
| 103 sourceUrl == other.sourceUrl && offset == other.offset; | |
| 104 | |
| 105 int get hashCode => sourceUrl.hashCode + offset; | |
| 106 | |
| 102 String toString() => '(Location $offset)'; | 107 String toString() => '(Location $offset)'; |
| 103 String get formatString => '$sourceUrl:${line + 1}:${column + 1}'; | 108 String get formatString => '$sourceUrl:${line + 1}:${column + 1}'; |
| 104 } | 109 } |
| 105 | 110 |
| 106 /// Implementation of [Location] with fixed values given at allocation time. | 111 /// Implementation of [Location] with fixed values given at allocation time. |
| 107 class FixedLocation extends Location { | 112 class FixedLocation extends Location { |
| 108 final String sourceUrl; | 113 final String sourceUrl; |
| 109 final int line; | 114 final int line; |
| 110 final int column; | 115 final int column; |
| 111 | 116 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 int getOffset(int line, int column) => | 352 int getOffset(int line, int column) => |
| 348 super.getOffset(line - _baseLine, | 353 super.getOffset(line - _baseLine, |
| 349 line == _baseLine ? column - _baseColumn : column) + _baseOffset; | 354 line == _baseLine ? column - _baseColumn : column) + _baseOffset; |
| 350 | 355 |
| 351 /// Retrieve the text associated with the specified range. This method | 356 /// Retrieve the text associated with the specified range. This method |
| 352 /// operates on the real offsets from the original file, so that error | 357 /// operates on the real offsets from the original file, so that error |
| 353 /// messages can be reported accurately. | 358 /// messages can be reported accurately. |
| 354 String getText(int start, [int end]) => | 359 String getText(int start, [int end]) => |
| 355 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); | 360 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); |
| 356 } | 361 } |
| OLD | NEW |