| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Renames only top-level elements that would let to ambiguity if not renamed. | 6 * Renames only top-level elements that would let to ambiguity if not renamed. |
| 7 * TODO(smok): Make sure that top-level fields are correctly renamed. | 7 * TODO(smok): Make sure that top-level fields are correctly renamed. |
| 8 */ | 8 */ |
| 9 void renamePlaceholders( | 9 void renamePlaceholders( |
| 10 Compiler compiler, | 10 Compiler compiler, |
| 11 PlaceholderCollector placeholderCollector, | 11 PlaceholderCollector placeholderCollector, |
| 12 Map<Node, String> renames, | 12 Map<Node, String> renames, |
| 13 Map<LibraryElement, String> imports, | 13 Map<LibraryElement, String> imports, |
| 14 Set<String> fixedMemberNames, | 14 Set<String> fixedMemberNames, |
| 15 bool minify, | |
| 16 bool cutDeclarationTypes) { | 15 bool cutDeclarationTypes) { |
| 17 final Map<LibraryElement, Map<String, String>> renamed | 16 final Map<LibraryElement, Map<String, String>> renamed |
| 18 = new Map<LibraryElement, Map<String, String>>(); | 17 = new Map<LibraryElement, Map<String, String>>(); |
| 19 Generator topLevelGenerator = | 18 Generator topLevelGenerator = compiler.enableMinification |
| 20 minify ? new MinifyingGenerator('ABCDEFGHIJKLMNOPQRSTUVWXYZ').generate | 19 ? new MinifyingGenerator('ABCDEFGHIJKLMNOPQRSTUVWXYZ').generate |
| 21 : conservativeGenerator; | 20 : conservativeGenerator; |
| 22 makeGenerator(usedIdentifierSet) => (name) { | 21 makeGenerator(usedIdentifierSet) => (name) { |
| 23 String newName = topLevelGenerator(name, usedIdentifierSet.contains); | 22 String newName = topLevelGenerator(name, usedIdentifierSet.contains); |
| 24 usedIdentifierSet.add(newName); | 23 usedIdentifierSet.add(newName); |
| 25 return newName; | 24 return newName; |
| 26 }; | 25 }; |
| 27 | 26 |
| 28 final usedTopLevelIdentifiers = new Set<String>(); | 27 final usedTopLevelIdentifiers = new Set<String>(); |
| 29 // TODO(antonm): we should also populate this set with top-level | 28 // TODO(antonm): we should also populate this set with top-level |
| 30 // names from core library. | 29 // names from core library. |
| 31 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'. | 30 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 renameNodes(placeholderCollector.nullNodes, (_) => ''); | 68 renameNodes(placeholderCollector.nullNodes, (_) => ''); |
| 70 renameNodes(placeholderCollector.unresolvedNodes, | 69 renameNodes(placeholderCollector.unresolvedNodes, |
| 71 (_) => generateUniqueName('Unresolved')); | 70 (_) => generateUniqueName('Unresolved')); |
| 72 sortedForEach(placeholderCollector.elementNodes, (element, nodes) { | 71 sortedForEach(placeholderCollector.elementNodes, (element, nodes) { |
| 73 String renamedElement = renameElement(element); | 72 String renamedElement = renameElement(element); |
| 74 renameNodes(nodes, (_) => renamedElement); | 73 renameNodes(nodes, (_) => renamedElement); |
| 75 }); | 74 }); |
| 76 sortedForEach(placeholderCollector.functionScopes, | 75 sortedForEach(placeholderCollector.functionScopes, |
| 77 (functionElement, functionScope) { | 76 (functionElement, functionScope) { |
| 78 Set<LocalPlaceholder> placeholders = functionScope.localPlaceholders; | 77 Set<LocalPlaceholder> placeholders = functionScope.localPlaceholders; |
| 79 Generator localGenerator = | 78 Generator localGenerator = compiler.enableMinification |
| 80 minify ? new MinifyingGenerator('abcdefghijklmnopqrstuvwxyz').generate | 79 ? new MinifyingGenerator('abcdefghijklmnopqrstuvwxyz').generate |
| 81 : conservativeGenerator; | 80 : conservativeGenerator; |
| 82 Set<String> memberIdentifiers = new Set<String>(); | 81 Set<String> memberIdentifiers = new Set<String>(); |
| 83 if (functionElement.getEnclosingClass() !== null) { | 82 if (functionElement.getEnclosingClass() !== null) { |
| 84 functionElement.getEnclosingClass().forEachMember( | 83 functionElement.getEnclosingClass().forEachMember( |
| 85 (enclosingClass, member) { | 84 (enclosingClass, member) { |
| 86 memberIdentifiers.add(member.name.slowToString()); | 85 memberIdentifiers.add(member.name.slowToString()); |
| 87 }); | 86 }); |
| 88 } | 87 } |
| 89 Set<String> usedLocalIdentifiers = new Set<String>(); | 88 Set<String> usedLocalIdentifiers = new Set<String>(); |
| 90 // TODO(smok): Take usages into account. | 89 // TODO(smok): Take usages into account. |
| 91 for (LocalPlaceholder placeholder in placeholders) { | 90 for (LocalPlaceholder placeholder in placeholders) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 int length = alphabet.length; | 158 int length = alphabet.length; |
| 160 StringBuffer resultBuilder = new StringBuffer(); | 159 StringBuffer resultBuilder = new StringBuffer(); |
| 161 while (index >= length) { | 160 while (index >= length) { |
| 162 resultBuilder.add(alphabet[index % length]); | 161 resultBuilder.add(alphabet[index % length]); |
| 163 index ~/= length; | 162 index ~/= length; |
| 164 } | 163 } |
| 165 resultBuilder.add(alphabet[index]); | 164 resultBuilder.add(alphabet[index]); |
| 166 return resultBuilder.toString(); | 165 return resultBuilder.toString(); |
| 167 } | 166 } |
| 168 } | 167 } |
| OLD | NEW |