| 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 bool minify) { | 14 bool minify, |
| 15 bool cutDeclarationTypes) { |
| 15 final Map<LibraryElement, Map<String, String>> renamed | 16 final Map<LibraryElement, Map<String, String>> renamed |
| 16 = new Map<LibraryElement, Map<String, String>>(); | 17 = new Map<LibraryElement, Map<String, String>>(); |
| 17 final Set<String> usedTopLevelIdentifiers = new Set<String>(); | 18 final Set<String> usedTopLevelIdentifiers = new Set<String>(); |
| 18 // TODO(antonm): we should also populate this set with top-level | 19 // TODO(antonm): we should also populate this set with top-level |
| 19 // names from core library. | 20 // names from core library. |
| 20 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'. | 21 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'. |
| 21 | 22 |
| 22 Generator topLevelGenerator = | 23 Generator topLevelGenerator = |
| 23 minify ? new MinifyingGenerator('ABCDEFGHIJKLMNOPQRSTUVWXYZ').generate | 24 minify ? new MinifyingGenerator('ABCDEFGHIJKLMNOPQRSTUVWXYZ').generate |
| 24 : conservativeGenerator; | 25 : conservativeGenerator; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 || usedTopLevelIdentifiers.contains(name) | 94 || usedTopLevelIdentifiers.contains(name) |
| 94 || usedLocalIdentifiers.contains(name) | 95 || usedLocalIdentifiers.contains(name) |
| 95 || memberIdentifiers.contains(name)); | 96 || memberIdentifiers.contains(name)); |
| 96 usedLocalIdentifiers.add(nextId); | 97 usedLocalIdentifiers.add(nextId); |
| 97 renameNodes(placeholder.nodes, (_) => nextId); | 98 renameNodes(placeholder.nodes, (_) => nextId); |
| 98 } | 99 } |
| 99 }); | 100 }); |
| 100 sortedForEach(placeholderCollector.privateNodes, (library, nodes) { | 101 sortedForEach(placeholderCollector.privateNodes, (library, nodes) { |
| 101 renameNodes(nodes, (node) => rename(library, node.source.slowToString())); | 102 renameNodes(nodes, (node) => rename(library, node.source.slowToString())); |
| 102 }); | 103 }); |
| 104 if (cutDeclarationTypes) { |
| 105 for (DeclarationTypePlaceholder placeholder in |
| 106 placeholderCollector.declarationTypePlaceholders) { |
| 107 renames[placeholder.typeNode] = placeholder.canOmitType ? '' : 'var'; |
| 108 } |
| 109 } |
| 103 } | 110 } |
| 104 | 111 |
| 105 typedef String Generator(String originalName, bool isForbidden(String name)); | 112 typedef String Generator(String originalName, bool isForbidden(String name)); |
| 106 | 113 |
| 107 /** Always tries to return original identifier name unless it is forbidden. */ | 114 /** Always tries to return original identifier name unless it is forbidden. */ |
| 108 String conservativeGenerator( | 115 String conservativeGenerator( |
| 109 String originalName, bool isForbidden(String name)) { | 116 String originalName, bool isForbidden(String name)) { |
| 110 String newName = originalName; | 117 String newName = originalName; |
| 111 while (isForbidden(newName)) { | 118 while (isForbidden(newName)) { |
| 112 newName = 'p_$newName'; | 119 newName = 'p_$newName'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 141 int length = alphabet.length; | 148 int length = alphabet.length; |
| 142 StringBuffer resultBuilder = new StringBuffer(); | 149 StringBuffer resultBuilder = new StringBuffer(); |
| 143 while (index >= length) { | 150 while (index >= length) { |
| 144 resultBuilder.add(alphabet[index % length]); | 151 resultBuilder.add(alphabet[index % length]); |
| 145 index ~/= length; | 152 index ~/= length; |
| 146 } | 153 } |
| 147 resultBuilder.add(alphabet[index]); | 154 resultBuilder.add(alphabet[index]); |
| 148 return resultBuilder.toString(); | 155 return resultBuilder.toString(); |
| 149 } | 156 } |
| 150 } | 157 } |
| OLD | NEW |