| 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 library js_backend.namer; | 5 library js_backend.namer; |
| 6 | 6 |
| 7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; | 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; |
| 10 | 10 |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 return '$name\$${suffix.join(r'$')}'; | 660 return '$name\$${suffix.join(r'$')}'; |
| 661 } | 661 } |
| 662 | 662 |
| 663 /// Name for a constructor body. | 663 /// Name for a constructor body. |
| 664 jsAst.Name constructorBodyName(FunctionElement ctor) { | 664 jsAst.Name constructorBodyName(FunctionElement ctor) { |
| 665 return _disambiguateInternalMember( | 665 return _disambiguateInternalMember( |
| 666 ctor, () => _proposeNameForConstructorBody(ctor)); | 666 ctor, () => _proposeNameForConstructorBody(ctor)); |
| 667 } | 667 } |
| 668 | 668 |
| 669 /// Annotated name for [method] encoding arity and named parameters. | 669 /// Annotated name for [method] encoding arity and named parameters. |
| 670 jsAst.Name instanceMethodName(FunctionElement method) { | 670 jsAst.Name instanceMethodName(MethodElement method) { |
| 671 if (method.isGenerativeConstructorBody) { | 671 if (method.isGenerativeConstructorBody) { |
| 672 return constructorBodyName(method); | 672 return constructorBodyName(method); |
| 673 } | 673 } |
| 674 return invocationName(new Selector.fromElement(method)); | 674 return invocationName(new Selector.fromElement(method)); |
| 675 } | 675 } |
| 676 | 676 |
| 677 String _jsNameHelper(Element e) { | 677 String _jsNameHelper(Element e) { |
| 678 String jsInteropName = backend.nativeData.getJsInteropName(e); | 678 String jsInteropName = backend.nativeData.getJsInteropName(e); |
| 679 if (jsInteropName != null && jsInteropName.isNotEmpty) return jsInteropName; | 679 if (jsInteropName != null && jsInteropName.isNotEmpty) return jsInteropName; |
| 680 return e.isLibrary | 680 return e.isLibrary |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 // However, as names from the same libary should have the same library | 1243 // However, as names from the same libary should have the same library |
| 1244 // name part, we disambiguate the library name here. | 1244 // name part, we disambiguate the library name here. |
| 1245 String disambiguated = name; | 1245 String disambiguated = name; |
| 1246 for (int c = 0; libraryLongNames.containsValue(disambiguated); c++) { | 1246 for (int c = 0; libraryLongNames.containsValue(disambiguated); c++) { |
| 1247 disambiguated = "$name$c"; | 1247 disambiguated = "$name$c"; |
| 1248 } | 1248 } |
| 1249 libraryLongNames[library] = disambiguated; | 1249 libraryLongNames[library] = disambiguated; |
| 1250 return disambiguated; | 1250 return disambiguated; |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 String suffixForGetInterceptor(Iterable<ClassElement> classes) { | 1253 String suffixForGetInterceptor(Iterable<ClassLike> classes) { |
| 1254 String abbreviate(ClassElement cls) { | 1254 String abbreviate(ClassElement cls) { |
| 1255 if (cls == coreClasses.objectClass) return "o"; | 1255 if (cls == coreClasses.objectClass) return "o"; |
| 1256 if (cls == helpers.jsStringClass) return "s"; | 1256 if (cls == helpers.jsStringClass) return "s"; |
| 1257 if (cls == helpers.jsArrayClass) return "a"; | 1257 if (cls == helpers.jsArrayClass) return "a"; |
| 1258 if (cls == helpers.jsDoubleClass) return "d"; | 1258 if (cls == helpers.jsDoubleClass) return "d"; |
| 1259 if (cls == helpers.jsIntClass) return "i"; | 1259 if (cls == helpers.jsIntClass) return "i"; |
| 1260 if (cls == helpers.jsNumberClass) return "n"; | 1260 if (cls == helpers.jsNumberClass) return "n"; |
| 1261 if (cls == helpers.jsNullClass) return "u"; | 1261 if (cls == helpers.jsNullClass) return "u"; |
| 1262 if (cls == helpers.jsBoolClass) return "b"; | 1262 if (cls == helpers.jsBoolClass) return "b"; |
| 1263 if (cls == helpers.jsInterceptorClass) return "I"; | 1263 if (cls == helpers.jsInterceptorClass) return "I"; |
| 1264 return cls.name; | 1264 return cls.name; |
| 1265 } | 1265 } |
| 1266 | 1266 |
| 1267 List<String> names = classes | 1267 List<String> names = classes |
| 1268 .where((cls) => !backend.isNativeOrExtendsNative(cls)) | 1268 .where((cls) => !backend.isNativeOrExtendsNative(cls)) |
| 1269 .map(abbreviate) | 1269 .map(abbreviate) |
| 1270 .toList(); | 1270 .toList(); |
| 1271 // There is one dispatch mechanism for all native classes. | 1271 // There is one dispatch mechanism for all native classes. |
| 1272 if (classes.any((cls) => backend.isNativeOrExtendsNative(cls))) { | 1272 if (classes.any((cls) => backend.isNativeOrExtendsNative(cls))) { |
| 1273 names.add("x"); | 1273 names.add("x"); |
| 1274 } | 1274 } |
| 1275 // Sort the names of the classes after abbreviating them to ensure | 1275 // Sort the names of the classes after abbreviating them to ensure |
| 1276 // the suffix is stable and predictable for the suggested names. | 1276 // the suffix is stable and predictable for the suggested names. |
| 1277 names.sort(); | 1277 names.sort(); |
| 1278 return names.join(); | 1278 return names.join(); |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 /// Property name used for `getInterceptor` or one of its specializations. | 1281 /// Property name used for `getInterceptor` or one of its specializations. |
| 1282 jsAst.Name nameForGetInterceptor(Iterable<ClassElement> classes) { | 1282 jsAst.Name nameForGetInterceptor(Iterable<ClassLike> classes) { |
| 1283 FunctionElement getInterceptor = helpers.getInterceptorMethod; | 1283 FunctionElement getInterceptor = helpers.getInterceptorMethod; |
| 1284 if (classes.contains(helpers.jsInterceptorClass)) { | 1284 if (classes.contains(helpers.jsInterceptorClass)) { |
| 1285 // If the base Interceptor class is in the set of intercepted classes, we | 1285 // If the base Interceptor class is in the set of intercepted classes, we |
| 1286 // need to go through the generic getInterceptorMethod, since any subclass | 1286 // need to go through the generic getInterceptorMethod, since any subclass |
| 1287 // of the base Interceptor could match. | 1287 // of the base Interceptor could match. |
| 1288 // The unspecialized getInterceptor method can also be accessed through | 1288 // The unspecialized getInterceptor method can also be accessed through |
| 1289 // its element, so we treat this as a user-space global instead of an | 1289 // its element, so we treat this as a user-space global instead of an |
| 1290 // internal global. | 1290 // internal global. |
| 1291 return _disambiguateGlobal(getInterceptor); | 1291 return _disambiguateGlobal(getInterceptor); |
| 1292 } | 1292 } |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2100 void addSuggestion(String original, String suggestion) { | 2100 void addSuggestion(String original, String suggestion) { |
| 2101 assert(!_suggestedNames.containsKey(original)); | 2101 assert(!_suggestedNames.containsKey(original)); |
| 2102 _suggestedNames[original] = suggestion; | 2102 _suggestedNames[original] = suggestion; |
| 2103 } | 2103 } |
| 2104 | 2104 |
| 2105 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2105 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2106 bool isSuggestion(String candidate) { | 2106 bool isSuggestion(String candidate) { |
| 2107 return _suggestedNames.containsValue(candidate); | 2107 return _suggestedNames.containsValue(candidate); |
| 2108 } | 2108 } |
| 2109 } | 2109 } |
| OLD | NEW |