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 '../compiler.dart' show Compiler; | 14 import '../compiler.dart' show Compiler; |
15 import '../constants/values.dart'; | 15 import '../constants/values.dart'; |
16 import '../core_types.dart' show CoreClasses; | 16 import '../core_types.dart' show CoreClasses; |
17 import '../dart_types.dart'; | 17 import '../dart_types.dart'; |
18 import '../diagnostics/invariant.dart' show DEBUG_MODE; | 18 import '../diagnostics/invariant.dart' show DEBUG_MODE; |
19 import '../elements/elements.dart'; | 19 import '../elements/elements.dart'; |
20 import '../js/js.dart' as jsAst; | 20 import '../js/js.dart' as jsAst; |
21 import '../js/js.dart' show js; | 21 import '../js/js.dart' show js; |
22 import '../tree/tree.dart'; | 22 import '../tree/tree.dart'; |
23 import '../universe/call_structure.dart' show CallStructure; | 23 import '../universe/call_structure.dart' show CallStructure; |
24 import '../universe/selector.dart' show Selector, SelectorKind; | 24 import '../universe/selector.dart' show Selector, SelectorKind; |
25 import '../util/characters.dart'; | 25 import '../util/characters.dart'; |
26 import '../util/util.dart'; | 26 import '../util/util.dart'; |
27 import '../world.dart' show ClassWorld; | 27 import '../world.dart' show ClosedWorld; |
28 import 'backend.dart'; | 28 import 'backend.dart'; |
29 import 'backend_helpers.dart'; | 29 import 'backend_helpers.dart'; |
30 import 'constant_system_javascript.dart'; | 30 import 'constant_system_javascript.dart'; |
31 | 31 |
32 part 'field_naming_mixin.dart'; | 32 part 'field_naming_mixin.dart'; |
33 part 'frequency_namer.dart'; | 33 part 'frequency_namer.dart'; |
34 part 'minify_namer.dart'; | 34 part 'minify_namer.dart'; |
35 part 'namer_names.dart'; | 35 part 'namer_names.dart'; |
36 | 36 |
37 /** | 37 /** |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 element, () => asEntity.declaredEntity.name); | 846 element, () => asEntity.declaredEntity.name); |
847 } | 847 } |
848 | 848 |
849 // If the name of the field might clash with another field, | 849 // If the name of the field might clash with another field, |
850 // use a mangled field name to avoid potential clashes. | 850 // use a mangled field name to avoid potential clashes. |
851 // Note that if the class extends a native class, that native class might | 851 // Note that if the class extends a native class, that native class might |
852 // have fields with fixed backend names, so we assume the worst and always | 852 // have fields with fixed backend names, so we assume the worst and always |
853 // mangle the field names of classes extending native classes. | 853 // mangle the field names of classes extending native classes. |
854 // Methods on such classes are stored on the interceptor, not the instance, | 854 // Methods on such classes are stored on the interceptor, not the instance, |
855 // so only fields have the potential to clash with a native property name. | 855 // so only fields have the potential to clash with a native property name. |
856 ClassWorld classWorld = compiler.closedWorld; | 856 ClosedWorld closedWorld = compiler.closedWorld; |
857 if (classWorld.isUsedAsMixin(enclosingClass) || | 857 if (closedWorld.isUsedAsMixin(enclosingClass) || |
858 _isShadowingSuperField(element) || | 858 _isShadowingSuperField(element) || |
859 _isUserClassExtendingNative(enclosingClass)) { | 859 _isUserClassExtendingNative(enclosingClass)) { |
860 String proposeName() => '${enclosingClass.name}_${element.name}'; | 860 String proposeName() => '${enclosingClass.name}_${element.name}'; |
861 return _disambiguateInternalMember(element, proposeName); | 861 return _disambiguateInternalMember(element, proposeName); |
862 } | 862 } |
863 | 863 |
864 // No superclass uses the disambiguated name as a property name, so we can | 864 // No superclass uses the disambiguated name as a property name, so we can |
865 // use it for this field. This generates nicer field names since otherwise | 865 // use it for this field. This generates nicer field names since otherwise |
866 // the field name would have to be mangled. | 866 // the field name would have to be mangled. |
867 return _disambiguateMember(element.memberName); | 867 return _disambiguateMember(element.memberName); |
(...skipping 1232 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 |