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

Side by Side Diff: lib/parser.dart

Issue 12937009: renaming File to Source (Closed) Base URL: git@github.com:dart-lang/source-maps.git@master
Patch Set: Created 7 years, 9 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) 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 /// Contains the top-level function to parse source maps version 3. 5 /// Contains the top-level function to parse source maps version 3.
6 library source_maps.parser; 6 library source_maps.parser;
7 7
8 import 'dart:json' as json; 8 import 'dart:json' as json;
9 9
10 import 'span.dart'; 10 import 'span.dart';
(...skipping 26 matching lines...) Expand all
37 'cannot contain "mappings", "sources", or "names".'); 37 'cannot contain "mappings", "sources", or "names".');
38 } 38 }
39 return new MultiSectionMapping.fromJson(map['sections'], otherMaps); 39 return new MultiSectionMapping.fromJson(map['sections'], otherMaps);
40 } 40 }
41 return new SingleMapping.fromJson(map); 41 return new SingleMapping.fromJson(map);
42 } 42 }
43 43
44 44
45 /// A mapping parsed our of a source map. 45 /// A mapping parsed our of a source map.
46 abstract class Mapping { 46 abstract class Mapping {
47 Span spanFor(int line, int column, {Map<String, File> files}); 47 Span spanFor(int line, int column, {Map<String, SourceFile> files});
48 48
49 Span spanForLocation(Location loc, {Map<String, File> files}) { 49 Span spanForLocation(Location loc, {Map<String, SourceFile> files}) {
50 return spanFor(loc.line, loc.column, files: files); 50 return spanFor(loc.line, loc.column, files: files);
51 } 51 }
52 } 52 }
53 53
54 /// A meta-level map containing sections. 54 /// A meta-level map containing sections.
55 class MultiSectionMapping extends Mapping { 55 class MultiSectionMapping extends Mapping {
56 /// For each section, the start line offset. 56 /// For each section, the start line offset.
57 final List<int> _lineStart = <int>[]; 57 final List<int> _lineStart = <int>[];
58 58
59 /// For each section, the start column offset. 59 /// For each section, the start column offset.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 int _indexFor(line, column) { 104 int _indexFor(line, column) {
105 for(int i = 0; i < _lineStart.length; i++) { 105 for(int i = 0; i < _lineStart.length; i++) {
106 if (line < _lineStart[i]) return i - 1; 106 if (line < _lineStart[i]) return i - 1;
107 if (line == _lineStart[i] && column < _columnStart[i]) return i - 1; 107 if (line == _lineStart[i] && column < _columnStart[i]) return i - 1;
108 } 108 }
109 return _lineStart.length - 1; 109 return _lineStart.length - 1;
110 } 110 }
111 111
112 Span spanFor(int line, int column, {Map<String, File> files}) { 112 Span spanFor(int line, int column, {Map<String, SourceFile> files}) {
113 int index = _indexFor(line, column); 113 int index = _indexFor(line, column);
114 return _maps[index].spanFor( 114 return _maps[index].spanFor(
115 line - _lineStart[index], column - _columnStart[index], files: files); 115 line - _lineStart[index], column - _columnStart[index], files: files);
116 } 116 }
117 117
118 String toString() { 118 String toString() {
119 var buff = new StringBuffer("$runtimeType : ["); 119 var buff = new StringBuffer("$runtimeType : [");
120 for (int i = 0; i < _lineStart.length; i++) { 120 for (int i = 0; i < _lineStart.length; i++) {
121 buff..write('(') 121 buff..write('(')
122 ..write(_lineStart[i]) 122 ..write(_lineStart[i])
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 /// [lineEntry] corresponds to a line prior to [line], then the result will be 234 /// [lineEntry] corresponds to a line prior to [line], then the result will be
235 /// the very last entry on that line. 235 /// the very last entry on that line.
236 TargetEntry _findColumn(int line, int column, TargetLineEntry lineEntry) { 236 TargetEntry _findColumn(int line, int column, TargetLineEntry lineEntry) {
237 if (lineEntry == null || lineEntry.entries.length == 0) return null; 237 if (lineEntry == null || lineEntry.entries.length == 0) return null;
238 if (lineEntry.line != line) return lineEntry.entries.last; 238 if (lineEntry.line != line) return lineEntry.entries.last;
239 var entries = lineEntry.entries; 239 var entries = lineEntry.entries;
240 int index = binarySearch(entries, (e) => e.column > column); 240 int index = binarySearch(entries, (e) => e.column > column);
241 return (index <= 0) ? null : entries[index - 1]; 241 return (index <= 0) ? null : entries[index - 1];
242 } 242 }
243 243
244 Span spanFor(int line, int column, {Map<String, File> files}) { 244 Span spanFor(int line, int column, {Map<String, SourceFile> files}) {
245 var lineEntry = _findLine(line); 245 var lineEntry = _findLine(line);
246 var entry = _findColumn(line, column, _findLine(line)); 246 var entry = _findColumn(line, column, _findLine(line));
247 if (entry == null) return null; 247 if (entry == null) return null;
248 var url = urls[entry.sourceUrlId]; 248 var url = urls[entry.sourceUrlId];
249 if (files != null && files[url] != null) { 249 if (files != null && files[url] != null) {
250 var file = files[url]; 250 var file = files[url];
251 var start = file.getOffset(entry.sourceLine, entry.sourceColumn); 251 var start = file.getOffset(entry.sourceLine, entry.sourceColumn);
252 if (entry.sourceNameId != null) { 252 if (entry.sourceNameId != null) {
253 var text = names[entry.sourceNameId]; 253 var text = names[entry.sourceNameId];
254 return new FileSpan(files[url], start, start + text.length, true); 254 return new FileSpan(files[url], start, start + text.length, true);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 static const _TokenKind EOF = const _TokenKind(isEof: true); 382 static const _TokenKind EOF = const _TokenKind(isEof: true);
383 static const _TokenKind VALUE = const _TokenKind(); 383 static const _TokenKind VALUE = const _TokenKind();
384 final bool isNewLine; 384 final bool isNewLine;
385 final bool isNewSegment; 385 final bool isNewSegment;
386 final bool isEof; 386 final bool isEof;
387 bool get isValue => !isNewLine && !isNewSegment && !isEof; 387 bool get isValue => !isNewLine && !isNewSegment && !isEof;
388 388
389 const _TokenKind( 389 const _TokenKind(
390 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); 390 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false});
391 } 391 }
OLDNEW
« no previous file with comments | « lib/builder.dart ('k') | lib/source_maps.dart » ('j') | lib/source_maps.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698