| 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 '../dart2jslib.dart' show SourceSpan; | 7 import '../dart2jslib.dart' show SourceSpan; |
| 8 import '../elements/elements.dart' show AstElement; | 8 import '../elements/elements.dart' show AstElement; |
| 9 import '../scanner/scannerlib.dart' show Token; | 9 import '../scanner/scannerlib.dart' show Token; |
| 10 import '../tree/tree.dart' show Node; | 10 import '../tree/tree.dart' show Node; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (endToken.charOffset < sourceFile.length) { | 88 if (endToken.charOffset < sourceFile.length) { |
| 89 endSourcePosition = | 89 endSourcePosition = |
| 90 new TokenSourceLocation(sourceFile, endToken, name); | 90 new TokenSourceLocation(sourceFile, endToken, name); |
| 91 } | 91 } |
| 92 return new StartEndSourceInformation(sourcePosition, endSourcePosition); | 92 return new StartEndSourceInformation(sourcePosition, endSourcePosition); |
| 93 } | 93 } |
| 94 | 94 |
| 95 String toString() { | 95 String toString() { |
| 96 StringBuffer sb = new StringBuffer(); | 96 StringBuffer sb = new StringBuffer(); |
| 97 sb.write('${startPosition.sourceUri}:'); | 97 sb.write('${startPosition.sourceUri}:'); |
| 98 sb.write('[${startPosition.line},${startPosition.column}]'); | 98 // Use 1-based line/column info to match usual dart tool output. |
| 99 sb.write('[${startPosition.line + 1},${startPosition.column + 1}]'); |
| 99 if (endPosition != null) { | 100 if (endPosition != null) { |
| 100 sb.write('-[${endPosition.line},${endPosition.column}]'); | 101 sb.write('-[${endPosition.line + 1},${endPosition.column + 1}]'); |
| 101 } | 102 } |
| 102 return sb.toString(); | 103 return sb.toString(); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 107 /// [SourceInformation] that consists of an offset position into the source |
| 108 /// code. |
| 109 class PositionSourceInformation implements SourceInformation { |
| 110 final SourceLocation sourcePosition; |
| 111 |
| 112 PositionSourceInformation(this.sourcePosition); |
| 113 |
| 114 @override |
| 115 void beginMapping(CodeOutput output) { |
| 116 output.setSourceLocation(sourcePosition); |
| 117 } |
| 118 |
| 119 @override |
| 120 void endMapping(CodeOutput output) { |
| 121 // Do nothing. |
| 122 } |
| 123 |
| 124 SourceSpan get sourceSpan { |
| 125 Uri uri = sourcePosition.sourceUri; |
| 126 int offset = sourcePosition.offset; |
| 127 return new SourceSpan(uri, offset, offset); |
| 128 } |
| 129 |
| 130 int get hashCode { |
| 131 return sourcePosition.hashCode * 17 & 0x7FFFFFFF; |
| 132 } |
| 133 |
| 134 bool operator ==(other) { |
| 135 if (identical(this, other)) return true; |
| 136 if (other is! PositionSourceInformation) return false; |
| 137 return sourcePosition == other.sourcePosition; |
| 138 } |
| 139 |
| 140 String toString() { |
| 141 StringBuffer sb = new StringBuffer(); |
| 142 sb.write('${sourcePosition.sourceUri}:'); |
| 143 // Use 1-based line/column info to match usual dart tool output. |
| 144 sb.write('[${sourcePosition.line + 1},${sourcePosition.column + 1}]'); |
| 145 return sb.toString(); |
| 146 } |
| 147 } |
| 148 |
| 106 /// A location in a source file. | 149 /// A location in a source file. |
| 107 abstract class SourceLocation { | 150 abstract class SourceLocation { |
| 108 final SourceFile _sourceFile; | 151 final SourceFile _sourceFile; |
| 109 int _line; | 152 int _line; |
| 110 | 153 |
| 111 SourceLocation(this._sourceFile) { | 154 SourceLocation(this._sourceFile) { |
| 112 assert(isValid); | 155 assert(isValid); |
| 113 } | 156 } |
| 114 | 157 |
| 115 /// The absolute URI of the source file of this source location. | 158 /// The absolute URI of the source file of this source location. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 140 } | 183 } |
| 141 | 184 |
| 142 bool operator ==(other) { | 185 bool operator ==(other) { |
| 143 if (identical(this, other)) return true; | 186 if (identical(this, other)) return true; |
| 144 if (other is! SourceLocation) return false; | 187 if (other is! SourceLocation) return false; |
| 145 return sourceUri == other.sourceUri && | 188 return sourceUri == other.sourceUri && |
| 146 offset == other.offset && | 189 offset == other.offset && |
| 147 sourceName == other.sourceName; | 190 sourceName == other.sourceName; |
| 148 } | 191 } |
| 149 | 192 |
| 150 String toString() => '${sourceUri}:[${line},${column}]'; | 193 String toString() { |
| 194 // Use 1-based line/column info to match usual dart tool output. |
| 195 return '${sourceUri}:[${line + 1},${column + 1}]'; |
| 196 } |
| 151 } | 197 } |
| 152 | 198 |
| 153 class TokenSourceLocation extends SourceLocation { | 199 class TokenSourceLocation extends SourceLocation { |
| 154 final Token token; | 200 final Token token; |
| 155 final String sourceName; | 201 final String sourceName; |
| 156 | 202 |
| 157 TokenSourceLocation(SourceFile sourceFile, this.token, this.sourceName) | 203 TokenSourceLocation(SourceFile sourceFile, this.token, this.sourceName) |
| 158 : super(sourceFile); | 204 : super(sourceFile); |
| 159 | 205 |
| 160 @override | 206 @override |
| 161 int get offset => token.charOffset; | 207 int get offset => token.charOffset; |
| 162 | 208 |
| 163 String toString() { | 209 String toString() { |
| 164 return '${super.toString()}:$sourceName'; | 210 return '${super.toString()}:$sourceName'; |
| 165 } | 211 } |
| 166 } | 212 } |
| OLD | NEW |