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 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 } | 37 } |
38 | 38 |
39 /** | 39 /** |
40 * Encapsulates the global state of field naming. | 40 * Encapsulates the global state of field naming. |
41 * | 41 * |
42 * The field naming registry allocates names to be used along a path in the | 42 * The field naming registry allocates names to be used along a path in the |
43 * inheritance hierarchy of fields, starting with the object class. The actual | 43 * inheritance hierarchy of fields, starting with the object class. The actual |
44 * hierarchy is encoded using instances of [_FieldNamingScope]. | 44 * hierarchy is encoded using instances of [_FieldNamingScope]. |
45 */ | 45 */ |
46 class _FieldNamingRegistry { | 46 class _FieldNamingRegistry { |
47 final MinifyNamer namer; | 47 final Namer namer; |
48 | 48 |
49 final Map<Entity, _FieldNamingScope> scopes = | 49 final Map<Entity, _FieldNamingScope> scopes = |
50 new Map<Entity, _FieldNamingScope>(); | 50 new Map<Entity, _FieldNamingScope>(); |
51 | 51 |
52 final Map<Entity, jsAst.Name> globalNames = new Map<Entity, jsAst.Name>(); | 52 final Map<Entity, jsAst.Name> globalNames = new Map<Entity, jsAst.Name>(); |
53 | 53 |
54 int globalCount = 0; | 54 int globalCount = 0; |
55 | 55 |
56 final List<jsAst.Name> nameStore = new List<jsAst.Name>(); | 56 final List<jsAst.Name> nameStore = new List<jsAst.Name>(); |
57 | 57 |
58 _FieldNamingRegistry(this.namer); | 58 _FieldNamingRegistry(this.namer); |
59 | 59 |
60 // Returns the name to be used for a field with distance [index] from the | 60 // Returns the name to be used for a field with distance [index] from the |
61 // root of the object hierarchy. The distance thereby is computed as the | 61 // root of the object hierarchy. The distance thereby is computed as the |
62 // number of fields preceding the current field in its classes inheritance | 62 // number of fields preceding the current field in its classes inheritance |
63 // chain. | 63 // chain. |
64 // | 64 // |
65 // The implementation assumes that names are requedsted in order, that is the | 65 // The implementation assumes that names are requedsted in order, that is the |
66 // name at position i+1 is requested after the name at position i was | 66 // name at position i+1 is requested after the name at position i was |
67 // requested. | 67 // requested. |
68 jsAst.Name getName(int index) { | 68 jsAst.Name getName(int index) { |
69 if (index >= nameStore.length) { | 69 if (index >= nameStore.length) { |
70 // The namer usually does not use certain names as they clash with | 70 // The namer usually does not use certain names as they clash with |
71 // existing properties on JS objects (see [_reservedNativeProperties]). | 71 // existing properties on JS objects (see [_reservedNativeProperties]). |
72 // However, some of them are really short and safe to use for fields. | 72 // However, some of them are really short and safe to use for fields. |
73 // Thus, we shortcut the namer to use those first. | 73 // Thus, we shortcut the namer to use those first. |
74 assert(index == nameStore.length + 1); | 74 assert(index == nameStore.length); |
herhut
2015/06/30 16:33:26
this is a back-ported fix from a later revision...
| |
75 if (index < MinifyNamer._reservedNativeProperties.length && | 75 if (index < MinifyNamer._reservedNativeProperties.length && |
76 MinifyNamer._reservedNativeProperties[index].length <= 2) { | 76 MinifyNamer._reservedNativeProperties[index].length <= 2) { |
77 nameStore.add( | 77 nameStore.add( |
78 new StringBackedName(MinifyNamer._reservedNativeProperties[index])); | 78 new StringBackedName(MinifyNamer._reservedNativeProperties[index])); |
79 } else { | 79 } else { |
80 nameStore.add(namer.getFreshName("field$index", namer.usedInstanceNames, | 80 nameStore.add(namer.getFreshName(NamingScope.instance, "field$index")); |
81 namer.suggestedInstanceNames)); | |
82 } | 81 } |
83 } | 82 } |
84 | 83 |
85 return nameStore[index]; | 84 return nameStore[index]; |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 /** | 88 /** |
90 * A [_FieldNamingScope] encodes a node in the inheritance tree of the current | 89 * A [_FieldNamingScope] encodes a node in the inheritance tree of the current |
91 * class hierarchy. The root node typically is the node corresponding to the | 90 * 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... | |
229 : super.rootScope(box, registry); | 228 : super.rootScope(box, registry); |
230 | 229 |
231 @override | 230 @override |
232 bool containsField(_) => true; | 231 bool containsField(_) => true; |
233 | 232 |
234 jsAst.Name operator [](Element field) { | 233 jsAst.Name operator [](Element field) { |
235 if (!names.containsKey(field)) add(field); | 234 if (!names.containsKey(field)) add(field); |
236 return names[field]; | 235 return names[field]; |
237 } | 236 } |
238 } | 237 } |
OLD | NEW |