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 class FrequencyBasedNamer extends Namer with _MinifiedFieldNamer, | 7 class FrequencyBasedNamer extends Namer with _MinifiedFieldNamer, |
8 _MinifiedOneShotInterceptorNamer implements jsAst.TokenFinalizer { | 8 _MinifiedOneShotInterceptorNamer implements jsAst.TokenFinalizer { |
9 _FieldNamingRegistry fieldRegistry; | 9 _FieldNamingRegistry fieldRegistry; |
10 List<TokenName> tokens = new List<TokenName>(); | 10 List<TokenName> tokens = new List<TokenName>(); |
11 | 11 |
12 Map<NamingScope, TokenScope> _tokenScopes = | 12 Map<NamingScope, TokenScope> _tokenScopes = |
13 new Maplet<NamingScope, TokenScope>(); | 13 new Maplet<NamingScope, TokenScope>(); |
14 | 14 |
15 // Some basic settings for smaller names | 15 // Some basic settings for smaller names |
16 String get isolateName => 'I'; | 16 String get isolateName => 'I'; |
17 String get isolatePropertiesName => 'p'; | 17 String get isolatePropertiesName => 'p'; |
18 bool get shouldMinify => true; | 18 bool get shouldMinify => true; |
19 | 19 |
20 final String getterPrefix = 'g'; | 20 final String getterPrefix = 'g'; |
21 final String setterPrefix = 's'; | 21 final String setterPrefix = 's'; |
22 final String callPrefix = ''; // this will create function names $<n> | 22 final String callPrefix = ''; // this will create function names $<n> |
23 | 23 |
24 FrequencyBasedNamer(Compiler compiler) : super(compiler) { | 24 FrequencyBasedNamer(Compiler compiler) : super(compiler) { |
25 fieldRegistry = new _FieldNamingRegistry(this); | 25 fieldRegistry = new _FieldNamingRegistry(this); |
26 } | 26 } |
27 | 27 |
28 TokenScope newScopeFor(NamingScope scope) { | 28 TokenScope newScopeFor(NamingScope scope) { |
29 if (scope == NamingScope.instance) { | 29 if (scope == instanceScope) { |
30 Set<String> illegalNames = new Set<String>.from(jsReserved); | 30 Set<String> illegalNames = new Set<String>.from(jsReserved); |
31 for (String illegal in MinifyNamer._reservedNativeProperties) { | 31 for (String illegal in MinifyNamer._reservedNativeProperties) { |
32 illegalNames.add(illegal); | 32 illegalNames.add(illegal); |
33 if (MinifyNamer._hasBannedPrefix(illegal)) { | 33 if (MinifyNamer._hasBannedPrefix(illegal)) { |
34 illegalNames.add(illegal.substring(1)); | 34 illegalNames.add(illegal.substring(1)); |
35 } | 35 } |
36 } | 36 } |
37 return new TokenScope(illegalNames); | 37 return new TokenScope(illegalNames); |
38 } else { | 38 } else { |
39 return new TokenScope(jsReserved); | 39 return new TokenScope(jsReserved); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 @override | 43 @override |
44 jsAst.Name getFreshName(NamingScope scope, String proposedName, | 44 jsAst.Name getFreshName(NamingScope scope, String proposedName, |
45 {bool sanitizeForNatives: false, | 45 {bool sanitizeForNatives: false, |
46 bool sanitizeForAnnotations: false}) { | 46 bool sanitizeForAnnotations: false}) { |
47 // Grab the scope for this token | 47 // Grab the scope for this token |
48 TokenScope tokenScope = _tokenScopes.putIfAbsent(scope, | 48 TokenScope tokenScope = _tokenScopes.putIfAbsent(scope, |
49 () => newScopeFor(scope)); | 49 () => newScopeFor(scope)); |
50 | 50 |
51 // Get the name the normal namer would use as a key. | 51 // Get the name the normal namer would use as a key. |
52 String proposed = _generateFreshStringForName(proposedName, | 52 String proposed = _generateFreshStringForName(proposedName, |
53 getUsedNames(scope), | 53 scope, |
54 getSuggestedNames(scope), | |
55 sanitizeForNatives: | 54 sanitizeForNatives: |
56 sanitizeForNatives, | 55 sanitizeForNatives, |
57 sanitizeForAnnotations: | 56 sanitizeForAnnotations: |
58 sanitizeForAnnotations); | 57 sanitizeForAnnotations); |
59 | 58 |
60 TokenName name = new TokenName(tokenScope, proposed); | 59 TokenName name = new TokenName(tokenScope, proposed); |
61 tokens.add(name); | 60 tokens.add(name); |
62 return name; | 61 return name; |
63 } | 62 } |
64 | 63 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 do { | 132 do { |
134 proposal = new String.fromCharCodes(_nextName); | 133 proposal = new String.fromCharCodes(_nextName); |
135 _incrementName(); | 134 _incrementName(); |
136 } while (MinifyNamer._hasBannedPrefix(proposal) || | 135 } while (MinifyNamer._hasBannedPrefix(proposal) || |
137 illegalNames.contains(proposal)); | 136 illegalNames.contains(proposal)); |
138 | 137 |
139 return proposal; | 138 return proposal; |
140 } | 139 } |
141 } | 140 } |
142 | 141 |
OLD | NEW |