Chromium Code Reviews| Index: lib/compiler/implementation/namer.dart |
| diff --git a/lib/compiler/implementation/namer.dart b/lib/compiler/implementation/namer.dart |
| index e28958b886ca876eb8ed4d3ae8a68e281cfceb7c..5db362c1f87fd68a0ab7990728f5041f7e32fcfc 100644 |
| --- a/lib/compiler/implementation/namer.dart |
| +++ b/lib/compiler/implementation/namer.dart |
| @@ -23,10 +23,12 @@ class Namer { |
| Map<Element, String> globals; |
| Map<String, int> usedGlobals; |
| + Map<String, LibraryElement> shortPrivateNameOwners; |
| Namer(this.compiler) |
| : globals = new Map<Element, String>(), |
| - usedGlobals = new Map<String, int>(); |
| + usedGlobals = new Map<String, int>(), |
| + shortPrivateNameOwners = new Map<String, LibraryElement>(); |
| final String CURRENT_ISOLATE = "\$"; |
| final String ISOLATE = "Isolate"; |
| @@ -40,10 +42,26 @@ class Namer { |
| } |
| String privateName(LibraryElement lib, SourceString name) { |
| + bool canNotClashWithMangledPrivateNames(String proposedName) { |
|
ngeoffray
2012/05/10 14:20:41
I'd inline the closure, and add a comment instead
floitsch
2012/05/10 14:33:01
Done.
|
| + return !proposedName.startsWith('_$LIBRARY_PREFIX'); |
| + } |
| + |
| if (name.isPrivate()) { |
| - return '_${getName(lib)}${name.slowToString()}'; |
| + String nameString = name.slowToString(); |
| + |
| + // The first library asking for a short private name wins. |
| + LibraryElement owner = |
| + shortPrivateNameOwners.putIfAbsent(nameString, () => lib); |
| + if (owner === lib && canNotClashWithMangledPrivateNames(nameString)) { |
| + return nameString; |
| + } |
| + String libName = getName(lib); |
| + // If a library name does not start with the [LIBRARY_PREFIX] then our |
| + // assumptions about clashing with mangled private members does not hold. |
| + assert(libName.startsWith(LIBRARY_PREFIX)); |
| + return '_$libName$nameString'; |
| } else { |
| - return '${name.slowToString()}'; |
| + return name.slowToString(); |
| } |
| } |
| @@ -98,6 +116,8 @@ class Namer { |
| } |
| } |
| + static final String LIBRARY_PREFIX = "lib"; |
| + |
| /** |
| * Returns a preferred JS-id for the given top-level or static element. |
| * The returned id is guaranteed to be a valid JS-id. |
| @@ -123,7 +143,7 @@ class Namer { |
| name = element.name.slowToString(); |
| name = '$name\$${functionElement.parameterCount(compiler)}'; |
| } else if (element.kind === ElementKind.LIBRARY) { |
| - name = 'lib'; |
| + name = LIBRARY_PREFIX; |
| } else { |
| name = element.name.slowToString(); |
| } |