| 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 final Map<LibraryElement, Map<String, String>> renamed | 14 final Map<LibraryElement, Map<String, String>> renamed |
| 15 = new Map<LibraryElement, Map<String, String>>(); | 15 = new Map<LibraryElement, Map<String, String>>(); |
| 16 final Set<String> usedTopLevelIdentifiers = new Set<String>(); | 16 final Set<String> usedTopLevelIdentifiers = new Set<String>(); |
| 17 // TODO(antonm): we should also populate this set with top-level |
| 18 // names from core library. |
| 19 usedTopLevelIdentifiers.add('main'); // Never rename anything to 'main'. |
| 17 | 20 |
| 18 Generator topLevelGenerator = | 21 Generator topLevelGenerator = |
| 19 true ? conservativeGenerator : new MinifyingGenerator('ABCD').generate; | 22 true ? conservativeGenerator : new MinifyingGenerator('ABCD').generate; |
| 20 String generateUniqueName(name) { | 23 String generateUniqueName(name) { |
| 21 String newName = topLevelGenerator( | 24 String newName = topLevelGenerator( |
| 22 name, usedTopLevelIdentifiers.contains); | 25 name, usedTopLevelIdentifiers.contains); |
| 23 usedTopLevelIdentifiers.add(newName); | 26 usedTopLevelIdentifiers.add(newName); |
| 24 return newName; | 27 return newName; |
| 25 } | 28 } |
| 26 | 29 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 int length = alphabet.length; | 118 int length = alphabet.length; |
| 116 StringBuffer resultBuilder = new StringBuffer(); | 119 StringBuffer resultBuilder = new StringBuffer(); |
| 117 while (index >= length) { | 120 while (index >= length) { |
| 118 resultBuilder.add(alphabet[index % length]); | 121 resultBuilder.add(alphabet[index % length]); |
| 119 index ~/= length; | 122 index ~/= length; |
| 120 } | 123 } |
| 121 resultBuilder.add(alphabet[index]); | 124 resultBuilder.add(alphabet[index]); |
| 122 return resultBuilder.toString(); | 125 return resultBuilder.toString(); |
| 123 } | 126 } |
| 124 } | 127 } |
| OLD | NEW |