| 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 |
| 11 import '../closure.dart'; | 11 import '../closure.dart'; |
| 12 import '../common.dart'; | 12 import '../common.dart'; |
| 13 import '../common/names.dart' show Identifiers, Selectors; | 13 import '../common/names.dart' show Identifiers, Selectors; |
| 14 import '../constants/values.dart'; | 14 import '../constants/values.dart'; |
| 15 import '../common_elements.dart' show CommonElements; | 15 import '../common_elements.dart' show CommonElements, ElementEnvironment; |
| 16 import '../diagnostics/invariant.dart' show DEBUG_MODE; | 16 import '../diagnostics/invariant.dart' show DEBUG_MODE; |
| 17 import '../elements/elements.dart' | 17 import '../elements/elements.dart' |
| 18 show | 18 show |
| 19 ClassElement, | 19 ClassElement, |
| 20 Element, | 20 Element, |
| 21 Elements, | 21 Elements, |
| 22 MemberElement, | 22 MemberElement, |
| 23 MixinApplicationElement; | 23 MixinApplicationElement; |
| 24 import '../elements/entities.dart'; | 24 import '../elements/entities.dart'; |
| 25 import '../elements/entity_utils.dart' as utils; | 25 import '../elements/entity_utils.dart' as utils; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 final Map<LibraryEntity, String> _libraryKeys = | 571 final Map<LibraryEntity, String> _libraryKeys = |
| 572 new HashMap<LibraryEntity, String>(); | 572 new HashMap<LibraryEntity, String>(); |
| 573 | 573 |
| 574 Namer(this._closedWorld, this._codegenWorldBuilder) { | 574 Namer(this._closedWorld, this._codegenWorldBuilder) { |
| 575 _literalAsyncPrefix = new StringBackedName(asyncPrefix); | 575 _literalAsyncPrefix = new StringBackedName(asyncPrefix); |
| 576 _literalGetterPrefix = new StringBackedName(getterPrefix); | 576 _literalGetterPrefix = new StringBackedName(getterPrefix); |
| 577 _literalSetterPrefix = new StringBackedName(setterPrefix); | 577 _literalSetterPrefix = new StringBackedName(setterPrefix); |
| 578 _literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix); | 578 _literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix); |
| 579 } | 579 } |
| 580 | 580 |
| 581 ElementEnvironment get _elementEnvironment => _closedWorld.elementEnvironment; |
| 582 |
| 581 CommonElements get _commonElements => _closedWorld.commonElements; | 583 CommonElements get _commonElements => _closedWorld.commonElements; |
| 582 | 584 |
| 583 NativeData get _nativeData => _closedWorld.nativeData; | 585 NativeData get _nativeData => _closedWorld.nativeData; |
| 584 | 586 |
| 585 String get deferredTypesName => 'deferredTypes'; | 587 String get deferredTypesName => 'deferredTypes'; |
| 586 String get isolateName => 'Isolate'; | 588 String get isolateName => 'Isolate'; |
| 587 String get isolatePropertiesName => r'$isolateProperties'; | 589 String get isolatePropertiesName => r'$isolateProperties'; |
| 588 jsAst.Name get noSuchMethodName => invocationName(Selectors.noSuchMethod_); | 590 jsAst.Name get noSuchMethodName => invocationName(Selectors.noSuchMethod_); |
| 589 | 591 |
| 590 /** | 592 /** |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 return _disambiguateInternalMember(element, proposeName); | 948 return _disambiguateInternalMember(element, proposeName); |
| 947 } | 949 } |
| 948 | 950 |
| 949 // No superclass uses the disambiguated name as a property name, so we can | 951 // No superclass uses the disambiguated name as a property name, so we can |
| 950 // use it for this field. This generates nicer field names since otherwise | 952 // use it for this field. This generates nicer field names since otherwise |
| 951 // the field name would have to be mangled. | 953 // the field name would have to be mangled. |
| 952 return _disambiguateMember(new Name(element.name, element.library)); | 954 return _disambiguateMember(new Name(element.name, element.library)); |
| 953 } | 955 } |
| 954 | 956 |
| 955 bool _isShadowingSuperField(FieldEntity element) { | 957 bool _isShadowingSuperField(FieldEntity element) { |
| 956 ClassEntity cls = element.enclosingClass; | 958 assert(element.isField); |
| 957 if (cls is ClassElement) { | 959 String fieldName = element.name; |
| 958 return cls.hasFieldShadowedBy(element); | 960 bool isPrivate = Name.isPrivateName(fieldName); |
| 961 LibraryEntity memberLibrary = element.library; |
| 962 ClassEntity lookupClass = |
| 963 _elementEnvironment.getSuperClass(element.enclosingClass); |
| 964 while (lookupClass != null) { |
| 965 MemberEntity foundMember = |
| 966 _elementEnvironment.lookupClassMember(lookupClass, fieldName); |
| 967 if (foundMember != null) { |
| 968 if (foundMember.isField) { |
| 969 if (!isPrivate || memberLibrary == foundMember.library) { |
| 970 // Private fields can only be shadowed by a field declared in the |
| 971 // same library. |
| 972 return true; |
| 973 } |
| 974 } |
| 975 } |
| 976 lookupClass = _elementEnvironment.getSuperClass(lookupClass); |
| 959 } | 977 } |
| 960 // TODO(redemption): Support class entities. | |
| 961 return false; | 978 return false; |
| 962 } | 979 } |
| 963 | 980 |
| 964 /// True if [class_] is a non-native class that inherits from a native class. | 981 /// True if [class_] is a non-native class that inherits from a native class. |
| 965 bool _isUserClassExtendingNative(ClassEntity class_) { | 982 bool _isUserClassExtendingNative(ClassEntity class_) { |
| 966 return !_nativeData.isNativeClass(class_) && | 983 return !_nativeData.isNativeClass(class_) && |
| 967 _nativeData.isNativeOrExtendsNative(class_); | 984 _nativeData.isNativeOrExtendsNative(class_); |
| 968 } | 985 } |
| 969 | 986 |
| 970 /// Annotated name for the setter of [element]. | 987 /// Annotated name for the setter of [element]. |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2244 void addSuggestion(String original, String suggestion) { | 2261 void addSuggestion(String original, String suggestion) { |
| 2245 assert(!_suggestedNames.containsKey(original)); | 2262 assert(!_suggestedNames.containsKey(original)); |
| 2246 _suggestedNames[original] = suggestion; | 2263 _suggestedNames[original] = suggestion; |
| 2247 } | 2264 } |
| 2248 | 2265 |
| 2249 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2266 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2250 bool isSuggestion(String candidate) { | 2267 bool isSuggestion(String candidate) { |
| 2251 return _suggestedNames.containsValue(candidate); | 2268 return _suggestedNames.containsValue(candidate); |
| 2252 } | 2269 } |
| 2253 } | 2270 } |
| OLD | NEW |