Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: pkg/compiler/lib/src/js_backend/field_naming_mixin.dart

Issue 2996463002: Make minification Entity-friendly. (Closed)
Patch Set: . Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.namer; 5 part of js_backend.namer;
6 6
7 abstract class _MinifiedFieldNamer implements Namer { 7 abstract class _MinifiedFieldNamer implements Namer {
8 _FieldNamingRegistry get fieldRegistry; 8 _FieldNamingRegistry get fieldRegistry;
9 9
10 // Returns a minimal name for the field that is globally unique along 10 // Returns a minimal name for the field that is globally unique along
11 // the given element's class inheritance chain. 11 // the given element's class inheritance chain.
12 // 12 //
13 // The inheritance scope based naming might not yield a name. For instance, 13 // The inheritance scope based naming might not yield a name. For instance,
14 // this could be because the field belongs to a mixin. In such a case this 14 // this could be because the field belongs to a mixin. In such a case this
15 // will return `null` and a normal field name has to be used. 15 // will return `null` and a normal field name has to be used.
16 jsAst.Name _minifiedInstanceFieldPropertyName(FieldElement element) { 16 jsAst.Name _minifiedInstanceFieldPropertyName(FieldEntity element) {
17 if (_nativeData.hasFixedBackendName(element)) { 17 if (_nativeData.hasFixedBackendName(element)) {
18 return new StringBackedName(_nativeData.getFixedBackendName(element)); 18 return new StringBackedName(_nativeData.getFixedBackendName(element));
19 } 19 }
20 20
21 _FieldNamingScope names; 21 _FieldNamingScope names;
22 if (element is BoxFieldElement) { 22 if (element is BoxFieldElement || element is JBoxedField) {
23 names = new _FieldNamingScope.forBox(element.box, fieldRegistry); 23 names = new _FieldNamingScope.forBox(element.box, fieldRegistry);
Siggi Cherem (dart-lang) 2017/08/03 23:44:54 this might trigger some unhappy analyzer in strong
Emily Fortuna 2017/08/04 01:35:03 yes, sorry about that. Just ran the analyzer tests
24 } else { 24 } else {
25 ClassElement cls = element.enclosingClass; 25 ClassEntity cls = element.enclosingClass;
26 names = new _FieldNamingScope.forClass(cls, _closedWorld, fieldRegistry); 26 names = new _FieldNamingScope.forClass(cls, _closedWorld, fieldRegistry);
27 } 27 }
28 28
29 if (names.containsField(element)) { 29 if (names.containsField(element)) {
30 return names[element]; 30 return names[element];
31 } 31 }
32 return null; 32 return null;
33 } 33 }
34 } 34 }
35 35
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 /// The number of locally used fields. Depending on the naming source 110 /// The number of locally used fields. Depending on the naming source
111 /// (e.g. inheritance based or globally unique for mixixns) this 111 /// (e.g. inheritance based or globally unique for mixixns) this
112 /// might be different from [inheritanceBasedFieldNameCounter]. 112 /// might be different from [inheritanceBasedFieldNameCounter].
113 int get _localFieldNameCounter => _fieldNameCounter; 113 int get _localFieldNameCounter => _fieldNameCounter;
114 void set _localFieldNameCounter(int val) { 114 void set _localFieldNameCounter(int val) {
115 _fieldNameCounter = val; 115 _fieldNameCounter = val;
116 } 116 }
117 117
118 factory _FieldNamingScope.forClass( 118 factory _FieldNamingScope.forClass(
119 ClassElement cls, ClosedWorld world, _FieldNamingRegistry registry) { 119 ClassEntity cls, ClosedWorld world, _FieldNamingRegistry registry) {
120 _FieldNamingScope result = registry.scopes[cls]; 120 _FieldNamingScope result = registry.scopes[cls];
121 if (result != null) return result; 121 if (result != null) return result;
122 122
123 if (world.isUsedAsMixin(cls)) { 123 if (world.isUsedAsMixin(cls)) {
124 result = new _MixinFieldNamingScope.mixin(cls, registry); 124 result = new _MixinFieldNamingScope.mixin(cls, registry);
125 } else { 125 } else {
126 if (cls.superclass == null) { 126 var superclass = world.elementEnvironment.getSuperClass(cls);
127 if (superclass == null) {
127 result = new _FieldNamingScope.rootScope(cls, registry); 128 result = new _FieldNamingScope.rootScope(cls, registry);
128 } else { 129 } else {
129 _FieldNamingScope superScope = 130 _FieldNamingScope superScope =
130 new _FieldNamingScope.forClass(cls.superclass, world, registry); 131 new _FieldNamingScope.forClass(superclass, world, registry);
131 if (cls.isMixinApplication) { 132 if (world.elementEnvironment.isMixinApplication(cls)) {
132 result = 133 result =
133 new _MixinFieldNamingScope.mixedIn(cls, superScope, registry); 134 new _MixinFieldNamingScope.mixedIn(cls, superScope, registry);
134 } else { 135 } else {
135 result = new _FieldNamingScope.inherit(cls, superScope, registry); 136 result = new _FieldNamingScope.inherit(cls, superScope, registry);
136 } 137 }
137 } 138 }
138 } 139 }
139 140
140 cls.forEachInstanceField((cls, field) => result.add(field)); 141 world.elementEnvironment.forEachClassMember(cls,
142 (ClassEntity declarer, MemberEntity member) {
143 if (member.isField && member.isInstanceMember) result.add(member);
144 });
141 145
142 registry.scopes[cls] = result; 146 registry.scopes[cls] = result;
143 return result; 147 return result;
144 } 148 }
145 149
146 factory _FieldNamingScope.forBox(Local box, _FieldNamingRegistry registry) { 150 factory _FieldNamingScope.forBox(Local box, _FieldNamingRegistry registry) {
147 return registry.scopes 151 return registry.scopes
148 .putIfAbsent(box, () => new _BoxFieldNamingScope(box, registry)); 152 .putIfAbsent(box, () => new _BoxFieldNamingScope(box, registry));
149 } 153 }
150 154
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 : super.rootScope(box, registry); 229 : super.rootScope(box, registry);
226 230
227 @override 231 @override
228 bool containsField(_) => true; 232 bool containsField(_) => true;
229 233
230 jsAst.Name operator [](Element field) { 234 jsAst.Name operator [](Element field) {
231 if (!names.containsKey(field)) add(field); 235 if (!names.containsKey(field)) add(field);
232 return names[field]; 236 return names[field];
233 } 237 }
234 } 238 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698