Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: pkg/compiler/lib/src/io/source_information.dart

Issue 2654023003: Add no-info mappings at start of out.js and after mapped functions (Closed)
Patch Set: fixes Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 '../common.dart'; 7 import '../common.dart';
8 import '../elements/elements.dart' 8 import '../elements/elements.dart'
9 show 9 show
10 AstElement, 10 AstElement,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 /// Generate [SourceInformation] for the switch statement [node]. 148 /// Generate [SourceInformation] for the switch statement [node].
149 SourceInformation buildSwitch(Node node) => null; 149 SourceInformation buildSwitch(Node node) => null;
150 150
151 /// Generate [SourceInformation] for the switch case in [node]. 151 /// Generate [SourceInformation] for the switch case in [node].
152 SourceInformation buildSwitchCase(Node node) => null; 152 SourceInformation buildSwitchCase(Node node) => null;
153 } 153 }
154 154
155 /// A location in a source file. 155 /// A location in a source file.
156 abstract class SourceLocation { 156 abstract class SourceLocation {
157 final SourceFile _sourceFile; 157 const SourceLocation();
158 int _line;
159
160 SourceLocation(this._sourceFile) {
161 assert(invariant(new SourceSpan(sourceUri, 0, 0), isValid,
162 message: "Invalid source location in ${sourceUri}: "
163 "offset=$offset, length=${_sourceFile.length}."));
164 }
165 158
166 /// The absolute URI of the source file of this source location. 159 /// The absolute URI of the source file of this source location.
167 Uri get sourceUri => _sourceFile.uri; 160 Uri get sourceUri;
168 161
169 /// The character offset of the this source location into the source file. 162 /// The character offset of the this source location into the source file.
170 int get offset; 163 int get offset;
171 164
172 /// The 0-based line number of the [offset]. 165 /// The 0-based line number of the [offset].
173 int get line { 166 int get line;
174 if (_line == null) _line = _sourceFile.getLine(offset);
175 return _line;
176 }
177 167
178 /// The 0-base column number of the [offset] with its line. 168 /// The 0-base column number of the [offset] with its line.
179 int get column => _sourceFile.getColumn(line, offset); 169 int get column;
180 170
181 /// The name associated with this source location, if any. 171 /// The name associated with this source location, if any.
182 String get sourceName; 172 String get sourceName;
183 173
184 /// `true` if the offset within the length of the source file. 174 /// `true` if the offset within the length of the source file.
185 bool get isValid => offset < _sourceFile.length; 175 bool get isValid;
186 176
187 int get hashCode { 177 int get hashCode {
188 return sourceUri.hashCode * 17 + 178 return sourceUri.hashCode * 17 +
189 offset.hashCode * 17 + 179 offset.hashCode * 17 +
190 sourceName.hashCode * 23; 180 sourceName.hashCode * 23;
191 } 181 }
192 182
193 bool operator ==(other) { 183 bool operator ==(other) {
194 if (identical(this, other)) return true; 184 if (identical(this, other)) return true;
195 if (other is! SourceLocation) return false; 185 if (other is! SourceLocation) return false;
196 return sourceUri == other.sourceUri && 186 return sourceUri == other.sourceUri &&
197 offset == other.offset && 187 offset == other.offset &&
198 sourceName == other.sourceName; 188 sourceName == other.sourceName;
199 } 189 }
200 190
201 String get shortText { 191 String get shortText {
202 // Use 1-based line/column info to match usual dart tool output. 192 // Use 1-based line/column info to match usual dart tool output.
203 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]'; 193 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]';
204 } 194 }
205 195
206 String toString() { 196 String toString() {
207 // Use 1-based line/column info to match usual dart tool output. 197 // Use 1-based line/column info to match usual dart tool output.
208 return '${sourceUri}:[${line + 1},${column + 1}]'; 198 return '${sourceUri}:[${line + 1},${column + 1}]';
209 } 199 }
210 } 200 }
211 201
212 class OffsetSourceLocation extends SourceLocation { 202 /// A location in a source file.
203 abstract class AbstractSourceLocation extends SourceLocation {
204 final SourceFile _sourceFile;
205 int _line;
206
207 AbstractSourceLocation(this._sourceFile) {
208 assert(invariant(new SourceSpan(sourceUri, 0, 0), isValid,
209 message: "Invalid source location in ${sourceUri}: "
210 "offset=$offset, length=${_sourceFile.length}."));
211 }
212
213 /// The absolute URI of the source file of this source location.
214 Uri get sourceUri => _sourceFile.uri;
215
216 /// The character offset of the this source location into the source file.
217 int get offset;
218
219 /// The 0-based line number of the [offset].
220 int get line {
221 if (_line == null) _line = _sourceFile.getLine(offset);
222 return _line;
223 }
224
225 /// The 0-base column number of the [offset] with its line.
226 int get column => _sourceFile.getColumn(line, offset);
227
228 /// The name associated with this source location, if any.
229 String get sourceName;
230
231 /// `true` if the offset within the length of the source file.
232 bool get isValid => offset < _sourceFile.length;
233
234 String get shortText {
235 // Use 1-based line/column info to match usual dart tool output.
236 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]';
237 }
238
239 String toString() {
240 // Use 1-based line/column info to match usual dart tool output.
241 return '${sourceUri}:[${line + 1},${column + 1}]';
242 }
243 }
244
245 class OffsetSourceLocation extends AbstractSourceLocation {
213 final int offset; 246 final int offset;
214 final String sourceName; 247 final String sourceName;
215 248
216 OffsetSourceLocation(SourceFile sourceFile, this.offset, this.sourceName) 249 OffsetSourceLocation(SourceFile sourceFile, this.offset, this.sourceName)
217 : super(sourceFile); 250 : super(sourceFile);
218 251
219 String get shortText { 252 String get shortText {
220 return '${super.shortText}:$sourceName'; 253 return '${super.shortText}:$sourceName';
221 } 254 }
222 255
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 Script script = compilationUnit.script; 308 Script script = compilationUnit.script;
276 if (uri == script.resourceUri) { 309 if (uri == script.resourceUri) {
277 sourceFile = script.file; 310 sourceFile = script.file;
278 break; 311 break;
279 } 312 }
280 } 313 }
281 } 314 }
282 } 315 }
283 return sourceFile; 316 return sourceFile;
284 } 317 }
318
319 class NoSourceLocationMarker extends SourceLocation {
320 const NoSourceLocationMarker();
321
322 @override
323 Uri get sourceUri => null;
324
325 @override
326 bool get isValid => true;
327
328 @override
329 String get sourceName => null;
330
331 @override
332 int get column => null;
333
334 @override
335 int get line => null;
336
337 @override
338 int get offset => null;
339
340 String get shortName => '<no-location>';
341
342 String toString() => '<no-location>';
343 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/io/position_information.dart ('k') | pkg/compiler/lib/src/io/source_map_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698