| 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 class ConflictingRenamer { | 9 class ConflictingRenamer { |
| 10 final Compiler compiler; | 10 final Compiler compiler; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 return (placeholder !== null) ? placeholder.rename(this) : null; | 28 return (placeholder !== null) ? placeholder.rename(this) : null; |
| 29 } | 29 } |
| 30 | 30 |
| 31 String getName(LibraryElement library, String originalName, renamer) => | 31 String getName(LibraryElement library, String originalName, renamer) => |
| 32 renamed.putIfAbsent(library, () => <String>{}) | 32 renamed.putIfAbsent(library, () => <String>{}) |
| 33 .putIfAbsent(originalName, renamer); | 33 .putIfAbsent(originalName, renamer); |
| 34 | 34 |
| 35 String renamePrivateIdentifier(LibraryElement library, String id) => | 35 String renamePrivateIdentifier(LibraryElement library, String id) => |
| 36 getName(library, id, () => '_${privateNameCounter++}${id}'); | 36 getName(library, id, () => '_${privateNameCounter++}${id}'); |
| 37 | 37 |
| 38 String generateUniqueName(name) { |
| 39 while (usedTopLevelIdentifiers.contains(name)) name = 'p_$name'; |
| 40 usedTopLevelIdentifiers.add(name); |
| 41 return name; |
| 42 } |
| 43 |
| 38 String renameElement(Element element) { | 44 String renameElement(Element element) { |
| 39 assert(element.isTopLevel()); | 45 assert(element.isTopLevel()); |
| 40 // TODO(smok): Make sure that the new name does not conflict with existing | 46 // TODO(smok): Make sure that the new name does not conflict with existing |
| 41 // local identifiers. | 47 // local identifiers. |
| 42 generateUniqueName(name) { | |
| 43 while (usedTopLevelIdentifiers.contains(name)) name = 'p_$name'; | |
| 44 usedTopLevelIdentifiers.add(name); | |
| 45 return name; | |
| 46 } | |
| 47 | |
| 48 String originalName = element.name.slowToString(); | 48 String originalName = element.name.slowToString(); |
| 49 LibraryElement library = element.getLibrary(); | 49 LibraryElement library = element.getLibrary(); |
| 50 if (library === compiler.coreLibrary) return originalName; | 50 if (library === compiler.coreLibrary) return originalName; |
| 51 if (isDartCoreLib(compiler, library)) { | 51 if (isDartCoreLib(compiler, library)) { |
| 52 final prefix = | 52 final prefix = |
| 53 imports.putIfAbsent(library, () => generateUniqueName('p')); | 53 imports.putIfAbsent(library, () => generateUniqueName('p')); |
| 54 return '$prefix.$originalName'; | 54 return '$prefix.$originalName'; |
| 55 } | 55 } |
| 56 | 56 |
| 57 return getName(library, originalName, | 57 return getName(library, originalName, |
| 58 () => generateUniqueName(originalName)); | 58 () => generateUniqueName(originalName)); |
| 59 } | 59 } |
| 60 } | 60 } |
| OLD | NEW |