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

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

Issue 2804613003: Make lines and columns one-based in SourceLocation. (Closed)
Patch Set: Created 3 years, 8 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_map_builder; 5 library dart2js.source_map_builder;
6 6
7 import 'package:kernel/ast.dart' show Location; 7 import 'package:kernel/ast.dart' show Location;
8 import '../../compiler_new.dart' show OutputSink, OutputType; 8 import '../../compiler_new.dart' show OutputSink, OutputType;
9 import '../util/uri_extras.dart' show relativize; 9 import '../util/uri_extras.dart' show relativize;
10 import '../util/util.dart'; 10 import '../util/util.dart';
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 int column = kernelLocation.column - 1; 56 int column = kernelLocation.column - 1;
57 lineColumnMap.add(line, column, sourceMapEntry); 57 lineColumnMap.add(line, column, sourceMapEntry);
58 58
59 SourceLocation location = sourceMapEntry.sourceLocation; 59 SourceLocation location = sourceMapEntry.sourceLocation;
60 if (location != null) { 60 if (location != null) {
61 if (location.sourceUri != null) { 61 if (location.sourceUri != null) {
62 LineColumnMap<SourceMapEntry> sourceLineColumnMap = 62 LineColumnMap<SourceMapEntry> sourceLineColumnMap =
63 sourceLocationMap.putIfAbsent(location.sourceUri, 63 sourceLocationMap.putIfAbsent(location.sourceUri,
64 () => new LineColumnMap<SourceMapEntry>()); 64 () => new LineColumnMap<SourceMapEntry>());
65 sourceLineColumnMap.add( 65 sourceLineColumnMap.add(
66 location.line, location.column, sourceMapEntry); 66 location.line - 1, location.column - 1, sourceMapEntry);
67 } 67 }
68 } 68 }
69 }); 69 });
70 70
71 return _build(lineColumnMap); 71 return _build(lineColumnMap);
72 } 72 }
73 73
74 String _build(LineColumnMap<SourceMapEntry> lineColumnMap) { 74 String _build(LineColumnMap<SourceMapEntry> lineColumnMap) {
75 IndexMap<Uri> uriMap = new IndexMap<Uri>(); 75 IndexMap<Uri> uriMap = new IndexMap<Uri>();
76 IndexMap<String> nameMap = new IndexMap<String>(); 76 IndexMap<String> nameMap = new IndexMap<String>();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 targetColumnEncoder.encode(output, targetColumn); 151 targetColumnEncoder.encode(output, targetColumn);
152 152
153 if (sourceLocation == null) { 153 if (sourceLocation == null) {
154 return; 154 return;
155 } 155 }
156 156
157 Uri sourceUri = sourceLocation.sourceUri; 157 Uri sourceUri = sourceLocation.sourceUri;
158 if (sourceUri != null) { 158 if (sourceUri != null) {
159 sourceUriIndexEncoder.encode(output, uriMap[sourceUri]); 159 sourceUriIndexEncoder.encode(output, uriMap[sourceUri]);
160 sourceLineEncoder.encode(output, sourceLocation.line); 160 sourceLineEncoder.encode(output, sourceLocation.line - 1);
161 sourceColumnEncoder.encode(output, sourceLocation.column); 161 sourceColumnEncoder.encode(output, sourceLocation.column - 1);
162 } 162 }
163 163
164 String sourceName = sourceLocation.sourceName; 164 String sourceName = sourceLocation.sourceName;
165 if (sourceName != null) { 165 if (sourceName != null) {
166 sourceNameIndexEncoder.encode(output, nameMap[sourceName]); 166 sourceNameIndexEncoder.encode(output, nameMap[sourceName]);
167 } 167 }
168 168
169 previousSourceLocation = sourceLocation; 169 previousSourceLocation = sourceLocation;
170 }); 170 });
171 } 171 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 int register(T element) { 356 int register(T element) {
357 return map.putIfAbsent(element, () => map.length); 357 return map.putIfAbsent(element, () => map.length);
358 } 358 }
359 359
360 /// Returns the index of [element]. 360 /// Returns the index of [element].
361 int operator [](T element) => map[element]; 361 int operator [](T element) => map[element];
362 362
363 /// Returns the indexed elements. 363 /// Returns the indexed elements.
364 Iterable<T> get elements => map.keys; 364 Iterable<T> get elements => map.keys;
365 } 365 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/io/source_information.dart ('k') | pkg/compiler/lib/src/io/start_end_information.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698