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; | |
138 list.add(value); | 137 list.add(value); |
139 return index; | 138 return index; |
140 }); | 139 }); |
141 } | 140 } |
142 | 141 |
143 static void encodeVLQ(StringBuffer output, int value) { | 142 static void encodeVLQ(StringBuffer output, int value) { |
144 int signBit = 0; | 143 int signBit = 0; |
145 if (value < 0) { | 144 if (value < 0) { |
146 signBit = 1; | 145 signBit = 1; |
147 value = -value; | 146 value = -value; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 182 |
184 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); | 183 int getColumn() => sourceFile.getColumn(getLine(), token.charOffset); |
185 | 184 |
186 String getSourceName() { | 185 String getSourceName() { |
187 if (token.isIdentifier()) return token.slowToString(); | 186 if (token.isIdentifier()) return token.slowToString(); |
188 return null; | 187 return null; |
189 } | 188 } |
190 | 189 |
191 bool isValid() => token.charOffset < sourceFile.text.length; | 190 bool isValid() => token.charOffset < sourceFile.text.length; |
192 } | 191 } |
OLD | NEW |