| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 9 */ | 9 */ |
| 10 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 DartType type = constant.representedType; | 1174 DartType type = constant.representedType; |
| 1175 JavaScriptBackend backend = compiler.backend; | 1175 JavaScriptBackend backend = compiler.backend; |
| 1176 String name = backend.rti.getRawTypeRepresentation(type); | 1176 String name = backend.rti.getRawTypeRepresentation(type); |
| 1177 addIdentifier(name); | 1177 addIdentifier(name); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 visitInterceptor(InterceptorConstant constant) { | 1180 visitInterceptor(InterceptorConstant constant) { |
| 1181 addRoot(constant.dispatchedType.element.name); | 1181 addRoot(constant.dispatchedType.element.name); |
| 1182 add('methods'); | 1182 add('methods'); |
| 1183 } | 1183 } |
| 1184 | |
| 1185 visitDummyReceiver(DummyReceiverConstant constant) { | |
| 1186 add('dummy_receiver'); | |
| 1187 } | |
| 1188 } | 1184 } |
| 1189 | 1185 |
| 1190 /** | 1186 /** |
| 1191 * Generates canonical hash values for [Constant]s. | 1187 * Generates canonical hash values for [Constant]s. |
| 1192 * | 1188 * |
| 1193 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, | 1189 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, |
| 1194 * so it can't be used for generating names. This hasher keeps consistency | 1190 * so it can't be used for generating names. This hasher keeps consistency |
| 1195 * between runs by basing hash values of the names of elements, rather than | 1191 * between runs by basing hash values of the names of elements, rather than |
| 1196 * their hashCodes. | 1192 * their hashCodes. |
| 1197 */ | 1193 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 JavaScriptBackend backend = compiler.backend; | 1251 JavaScriptBackend backend = compiler.backend; |
| 1256 String name = backend.rti.getRawTypeRepresentation(type); | 1252 String name = backend.rti.getRawTypeRepresentation(type); |
| 1257 return _hashString(4, name); | 1253 return _hashString(4, name); |
| 1258 } | 1254 } |
| 1259 | 1255 |
| 1260 visitInterceptor(InterceptorConstant constant) { | 1256 visitInterceptor(InterceptorConstant constant) { |
| 1261 String typeName = constant.dispatchedType.element.name; | 1257 String typeName = constant.dispatchedType.element.name; |
| 1262 return _hashString(5, typeName); | 1258 return _hashString(5, typeName); |
| 1263 } | 1259 } |
| 1264 | 1260 |
| 1265 visitDummyReceiver(DummyReceiverConstant constant) { | |
| 1266 compiler.internalError( | |
| 1267 'DummyReceiverConstant should never be named and never be subconstant'); | |
| 1268 } | |
| 1269 | |
| 1270 int _hashString(int hash, String s) { | 1261 int _hashString(int hash, String s) { |
| 1271 int length = s.length; | 1262 int length = s.length; |
| 1272 hash = _combine(hash, length); | 1263 hash = _combine(hash, length); |
| 1273 // Increasing stride is O(log N) on large strings which are unlikely to have | 1264 // Increasing stride is O(log N) on large strings which are unlikely to have |
| 1274 // many collisions. | 1265 // many collisions. |
| 1275 for (int i = 0; i < length; i += 1 + (i >> 2)) { | 1266 for (int i = 0; i < length; i += 1 + (i >> 2)) { |
| 1276 hash = _combine(hash, s.codeUnitAt(i)); | 1267 hash = _combine(hash, s.codeUnitAt(i)); |
| 1277 } | 1268 } |
| 1278 return hash; | 1269 return hash; |
| 1279 } | 1270 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 if (!first) { | 1382 if (!first) { |
| 1392 sb.write('_'); | 1383 sb.write('_'); |
| 1393 } | 1384 } |
| 1394 sb.write('_'); | 1385 sb.write('_'); |
| 1395 visit(link.head); | 1386 visit(link.head); |
| 1396 first = true; | 1387 first = true; |
| 1397 } | 1388 } |
| 1398 } | 1389 } |
| 1399 } | 1390 } |
| 1400 } | 1391 } |
| OLD | NEW |