| OLD | NEW |
| 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; | 5 part of js_backend; |
| 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(Element element) { | 16 jsAst.Name _minifiedInstanceFieldPropertyName(Element element) { |
| 17 if (backend.hasFixedBackendName(element)) { | 17 if (backend.hasFixedBackendName(element)) { |
| 18 return new StringBackedName(backend.getFixedBackendName(element)); | 18 return new StringBackedName(backend.getFixedBackendName(element)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 _FieldNamingScope names; | 21 _FieldNamingScope names; |
| 22 if (element is BoxFieldElement) { | 22 if (element is BoxFieldElement) { |
| 23 names = new _FieldNamingScope.forBox(element.box, fieldRegistry); | 23 names = new _FieldNamingScope.forBox(element.box, fieldRegistry); |
| 24 } else { | 24 } else { |
| 25 ClassElement cls = element is ClosureFieldElement | 25 ClassElement cls = element.enclosingClass; |
| 26 ? element.closureClass | |
| 27 : element.enclosingClass; | |
| 28 names = | 26 names = |
| 29 new _FieldNamingScope.forClass(cls, compiler.world, fieldRegistry); | 27 new _FieldNamingScope.forClass(cls, compiler.world, fieldRegistry); |
| 30 } | 28 } |
| 31 | 29 |
| 32 if (names.containsField(element)) { | 30 if (names.containsField(element)) { |
| 33 return names[element]; | 31 return names[element]; |
| 34 } | 32 } |
| 35 return null; | 33 return null; |
| 36 } | 34 } |
| 37 } | 35 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // The namer usually does not use certain names as they clash with | 68 // The namer usually does not use certain names as they clash with |
| 71 // existing properties on JS objects (see [_reservedNativeProperties]). | 69 // existing properties on JS objects (see [_reservedNativeProperties]). |
| 72 // However, some of them are really short and safe to use for fields. | 70 // However, some of them are really short and safe to use for fields. |
| 73 // Thus, we shortcut the namer to use those first. | 71 // Thus, we shortcut the namer to use those first. |
| 74 assert(index == nameStore.length); | 72 assert(index == nameStore.length); |
| 75 if (index < MinifyNamer._reservedNativeProperties.length && | 73 if (index < MinifyNamer._reservedNativeProperties.length && |
| 76 MinifyNamer._reservedNativeProperties[index].length <= 2) { | 74 MinifyNamer._reservedNativeProperties[index].length <= 2) { |
| 77 nameStore.add( | 75 nameStore.add( |
| 78 new StringBackedName(MinifyNamer._reservedNativeProperties[index])); | 76 new StringBackedName(MinifyNamer._reservedNativeProperties[index])); |
| 79 } else { | 77 } else { |
| 80 nameStore.add(namer.getFreshName(NamingScope.instance, "field$index")); | 78 nameStore.add(namer.getFreshName(namer.instanceScope, "field$index")); |
| 81 } | 79 } |
| 82 } | 80 } |
| 83 | 81 |
| 84 return nameStore[index]; | 82 return nameStore[index]; |
| 85 } | 83 } |
| 86 } | 84 } |
| 87 | 85 |
| 88 /** | 86 /** |
| 89 * A [_FieldNamingScope] encodes a node in the inheritance tree of the current | 87 * A [_FieldNamingScope] encodes a node in the inheritance tree of the current |
| 90 * class hierarchy. The root node typically is the node corresponding to the | 88 * class hierarchy. The root node typically is the node corresponding to the |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 : super.rootScope(box, registry); | 226 : super.rootScope(box, registry); |
| 229 | 227 |
| 230 @override | 228 @override |
| 231 bool containsField(_) => true; | 229 bool containsField(_) => true; |
| 232 | 230 |
| 233 jsAst.Name operator [](Element field) { | 231 jsAst.Name operator [](Element field) { |
| 234 if (!names.containsKey(field)) add(field); | 232 if (!names.containsKey(field)) add(field); |
| 235 return names[field]; | 233 return names[field]; |
| 236 } | 234 } |
| 237 } | 235 } |
| OLD | NEW |