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 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 JavaScriptBackend backend = compiler.backend; | 1182 JavaScriptBackend backend = compiler.backend; |
1183 String name = backend.rti.getRawTypeRepresentation(type); | 1183 String name = backend.rti.getRawTypeRepresentation(type); |
1184 addIdentifier(name); | 1184 addIdentifier(name); |
1185 } | 1185 } |
1186 | 1186 |
1187 visitInterceptor(InterceptorConstant constant) { | 1187 visitInterceptor(InterceptorConstant constant) { |
1188 addRoot(constant.dispatchedType.element.name); | 1188 addRoot(constant.dispatchedType.element.name); |
1189 add('methods'); | 1189 add('methods'); |
1190 } | 1190 } |
1191 | 1191 |
1192 visitDummyReceiver(DummyReceiverConstant constant) { | 1192 visitDummy(DummyConstant constant) { |
1193 add('dummy_receiver'); | 1193 add('dummy_receiver'); |
1194 } | 1194 } |
1195 } | 1195 } |
1196 | 1196 |
1197 /** | 1197 /** |
1198 * Generates canonical hash values for [Constant]s. | 1198 * Generates canonical hash values for [Constant]s. |
1199 * | 1199 * |
1200 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, | 1200 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, |
1201 * so it can't be used for generating names. This hasher keeps consistency | 1201 * so it can't be used for generating names. This hasher keeps consistency |
1202 * between runs by basing hash values of the names of elements, rather than | 1202 * between runs by basing hash values of the names of elements, rather than |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 JavaScriptBackend backend = compiler.backend; | 1262 JavaScriptBackend backend = compiler.backend; |
1263 String name = backend.rti.getRawTypeRepresentation(type); | 1263 String name = backend.rti.getRawTypeRepresentation(type); |
1264 return _hashString(4, name); | 1264 return _hashString(4, name); |
1265 } | 1265 } |
1266 | 1266 |
1267 visitInterceptor(InterceptorConstant constant) { | 1267 visitInterceptor(InterceptorConstant constant) { |
1268 String typeName = constant.dispatchedType.element.name; | 1268 String typeName = constant.dispatchedType.element.name; |
1269 return _hashString(5, typeName); | 1269 return _hashString(5, typeName); |
1270 } | 1270 } |
1271 | 1271 |
1272 visitDummyReceiver(DummyReceiverConstant constant) { | 1272 visitDummy(DummyConstant constant) { |
1273 compiler.internalError( | 1273 compiler.internalError( |
1274 'DummyReceiverConstant should never be named and never be subconstant'); | 1274 'DummyReceiverConstant should never be named and never be subconstant'); |
1275 } | 1275 } |
1276 | 1276 |
1277 int _hashString(int hash, String s) { | 1277 int _hashString(int hash, String s) { |
1278 int length = s.length; | 1278 int length = s.length; |
1279 hash = _combine(hash, length); | 1279 hash = _combine(hash, length); |
1280 // Increasing stride is O(log N) on large strings which are unlikely to have | 1280 // Increasing stride is O(log N) on large strings which are unlikely to have |
1281 // many collisions. | 1281 // many collisions. |
1282 for (int i = 0; i < length; i += 1 + (i >> 2)) { | 1282 for (int i = 0; i < length; i += 1 + (i >> 2)) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 if (!first) { | 1398 if (!first) { |
1399 sb.write('_'); | 1399 sb.write('_'); |
1400 } | 1400 } |
1401 sb.write('_'); | 1401 sb.write('_'); |
1402 visit(link.head); | 1402 visit(link.head); |
1403 first = true; | 1403 first = true; |
1404 } | 1404 } |
1405 } | 1405 } |
1406 } | 1406 } |
1407 } | 1407 } |
OLD | NEW |