| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 _rtiEncoder = value; | 507 _rtiEncoder = value; |
| 508 } | 508 } |
| 509 | 509 |
| 510 /// Used disambiguated names in the global namespace, issued by | 510 /// Used disambiguated names in the global namespace, issued by |
| 511 /// [_disambiguateGlobal], and [_disambiguateInternalGlobal]. | 511 /// [_disambiguateGlobal], and [_disambiguateInternalGlobal]. |
| 512 /// | 512 /// |
| 513 /// Although global names are distributed across a number of global objects, | 513 /// Although global names are distributed across a number of global objects, |
| 514 /// (see [globalObjectFor]), we currently use a single namespace for all these | 514 /// (see [globalObjectFor]), we currently use a single namespace for all these |
| 515 /// names. | 515 /// names. |
| 516 final NamingScope globalScope = new NamingScope(); | 516 final NamingScope globalScope = new NamingScope(); |
| 517 final Map<Element, jsAst.Name> userGlobals = | 517 final Map<Entity, jsAst.Name> userGlobals = new HashMap<Entity, jsAst.Name>(); |
| 518 new HashMap<Element, jsAst.Name>(); | |
| 519 final Map<String, jsAst.Name> internalGlobals = | 518 final Map<String, jsAst.Name> internalGlobals = |
| 520 new HashMap<String, jsAst.Name>(); | 519 new HashMap<String, jsAst.Name>(); |
| 521 | 520 |
| 522 /// Used disambiguated names in the instance namespace, issued by | 521 /// Used disambiguated names in the instance namespace, issued by |
| 523 /// [_disambiguateMember], [_disambiguateInternalMember], | 522 /// [_disambiguateMember], [_disambiguateInternalMember], |
| 524 /// [_disambiguateOperator], and [reservePublicMemberName]. | 523 /// [_disambiguateOperator], and [reservePublicMemberName]. |
| 525 final NamingScope instanceScope = new NamingScope(); | 524 final NamingScope instanceScope = new NamingScope(); |
| 526 final Map<String, jsAst.Name> userInstanceMembers = | 525 final Map<String, jsAst.Name> userInstanceMembers = |
| 527 new HashMap<String, jsAst.Name>(); | 526 new HashMap<String, jsAst.Name>(); |
| 528 final Map<Element, jsAst.Name> internalInstanceMembers = | 527 final Map<Element, jsAst.Name> internalInstanceMembers = |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 jsAst.Name invocationMirrorInternalName(Selector selector) => | 859 jsAst.Name invocationMirrorInternalName(Selector selector) => |
| 861 invocationName(selector); | 860 invocationName(selector); |
| 862 | 861 |
| 863 /** | 862 /** |
| 864 * Returns the disambiguated name for the given field, used for constructing | 863 * Returns the disambiguated name for the given field, used for constructing |
| 865 * the getter and setter names. | 864 * the getter and setter names. |
| 866 */ | 865 */ |
| 867 jsAst.Name fieldAccessorName(FieldElement element) { | 866 jsAst.Name fieldAccessorName(FieldElement element) { |
| 868 return element.isInstanceMember | 867 return element.isInstanceMember |
| 869 ? _disambiguateMember(element.memberName) | 868 ? _disambiguateMember(element.memberName) |
| 870 : _disambiguateGlobal(element); | 869 : _disambiguateGlobalMember(element); |
| 871 } | 870 } |
| 872 | 871 |
| 873 /** | 872 /** |
| 874 * Returns name of the JavaScript property used to store a static or instance | 873 * Returns name of the JavaScript property used to store a static or instance |
| 875 * field. | 874 * field. |
| 876 */ | 875 */ |
| 877 jsAst.Name fieldPropertyName(FieldElement element) { | 876 jsAst.Name fieldPropertyName(FieldElement element) { |
| 878 return element.isInstanceMember | 877 return element.isInstanceMember |
| 879 ? instanceFieldPropertyName(element) | 878 ? instanceFieldPropertyName(element) |
| 880 : _disambiguateGlobal(element); | 879 : _disambiguateGlobalMember(element); |
| 881 } | 880 } |
| 882 | 881 |
| 883 /** | 882 /// Returns a JavaScript property name used to store the member [element] on |
| 884 * Returns a JavaScript property name used to store [element] on one | 883 /// one of the global objects. |
| 885 * of the global objects. | 884 /// |
| 886 * | 885 /// Should be used together with [globalObjectForMember], which denotes the |
| 887 * Should be used together with [globalObjectFor], which denotes the object | 886 /// object on which the returned property name should be used. |
| 888 * on which the returned property name should be used. | 887 jsAst.Name globalPropertyNameForMember(MemberEntity element) => |
| 889 */ | 888 _disambiguateGlobalMember(element); |
| 890 jsAst.Name globalPropertyName(Element element) { | 889 |
| 891 return _disambiguateGlobal(element); | 890 /// Returns a JavaScript property name used to store the class [element] on |
| 892 } | 891 /// one of the global objects. |
| 892 /// |
| 893 /// Should be used together with [globalObjectForClass], which denotes the |
| 894 /// object on which the returned property name should be used. |
| 895 jsAst.Name globalPropertyNameForClass(ClassEntity element) => |
| 896 _disambiguateGlobalType(element); |
| 897 |
| 898 /// Returns a JavaScript property name used to store the type (typedef) |
| 899 /// [element] on one of the global objects. |
| 900 /// |
| 901 /// Should be used together with [globalObjectForType], which denotes the |
| 902 /// object on which the returned property name should be used. |
| 903 jsAst.Name globalPropertyNameForType(TypeDeclarationElement element) => |
| 904 _disambiguateGlobalType(element); |
| 893 | 905 |
| 894 /** | 906 /** |
| 895 * Returns the JavaScript property name used to store an instance field. | 907 * Returns the JavaScript property name used to store an instance field. |
| 896 */ | 908 */ |
| 897 jsAst.Name instanceFieldPropertyName(FieldElement element) { | 909 jsAst.Name instanceFieldPropertyName(FieldElement element) { |
| 898 ClassElement enclosingClass = element.enclosingClass; | 910 ClassElement enclosingClass = element.enclosingClass; |
| 899 | 911 |
| 900 if (_nativeData.hasFixedBackendName(element)) { | 912 if (_nativeData.hasFixedBackendName(element)) { |
| 901 return new StringBackedName(_nativeData.getFixedBackendName(element)); | 913 return new StringBackedName(_nativeData.getFixedBackendName(element)); |
| 902 } | 914 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 String keyBase = library.name; | 1028 String keyBase = library.name; |
| 1017 int counter = 0; | 1029 int counter = 0; |
| 1018 String key = keyBase; | 1030 String key = keyBase; |
| 1019 while (_libraryKeys.values.contains(key)) { | 1031 while (_libraryKeys.values.contains(key)) { |
| 1020 key = "$keyBase${counter++}"; | 1032 key = "$keyBase${counter++}"; |
| 1021 } | 1033 } |
| 1022 return key; | 1034 return key; |
| 1023 }); | 1035 }); |
| 1024 } | 1036 } |
| 1025 | 1037 |
| 1038 jsAst.Name _disambiguateGlobalMember(MemberEntity element) { |
| 1039 return _disambiguateGlobal(element, _proposeNameForMember); |
| 1040 } |
| 1041 |
| 1042 jsAst.Name _disambiguateGlobalType(Entity element) { |
| 1043 return _disambiguateGlobal(element, _proposeNameForType); |
| 1044 } |
| 1045 |
| 1026 /// Returns the disambiguated name for a top-level or static element. | 1046 /// Returns the disambiguated name for a top-level or static element. |
| 1027 /// | 1047 /// |
| 1028 /// The resulting name is unique within the global-member namespace. | 1048 /// The resulting name is unique within the global-member namespace. |
| 1029 jsAst.Name _disambiguateGlobal(Element element) { | 1049 jsAst.Name _disambiguateGlobal( |
| 1050 Entity element, String proposeName(Entity element)) { |
| 1030 // TODO(asgerf): We can reuse more short names if we disambiguate with | 1051 // TODO(asgerf): We can reuse more short names if we disambiguate with |
| 1031 // a separate namespace for each of the global holder objects. | 1052 // a separate namespace for each of the global holder objects. |
| 1032 element = element.declaration; | 1053 if (element is Element) { |
| 1054 // Ensures we only work on declarations. Non-[Element] entities do not |
| 1055 // have the declaration/implementation separation. |
| 1056 Element e = element; |
| 1057 element = e.declaration; |
| 1058 } |
| 1033 jsAst.Name newName = userGlobals[element]; | 1059 jsAst.Name newName = userGlobals[element]; |
| 1034 if (newName == null) { | 1060 if (newName == null) { |
| 1035 String proposedName = _proposeNameForGlobal(element); | 1061 String proposedName = proposeName(element); |
| 1036 newName = getFreshName(globalScope, proposedName); | 1062 newName = getFreshName(globalScope, proposedName); |
| 1037 userGlobals[element] = newName; | 1063 userGlobals[element] = newName; |
| 1038 } | 1064 } |
| 1039 return _newReference(newName); | 1065 return _newReference(newName); |
| 1040 } | 1066 } |
| 1041 | 1067 |
| 1042 /// Returns the disambiguated name for an instance method or field | 1068 /// Returns the disambiguated name for an instance method or field |
| 1043 /// with [originalName] in [library]. | 1069 /// with [originalName] in [library]. |
| 1044 /// | 1070 /// |
| 1045 /// [library] may be `null` if [originalName] is known to be public. | 1071 /// [library] may be `null` if [originalName] is known to be public. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 /// If [name] is not an annotated name, the result will not be an annotated | 1266 /// If [name] is not an annotated name, the result will not be an annotated |
| 1241 /// name either. | 1267 /// name either. |
| 1242 String _sanitizeForNatives(String name) { | 1268 String _sanitizeForNatives(String name) { |
| 1243 if (!name.contains(r'$')) { | 1269 if (!name.contains(r'$')) { |
| 1244 // Prepend $$. The result must not coincide with an annotated name. | 1270 // Prepend $$. The result must not coincide with an annotated name. |
| 1245 name = '\$\$$name'; | 1271 name = '\$\$$name'; |
| 1246 } | 1272 } |
| 1247 return name; | 1273 return name; |
| 1248 } | 1274 } |
| 1249 | 1275 |
| 1250 /** | 1276 /// Returns a proposed name for the given typedef or class [element]. |
| 1251 * Returns a proposed name for the given top-level or static element. | 1277 /// The returned id is guaranteed to be a valid JavaScript identifier. |
| 1252 * The returned id is guaranteed to be a valid JavaScript identifier. | 1278 String _proposeNameForType(Entity element) { |
| 1253 */ | 1279 return element.name.replaceAll('+', '_'); |
| 1254 String _proposeNameForGlobal(Element element) { | 1280 } |
| 1255 assert(!element.isInstanceMember); | 1281 |
| 1282 /// Returns a proposed name for the given top-level or static member |
| 1283 /// [element]. The returned id is guaranteed to be a valid JavaScript |
| 1284 /// identifier. |
| 1285 String _proposeNameForMember(MemberEntity element) { |
| 1286 if (element.isConstructor) { |
| 1287 return _proposeNameForConstructor(element); |
| 1288 } else if (element.enclosingClass != null) { |
| 1289 ClassEntity enclosingClass = element.enclosingClass; |
| 1290 return '${enclosingClass.name}_${element.name}'; |
| 1291 } |
| 1292 return element.name.replaceAll('+', '_'); |
| 1293 } |
| 1294 |
| 1295 String _proposeNameForConstructor(ConstructorEntity element) { |
| 1296 String className = element.enclosingClass.name; |
| 1256 if (element.isGenerativeConstructor) { | 1297 if (element.isGenerativeConstructor) { |
| 1257 return '${element.enclosingClass.name}\$${element.name}'; | 1298 return '${className}\$${element.name}'; |
| 1258 } | 1299 } else { |
| 1259 if (element.isFactoryConstructor) { | |
| 1260 // TODO(johnniwinther): Change factory name encoding as to not include | 1300 // TODO(johnniwinther): Change factory name encoding as to not include |
| 1261 // the class-name twice. | 1301 // the class-name twice. |
| 1262 String className = element.enclosingClass.name; | 1302 String constructorName; |
| 1263 return '${className}_${Elements.reconstructConstructorName(element)}'; | 1303 if (element.name == '') { |
| 1304 constructorName = className; |
| 1305 } else { |
| 1306 constructorName = '${className}\$${element.name}'; |
| 1307 } |
| 1308 return '${className}_${constructorName}'; |
| 1264 } | 1309 } |
| 1265 if (Elements.isStaticOrTopLevel(element)) { | |
| 1266 if (element.isClassMember) { | |
| 1267 ClassElement enclosingClass = element.enclosingClass; | |
| 1268 return '${enclosingClass.name}_${element.name}'; | |
| 1269 } | |
| 1270 return element.name.replaceAll('+', '_'); | |
| 1271 } | |
| 1272 if (element.isLibrary) { | |
| 1273 LibraryElement library = element; | |
| 1274 return _proposeNameForLibrary(library); | |
| 1275 } | |
| 1276 return element.name; | |
| 1277 } | 1310 } |
| 1278 | 1311 |
| 1279 /** | 1312 /** |
| 1280 * Returns a proposed name for the given [LibraryElement]. | 1313 * Returns a proposed name for the given [LibraryElement]. |
| 1281 * The returned id is guaranteed to be a valid JavaScript identifier. | 1314 * The returned id is guaranteed to be a valid JavaScript identifier. |
| 1282 */ | 1315 */ |
| 1283 // TODO(sra): Pre-process libraries to assign [libraryLongNames] in a way that | 1316 // TODO(sra): Pre-process libraries to assign [libraryLongNames] in a way that |
| 1284 // is independent of the order of calls to namer. | 1317 // is independent of the order of calls to namer. |
| 1285 String _proposeNameForLibrary(LibraryEntity library) { | 1318 String _proposeNameForLibrary(LibraryEntity library) { |
| 1286 String name = libraryLongNames[library]; | 1319 String name = libraryLongNames[library]; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 /// Property name used for `getInterceptor` or one of its specializations. | 1382 /// Property name used for `getInterceptor` or one of its specializations. |
| 1350 jsAst.Name nameForGetInterceptor(Iterable<ClassEntity> classes) { | 1383 jsAst.Name nameForGetInterceptor(Iterable<ClassEntity> classes) { |
| 1351 MethodElement getInterceptor = _commonElements.getInterceptorMethod; | 1384 MethodElement getInterceptor = _commonElements.getInterceptorMethod; |
| 1352 if (classes.contains(_commonElements.jsInterceptorClass)) { | 1385 if (classes.contains(_commonElements.jsInterceptorClass)) { |
| 1353 // If the base Interceptor class is in the set of intercepted classes, we | 1386 // If the base Interceptor class is in the set of intercepted classes, we |
| 1354 // need to go through the generic getInterceptorMethod, since any subclass | 1387 // need to go through the generic getInterceptorMethod, since any subclass |
| 1355 // of the base Interceptor could match. | 1388 // of the base Interceptor could match. |
| 1356 // The unspecialized getInterceptor method can also be accessed through | 1389 // The unspecialized getInterceptor method can also be accessed through |
| 1357 // its element, so we treat this as a user-space global instead of an | 1390 // its element, so we treat this as a user-space global instead of an |
| 1358 // internal global. | 1391 // internal global. |
| 1359 return _disambiguateGlobal(getInterceptor); | 1392 return _disambiguateGlobalMember(getInterceptor); |
| 1360 } | 1393 } |
| 1361 String suffix = suffixForGetInterceptor(classes); | 1394 String suffix = suffixForGetInterceptor(classes); |
| 1362 return _disambiguateInternalGlobal("${getInterceptor.name}\$$suffix"); | 1395 return _disambiguateInternalGlobal("${getInterceptor.name}\$$suffix"); |
| 1363 } | 1396 } |
| 1364 | 1397 |
| 1365 /// Property name used for the one-shot interceptor method for the given | 1398 /// Property name used for the one-shot interceptor method for the given |
| 1366 /// [selector] and return-type specialization. | 1399 /// [selector] and return-type specialization. |
| 1367 jsAst.Name nameForGetOneShotInterceptor( | 1400 jsAst.Name nameForGetOneShotInterceptor( |
| 1368 Selector selector, Iterable<ClassEntity> classes) { | 1401 Selector selector, Iterable<ClassEntity> classes) { |
| 1369 // The one-shot name is a global name derived from the invocation name. To | 1402 // The one-shot name is a global name derived from the invocation name. To |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1400 // | 1433 // |
| 1401 // - If given a class, this must coincide with the class name, which | 1434 // - If given a class, this must coincide with the class name, which |
| 1402 // is also the GLOBAL property name of its constructor. | 1435 // is also the GLOBAL property name of its constructor. |
| 1403 // | 1436 // |
| 1404 // - The result is used to derive `$isX` and `$asX` names, which are used | 1437 // - The result is used to derive `$isX` and `$asX` names, which are used |
| 1405 // as INSTANCE property names. | 1438 // as INSTANCE property names. |
| 1406 // | 1439 // |
| 1407 // To prevent clashes in both namespaces at once, we disambiguate the name | 1440 // To prevent clashes in both namespaces at once, we disambiguate the name |
| 1408 // as a global here, and in [_sanitizeForAnnotations] we ensure that | 1441 // as a global here, and in [_sanitizeForAnnotations] we ensure that |
| 1409 // ordinary instance members cannot start with `$is` or `$as`. | 1442 // ordinary instance members cannot start with `$is` or `$as`. |
| 1410 return _disambiguateGlobal(element); | 1443 return _disambiguateGlobalType(element); |
| 1411 } | 1444 } |
| 1412 | 1445 |
| 1413 /// Returns the disambiguated name of [class_]. | 1446 /// Returns the disambiguated name of [class_]. |
| 1414 /// | 1447 /// |
| 1415 /// This is both the *runtime type* of the class (see [runtimeTypeName]) | 1448 /// This is both the *runtime type* of the class (see [runtimeTypeName]) |
| 1416 /// and a global property name in which to store its JS constructor. | 1449 /// and a global property name in which to store its JS constructor. |
| 1417 jsAst.Name className(ClassElement class_) => _disambiguateGlobal(class_); | 1450 jsAst.Name className(ClassElement class_) => _disambiguateGlobalType(class_); |
| 1418 | 1451 |
| 1419 /// Property name on which [member] can be accessed directly, | 1452 /// Property name on which [member] can be accessed directly, |
| 1420 /// without clashing with another JS property name. | 1453 /// without clashing with another JS property name. |
| 1421 /// | 1454 /// |
| 1422 /// This is used for implementing super-calls, where ordinary dispatch | 1455 /// This is used for implementing super-calls, where ordinary dispatch |
| 1423 /// semantics must be circumvented. For example: | 1456 /// semantics must be circumvented. For example: |
| 1424 /// | 1457 /// |
| 1425 /// class A { foo() } | 1458 /// class A { foo() } |
| 1426 /// class B extends A { | 1459 /// class B extends A { |
| 1427 /// foo() { super.foo() } | 1460 /// foo() { super.foo() } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1443 return "super\$${member.enclosingClass.name}\$$invocationName"; | 1476 return "super\$${member.enclosingClass.name}\$$invocationName"; |
| 1444 }); | 1477 }); |
| 1445 } | 1478 } |
| 1446 | 1479 |
| 1447 /// Property name in which to store the given static or instance [method]. | 1480 /// Property name in which to store the given static or instance [method]. |
| 1448 /// For instance methods, this includes the suffix encoding arity and named | 1481 /// For instance methods, this includes the suffix encoding arity and named |
| 1449 /// parameters. | 1482 /// parameters. |
| 1450 /// | 1483 /// |
| 1451 /// The name is not necessarily unique to [method], since a static method | 1484 /// The name is not necessarily unique to [method], since a static method |
| 1452 /// may share its name with an instance method. | 1485 /// may share its name with an instance method. |
| 1453 jsAst.Name methodPropertyName(Element method) { | 1486 jsAst.Name methodPropertyName(MethodElement method) { |
| 1454 return method.isInstanceMember | 1487 return method.isInstanceMember |
| 1455 ? instanceMethodName(method) | 1488 ? instanceMethodName(method) |
| 1456 : globalPropertyName(method); | 1489 : globalPropertyNameForMember(method); |
| 1457 } | 1490 } |
| 1458 | 1491 |
| 1459 /// Returns true if [element] is stored in the static state holder | 1492 /// Returns true if [element] is stored in the static state holder |
| 1460 /// ([staticStateHolder]). We intend to store only mutable static state | 1493 /// ([staticStateHolder]). We intend to store only mutable static state |
| 1461 /// there, whereas constants are stored in 'C'. Functions, accessors, | 1494 /// there, whereas constants are stored in 'C'. Functions, accessors, |
| 1462 /// classes, etc. are stored in one of the other objects in | 1495 /// classes, etc. are stored in one of the other objects in |
| 1463 /// [reservedGlobalObjectNames]. | 1496 /// [reservedGlobalObjectNames]. |
| 1464 bool _isPropertyOfStaticStateHolder(Element element) { | 1497 bool _isPropertyOfStaticStateHolder(MemberEntity element) { |
| 1465 // TODO(ahe): Make sure this method's documentation is always true and | 1498 // TODO(ahe): Make sure this method's documentation is always true and |
| 1466 // remove the word "intend". | 1499 // remove the word "intend". |
| 1467 return | 1500 if (element is MemberElement) { |
| 1468 // TODO(ahe): Re-write these tests to be positive (so it only returns | 1501 // TODO(johnniwinther): Clean up this method to have a single semantics on |
| 1469 // true for static/top-level mutable fields). Right now, a number of | 1502 // entities. |
| 1470 // other elements, such as bound closures also live in | 1503 return |
| 1471 // [staticStateHolder]. | 1504 // TODO(ahe): Re-write these tests to be positive (so it only returns |
| 1472 !element.isAccessor && | 1505 // true for static/top-level mutable fields). Right now, a number of |
| 1473 !element.isClass && | 1506 // other elements, such as bound closures also live in |
| 1474 !element.isTypedef && | 1507 // [staticStateHolder]. |
| 1475 !element.isConstructor && | 1508 !element.isAccessor && |
| 1476 !element.isFunction && | 1509 !element.isClass && |
| 1477 !element.isLibrary; | 1510 !element.isTypedef && |
| 1511 !element.isConstructor && |
| 1512 !element.isFunction && |
| 1513 !element.isLibrary; |
| 1514 } |
| 1515 return element.isField; |
| 1478 } | 1516 } |
| 1479 | 1517 |
| 1480 /// Returns [staticStateHolder] or one of [reservedGlobalObjectNames]. | 1518 /// Returns [staticStateHolder] or one of [reservedGlobalObjectNames]. |
| 1481 // TODO(johnniwinther): Verify that the implementation can be changed to | 1519 // TODO(johnniwinther): Verify that the implementation can be changed to |
| 1482 // `globalObjectForLibrary(element.library)`. | 1520 // `globalObjectForLibrary(element.library)`. |
| 1483 String globalObjectForMethod(MethodElement element) => | 1521 String globalObjectForMethod(MethodElement element) => |
| 1484 globalObjectFor(element); | 1522 globalObjectForMember(element); |
| 1485 | 1523 |
| 1486 /// Returns [staticStateHolder] or one of [reservedGlobalObjectNames]. | 1524 /// Returns [staticStateHolder] or one of [reservedGlobalObjectNames]. |
| 1487 String globalObjectFor(Element element) { | 1525 String globalObjectForMember(MemberEntity element) { |
| 1488 if (_isPropertyOfStaticStateHolder(element)) return staticStateHolder; | 1526 if (_isPropertyOfStaticStateHolder(element)) return staticStateHolder; |
| 1489 return globalObjectForLibrary(element.library); | 1527 return globalObjectForLibrary(element.library); |
| 1490 } | 1528 } |
| 1491 | 1529 |
| 1530 String globalObjectForClass(ClassEntity element) { |
| 1531 return globalObjectForLibrary(element.library); |
| 1532 } |
| 1533 |
| 1534 String globalObjectForType(Entity element) { |
| 1535 if (element is TypedefElement) { |
| 1536 return globalObjectForLibrary(element.library); |
| 1537 } |
| 1538 return globalObjectForClass(element); |
| 1539 } |
| 1540 |
| 1492 /// Returns the [reservedGlobalObjectNames] for [library]. | 1541 /// Returns the [reservedGlobalObjectNames] for [library]. |
| 1493 String globalObjectForLibrary(LibraryElement library) { | 1542 String globalObjectForLibrary(LibraryEntity library) { |
| 1494 if (library == _commonElements.interceptorsLibrary) return 'J'; | 1543 if (library == _commonElements.interceptorsLibrary) return 'J'; |
| 1495 if (library.isInternalLibrary) return 'H'; | 1544 Uri uri = library.canonicalUri; |
| 1496 if (library.isPlatformLibrary) { | 1545 if (uri.scheme == 'dart') { |
| 1497 if ('${library.canonicalUri}' == 'dart:html') return 'W'; | 1546 if (uri.path == 'html') return 'W'; |
| 1547 if (uri.path.startsWith('_')) return 'H'; |
| 1498 return 'P'; | 1548 return 'P'; |
| 1499 } | 1549 } |
| 1500 return userGlobalObjects[library.name.hashCode % userGlobalObjects.length]; | 1550 return userGlobalObjects[library.name.hashCode % userGlobalObjects.length]; |
| 1501 } | 1551 } |
| 1502 | 1552 |
| 1503 jsAst.Name deriveLazyInitializerName(jsAst.Name name) { | 1553 jsAst.Name deriveLazyInitializerName(jsAst.Name name) { |
| 1504 // These are not real dart getters, so do not use GetterName; | 1554 // These are not real dart getters, so do not use GetterName; |
| 1505 return new CompoundName([_literalLazyGetterPrefix, name]); | 1555 return new CompoundName([_literalLazyGetterPrefix, name]); |
| 1506 } | 1556 } |
| 1507 | 1557 |
| 1508 jsAst.Name lazyInitializerName(Element element) { | 1558 jsAst.Name lazyInitializerName(FieldEntity element) { |
| 1509 assert(Elements.isStaticOrTopLevelField(element)); | 1559 assert(element.isTopLevel || element.isStatic); |
| 1510 jsAst.Name name = _disambiguateGlobal(element); | 1560 jsAst.Name name = _disambiguateGlobalMember(element); |
| 1511 // These are not real dart getters, so do not use GetterName; | 1561 // These are not real dart getters, so do not use GetterName; |
| 1512 return deriveLazyInitializerName(name); | 1562 return deriveLazyInitializerName(name); |
| 1513 } | 1563 } |
| 1514 | 1564 |
| 1515 jsAst.Name staticClosureName(Element element) { | 1565 jsAst.Name staticClosureName(Element element) { |
| 1516 assert(Elements.isStaticOrTopLevelFunction(element)); | 1566 assert(Elements.isStaticOrTopLevelFunction(element)); |
| 1517 String enclosing = | 1567 String enclosing = |
| 1518 element.enclosingClass == null ? "" : element.enclosingClass.name; | 1568 element.enclosingClass == null ? "" : element.enclosingClass.name; |
| 1519 String library = _proposeNameForLibrary(element.library); | 1569 String library = _proposeNameForLibrary(element.library); |
| 1520 return _disambiguateInternalGlobal( | 1570 return _disambiguateInternalGlobal( |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2189 void addSuggestion(String original, String suggestion) { | 2239 void addSuggestion(String original, String suggestion) { |
| 2190 assert(!_suggestedNames.containsKey(original)); | 2240 assert(!_suggestedNames.containsKey(original)); |
| 2191 _suggestedNames[original] = suggestion; | 2241 _suggestedNames[original] = suggestion; |
| 2192 } | 2242 } |
| 2193 | 2243 |
| 2194 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2244 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2195 bool isSuggestion(String candidate) { | 2245 bool isSuggestion(String candidate) { |
| 2196 return _suggestedNames.containsValue(candidate); | 2246 return _suggestedNames.containsValue(candidate); |
| 2197 } | 2247 } |
| 2198 } | 2248 } |
| OLD | NEW |