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 * Names are generated through three stages: | 10 * Names are generated through three stages: |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 return new StringBackedName(backend.getFixedBackendName(element)); | 778 return new StringBackedName(backend.getFixedBackendName(element)); |
779 } | 779 } |
780 | 780 |
781 // Some elements, like e.g. instances of BoxFieldElement are special. | 781 // Some elements, like e.g. instances of BoxFieldElement are special. |
782 // They are created with a unique and safe name for the element model. | 782 // They are created with a unique and safe name for the element model. |
783 // While their name is unique, it is not very readable. So we try to | 783 // While their name is unique, it is not very readable. So we try to |
784 // preserve the original, proposed name. | 784 // preserve the original, proposed name. |
785 // However, as boxes are not really instances of classes, the usual naming | 785 // However, as boxes are not really instances of classes, the usual naming |
786 // scheme that tries to avoid name clashes with super classes does not | 786 // scheme that tries to avoid name clashes with super classes does not |
787 // apply. So we can directly grab a name. | 787 // apply. So we can directly grab a name. |
788 if (element is JSEntity) { | 788 Entity asEntity = element; |
| 789 if (asEntity is JSEntity) { |
789 return _disambiguateInternalMember(element, | 790 return _disambiguateInternalMember(element, |
790 () => element.declaredEntity.name); | 791 () => asEntity.declaredEntity.name); |
791 } | 792 } |
792 | 793 |
793 // If the name of the field might clash with another field, | 794 // If the name of the field might clash with another field, |
794 // use a mangled field name to avoid potential clashes. | 795 // use a mangled field name to avoid potential clashes. |
795 // Note that if the class extends a native class, that native class might | 796 // Note that if the class extends a native class, that native class might |
796 // have fields with fixed backend names, so we assume the worst and always | 797 // have fields with fixed backend names, so we assume the worst and always |
797 // mangle the field names of classes extending native classes. | 798 // mangle the field names of classes extending native classes. |
798 // Methods on such classes are stored on the interceptor, not the instance, | 799 // Methods on such classes are stored on the interceptor, not the instance, |
799 // so only fields have the potential to clash with a native property name. | 800 // so only fields have the potential to clash with a native property name. |
800 ClassWorld classWorld = compiler.world; | 801 ClassWorld classWorld = compiler.world; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 /// This is used as the property name for fields, type variables, | 1006 /// This is used as the property name for fields, type variables, |
1006 /// constructor bodies, and super-accessors. | 1007 /// constructor bodies, and super-accessors. |
1007 /// | 1008 /// |
1008 /// The resulting name is unique within the instance-member namespace. | 1009 /// The resulting name is unique within the instance-member namespace. |
1009 jsAst.Name _disambiguateInternalMember(Element element, | 1010 jsAst.Name _disambiguateInternalMember(Element element, |
1010 String proposeName()) { | 1011 String proposeName()) { |
1011 jsAst.Name newName = internalInstanceMembers[element]; | 1012 jsAst.Name newName = internalInstanceMembers[element]; |
1012 if (newName == null) { | 1013 if (newName == null) { |
1013 String name = proposeName(); | 1014 String name = proposeName(); |
1014 | 1015 |
1015 if (element is PrivatelyNamedJSEntity) { | 1016 Entity asEntity = element; |
1016 NamingScope scope = _getPrivateScopeFor(element); | 1017 if (asEntity is PrivatelyNamedJSEntity) { |
| 1018 NamingScope scope = _getPrivateScopeFor(asEntity); |
1017 newName = getFreshName(scope, name, | 1019 newName = getFreshName(scope, name, |
1018 sanitizeForAnnotations: true, | 1020 sanitizeForAnnotations: true, |
1019 sanitizeForNatives: false); | 1021 sanitizeForNatives: false); |
1020 internalInstanceMembers[element] = newName; | 1022 internalInstanceMembers[element] = newName; |
1021 } else { | 1023 } else { |
1022 bool mayClashNative = | 1024 bool mayClashNative = |
1023 _isUserClassExtendingNative(element.enclosingClass); | 1025 _isUserClassExtendingNative(element.enclosingClass); |
1024 newName = getFreshName(instanceScope, name, | 1026 newName = getFreshName(instanceScope, name, |
1025 sanitizeForAnnotations: true, | 1027 sanitizeForAnnotations: true, |
1026 sanitizeForNatives: mayClashNative); | 1028 sanitizeForNatives: mayClashNative); |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 String suggestName(String original) => _suggestedNames[original]; | 2037 String suggestName(String original) => _suggestedNames[original]; |
2036 void addSuggestion(String original, String suggestion) { | 2038 void addSuggestion(String original, String suggestion) { |
2037 assert(!_suggestedNames.containsKey(original)); | 2039 assert(!_suggestedNames.containsKey(original)); |
2038 _suggestedNames[original] = suggestion; | 2040 _suggestedNames[original] = suggestion; |
2039 } | 2041 } |
2040 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2042 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
2041 bool isSuggestion(String candidate) { | 2043 bool isSuggestion(String candidate) { |
2042 return _suggestedNames.containsValue(candidate); | 2044 return _suggestedNames.containsValue(candidate); |
2043 } | 2045 } |
2044 } | 2046 } |
OLD | NEW |