Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
| index b6db3327ebf13fd05e6e3e280e9b4279978bb57c..31f39fd7ff3f3fa9ce858d627bb6e16b70b19bfa 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
| @@ -99,11 +99,6 @@ class Namer implements ClosureNamer { |
| return result; |
| } |
| - String closureInvocationName(Selector selector) { |
| - return instanceMethodInvocationName(null, closureInvocationSelectorName, |
| - selector); |
| - } |
| - |
| String breakLabelName(LabelElement label) { |
| return '\$${label.labelName}\$${label.target.nestingLevel}'; |
| } |
| @@ -126,45 +121,43 @@ class Namer implements ClosureNamer { |
| * If the [name] is not private returns [:name.slowToString():]. Otherwise |
| * mangles the [name] so that each library has a unique name. |
| */ |
| - String privateName(LibraryElement lib, SourceString name) { |
| - String result; |
| - if (name.isPrivate()) { |
| - String nameString = name.slowToString(); |
| - // The first library asking for a short private name wins. |
| - LibraryElement owner = shouldMinify ? |
| - lib : |
| - shortPrivateNameOwners.putIfAbsent(nameString, () => lib); |
| - // If a private name could clash with a mangled private name we don't |
| - // use the short name. For example a private name "_lib3_foo" would |
| - // clash with "_foo" from "lib3". |
| - if (owner == lib && |
| - !nameString.startsWith('_$LIBRARY_PREFIX') && |
| - !shouldMinify) { |
| - result = nameString; |
| - } else { |
| - String libName = getName(lib); |
| - // If a library name does not start with the [LIBRARY_PREFIX] then our |
| - // assumptions about clashing with mangled private members do not hold. |
| - assert(shouldMinify || libName.startsWith(LIBRARY_PREFIX)); |
| - // TODO(erikcorry): Fix this with other manglings to avoid clashes. |
| - result = '_lib$libName\$$nameString'; |
| - } |
| - } else { |
| - result = name.slowToString(); |
| + String privateName(LibraryElement library, SourceString name) { |
| + // Public names are easy. |
| + String nameString = name.slowToString(); |
| + if (!name.isPrivate()) return nameString; |
| + |
| + // The first library asking for a short private name wins. |
| + LibraryElement owner = shouldMinify |
| + ? library |
| + : shortPrivateNameOwners.putIfAbsent(nameString, () => library); |
| + |
| + // If a private name could clash with a mangled private name we don't |
| + // use the short name. For example a private name "_lib3_foo" would |
| + // clash with "_foo" from "lib3". |
| + if (owner == library && |
| + !nameString.startsWith('_$LIBRARY_PREFIX') && |
| + !shouldMinify) { |
| + return nameString; |
| } |
| - return result; |
| + |
| + // If a library name does not start with the [LIBRARY_PREFIX] then our |
| + // assumptions about clashing with mangled private members do not hold. |
| + String libraryName = getName(library); |
| + assert(shouldMinify || libraryName.startsWith(LIBRARY_PREFIX)); |
| + // TODO(erikcorry): Fix this with other manglings to avoid clashes. |
| + return '_library$libraryName\$$nameString'; |
|
ngeoffray
2013/01/11 10:29:11
Note that you just changed the name to start with
|
| } |
| String instanceMethodName(FunctionElement element) { |
| SourceString name = Elements.operatorNameToIdentifier(element.name); |
| - LibraryElement lib = element.getLibrary(); |
| + LibraryElement library = element.getLibrary(); |
| if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| ConstructorBodyElement bodyElement = element; |
| name = bodyElement.constructor.name; |
| } |
| FunctionSignature signature = element.computeSignature(compiler); |
| String methodName = |
| - '${privateName(lib, name)}\$${signature.parameterCount}'; |
| + '${privateName(library, name)}\$${signature.parameterCount}'; |
| if (signature.optionalParametersAreNamed && |
| !signature.optionalParameters.isEmpty) { |
| StringBuffer buffer = new StringBuffer(); |
| @@ -188,41 +181,39 @@ class Namer implements ClosureNamer { |
| return getMappedInstanceName(proposedName); |
| } |
| - String instanceMethodInvocationName(LibraryElement lib, SourceString name, |
| - Selector selector) { |
| - name = Elements.operatorNameToIdentifier(name); |
| - // TODO(floitsch): mangle, while preserving uniqueness. |
| - StringBuffer buffer = new StringBuffer(); |
| - List<SourceString> names = selector.getOrderedNamedArguments(); |
| - for (SourceString argumentName in names) { |
| - buffer.add(r'$'); |
| - argumentName.printOn(buffer); |
| - } |
| - if (name == closureInvocationSelectorName) { |
| - // We don't mangle the closure invoking function name because it is |
| - // generated in by string concatenation applyFunction from js_helper.dart. |
| - return '$closureInvocationSelectorName\$${selector.argumentCount}$buffer'; |
| + String invocationName(Selector selector) { |
| + if (selector.isGetter()) { |
| + String proposedName = privateName(selector.library, selector.name); |
| + return 'get\$${getMappedInstanceName(proposedName)}'; |
| + } else if (selector.isSetter()) { |
| + String proposedName = privateName(selector.library, selector.name); |
| + return 'set\$${getMappedInstanceName(proposedName)}'; |
| + } else { |
| + assert(selector.isCall()); |
| + SourceString name = Elements.operatorNameToIdentifier(selector.name); |
| + StringBuffer buffer = new StringBuffer(); |
| + for (SourceString argumentName in selector.getOrderedNamedArguments()) { |
| + buffer.add(r'$'); |
| + argumentName.printOn(buffer); |
| + } |
| + String suffix = '\$${selector.argumentCount}$buffer'; |
| + // We don't mangle the closure invoking function name because it |
| + // is generated in by string concatenation applyFunction from |
|
ngeoffray
2013/01/11 10:29:11
in by string concatenation applyFunction -> by str
|
| + // js_helper.dart. |
| + if (selector.isClosureCall()) return "$name$suffix"; |
| + String proposedName = privateName(selector.library, name); |
| + return getMappedInstanceName('$proposedName$suffix'); |
| } |
| - return getMappedInstanceName( |
| - '${privateName(lib, name)}\$${selector.argumentCount}$buffer'); |
| } |
| /** |
| * Returns the internal name used for an invocation mirror of this selector. |
| */ |
| - String invocationMirrorInternalName(Selector selector) { |
| - if (selector.isGetter()) { |
| - return getterName(selector.library, selector.name); |
| - } else if (selector.isSetter()) { |
| - return setterName(selector.library, selector.name); |
| - } else { |
| - return instanceMethodInvocationName( |
| - selector.library, selector.name, selector); |
| - } |
| - } |
| + String invocationMirrorInternalName(Selector selector) |
| + => invocationName(selector); |
| - String instanceFieldName(LibraryElement libraryElement, SourceString name) { |
| - String proposedName = privateName(libraryElement, name); |
| + String instanceFieldName(Element element) { |
| + String proposedName = privateName(element.getLibrary(), element.name); |
| return getMappedInstanceName(proposedName); |
| } |
| @@ -239,19 +230,18 @@ class Namer implements ClosureNamer { |
| // this can't happen because we can't inherit from native classes. |
| assert (!fieldElement.hasFixedBackendName()); |
| - ClassElement cls = fieldElement.getEnclosingClass(); |
| - LibraryElement libraryElement = fieldElement.getLibrary(); |
| - String libName = getName(libraryElement); |
| - String clsName = getName(cls); |
| - String instanceName = instanceFieldName(libraryElement, fieldElement.name); |
| - return getMappedInstanceName('$libName\$$clsName\$$instanceName'); |
| + String libraryName = getName(fieldElement.getLibrary()); |
| + String className = getName(fieldElement.getEnclosingClass()); |
| + String instanceName = instanceFieldName(fieldElement); |
| + return getMappedInstanceName('$libraryName\$$className\$$instanceName'); |
| } |
| - String setterName(LibraryElement lib, SourceString name) { |
| + String setterName(Element element) { |
| // We dynamically create setters from the field-name. The setter name must |
| // therefore be derived from the instance field-name. |
| - String fieldName = getMappedInstanceName(privateName(lib, name)); |
| - return 'set\$$fieldName'; |
| + LibraryElement library = element.getLibrary(); |
| + String name = getMappedInstanceName(privateName(library, element.name)); |
| + return 'set\$$name'; |
| } |
| String setterNameFromAccessorName(String name) { |
| @@ -273,11 +263,12 @@ class Namer implements ClosureNamer { |
| return 'get\$$name'; |
| } |
| - String getterName(LibraryElement lib, SourceString name) { |
| + String getterName(Element element) { |
| // We dynamically create getters from the field-name. The getter name must |
| // therefore be derived from the instance field-name. |
| - String fieldName = getMappedInstanceName(privateName(lib, name)); |
| - return 'get\$$fieldName'; |
| + LibraryElement library = element.getLibrary(); |
| + String name = getMappedInstanceName(privateName(library, element.name)); |
| + return 'get\$$name'; |
| } |
| String getMappedGlobalName(String proposedName) { |
| @@ -328,7 +319,6 @@ class Namer implements ClosureNamer { |
| */ |
| String _computeGuess(Element element) { |
| assert(!element.isInstanceMember()); |
| - LibraryElement lib = element.getLibrary(); |
| String name; |
| if (element.isGenerativeConstructor()) { |
| if (element.name == element.getEnclosingClass().name) { |
| @@ -401,11 +391,11 @@ class Namer implements ClosureNamer { |
| || element.kind == ElementKind.FUNCTION) { |
| return instanceMethodName(element); |
| } else if (element.kind == ElementKind.GETTER) { |
| - return getterName(element.getLibrary(), element.name); |
| + return getterName(element); |
| } else if (element.kind == ElementKind.SETTER) { |
| - return setterName(element.getLibrary(), element.name); |
| + return setterName(element); |
| } else if (element.kind == ElementKind.FIELD) { |
| - return instanceFieldName(element.getLibrary(), element.name); |
| + return instanceFieldName(element); |
| } else { |
| compiler.internalError('getName for bad kind: ${element.kind}', |
| node: element.parseNode(compiler)); |