| 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, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 name, usedTopLevelIdentifiers.contains); | 25 name, usedTopLevelIdentifiers.contains); |
| 26 usedTopLevelIdentifiers.add(newName); | 26 usedTopLevelIdentifiers.add(newName); |
| 27 return newName; | 27 return newName; |
| 28 } | 28 } |
| 29 | 29 |
| 30 rename(library, originalName) => | 30 rename(library, originalName) => |
| 31 renamed.putIfAbsent(library, () => <String>{}) | 31 renamed.putIfAbsent(library, () => <String>{}) |
| 32 .putIfAbsent(originalName, () => generateUniqueName(originalName)); | 32 .putIfAbsent(originalName, () => generateUniqueName(originalName)); |
| 33 | 33 |
| 34 String renameElement(Element element) { | 34 String renameElement(Element element) { |
| 35 assert(element.isTopLevel() || element is TypeVariableElement); | 35 assert(Elements.isStaticOrTopLevel(element) |
| 36 || element is TypeVariableElement); |
| 36 // TODO(smok): Make sure that the new name does not conflict with existing | 37 // TODO(smok): Make sure that the new name does not conflict with existing |
| 37 // local identifiers. | 38 // local identifiers. |
| 39 // TODO(smok): We may want to reuse class static field and method names. |
| 38 String originalName = element.name.slowToString(); | 40 String originalName = element.name.slowToString(); |
| 39 LibraryElement library = element.getLibrary(); | 41 LibraryElement library = element.getLibrary(); |
| 40 if (isDartCoreLib(compiler, library)) { | 42 if (isDartCoreLib(compiler, library)) { |
| 41 final prefix = | 43 final prefix = |
| 42 imports.putIfAbsent(library, () => generateUniqueName('p')); | 44 imports.putIfAbsent(library, () => generateUniqueName('p')); |
| 43 return '$prefix.$originalName'; | 45 return '$prefix.$originalName'; |
| 44 } | 46 } |
| 45 | 47 |
| 46 return rename(library, originalName); | 48 return rename(library, originalName); |
| 47 } | 49 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 int length = alphabet.length; | 120 int length = alphabet.length; |
| 119 StringBuffer resultBuilder = new StringBuffer(); | 121 StringBuffer resultBuilder = new StringBuffer(); |
| 120 while (index >= length) { | 122 while (index >= length) { |
| 121 resultBuilder.add(alphabet[index % length]); | 123 resultBuilder.add(alphabet[index % length]); |
| 122 index ~/= length; | 124 index ~/= length; |
| 123 } | 125 } |
| 124 resultBuilder.add(alphabet[index]); | 126 resultBuilder.add(alphabet[index]); |
| 125 return resultBuilder.toString(); | 127 return resultBuilder.toString(); |
| 126 } | 128 } |
| 127 } | 129 } |
| OLD | NEW |