OLD | NEW |
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 source_map_builder; | 5 library source_map_builder; |
6 | 6 |
7 import 'util/util.dart'; | 7 import 'util/util.dart'; |
8 import 'scanner/scannerlib.dart' show Token; | 8 import 'scanner/scannerlib.dart' show Token; |
9 import 'source_file.dart'; | 9 import 'source_file.dart'; |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 int sourceNameIndex = indexOf(sourceNameList, sourceName, sourceNameMap); | 129 int sourceNameIndex = indexOf(sourceNameList, sourceName, sourceNameMap); |
130 encodeVLQ(output, sourceNameIndex - previousSourceNameIndex); | 130 encodeVLQ(output, sourceNameIndex - previousSourceNameIndex); |
131 previousSourceNameIndex = sourceNameIndex; | 131 previousSourceNameIndex = sourceNameIndex; |
132 } | 132 } |
133 | 133 |
134 int indexOf(List<String> list, String value, Map<String, int> map) { | 134 int indexOf(List<String> list, String value, Map<String, int> map) { |
135 return map.putIfAbsent(value, () { | 135 return map.putIfAbsent(value, () { |
136 int index = list.length; | 136 int index = list.length; |
| 137 map[value] = index; |
137 list.add(value); | 138 list.add(value); |
138 return index; | 139 return index; |
139 }); | 140 }); |
140 } | 141 } |
141 | 142 |
142 static void encodeVLQ(StringBuffer output, int value) { | 143 static void encodeVLQ(StringBuffer output, int value) { |
143 int signBit = 0; | 144 int signBit = 0; |
144 if (value < 0) { | 145 if (value < 0) { |
145 signBit = 1; | 146 signBit = 1; |
146 value = -value; | 147 value = -value; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 183 |
183 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); | 184 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); |
184 | 185 |
185 String getSourceName() { | 186 String getSourceName() { |
186 if (token.isIdentifier()) return token.slowToString(); | 187 if (token.isIdentifier()) return token.slowToString(); |
187 return null; | 188 return null; |
188 } | 189 } |
189 | 190 |
190 bool isValid() => token.charOffset < sourceFile.text.length; | 191 bool isValid() => token.charOffset < sourceFile.text.length; |
191 } | 192 } |
OLD | NEW |