Chromium Code Reviews| Index: lib/compiler/implementation/dart_backend/renamer.dart |
| diff --git a/lib/compiler/implementation/dart_backend/renamer.dart b/lib/compiler/implementation/dart_backend/renamer.dart |
| index da1bd9f59aacba0037408ff13a2d6ba599a10a91..9220504a39a1741441547f7f847ae85090338941 100644 |
| --- a/lib/compiler/implementation/dart_backend/renamer.dart |
| +++ b/lib/compiler/implementation/dart_backend/renamer.dart |
| @@ -4,7 +4,7 @@ |
| /** |
| * Renames only top-level elements that would let to ambiguity if not renamed. |
| - * TODO(smok): Make sure that top-level fields and methods correctly renamed. |
| + * TODO(smok): Make sure that top-level fields are correctly renamed. |
| */ |
| class ConflictingRenamer extends Renamer { |
| final Compiler compiler; |
| @@ -25,39 +25,42 @@ class ConflictingRenamer extends Renamer { |
| contextElements = resolvedElements[element]; |
| } |
| - String renameSendMethod(Send send) { |
| - // Rename only if this Send is a function call. |
| - if (contextElements[send] !== null && contextElements[send].isFunction()) { |
| - return renameElement(contextElements[send]); |
| - } else { |
| - return null; |
| - } |
| + String getFactoryName(FunctionExpression node) { |
|
Anton Muhin
2012/07/27 11:15:34
nit: arrow syntax? here and below
Roman
2012/07/27 11:32:45
Done.
|
| + return node.name.asSend().selector.asIdentifier().source.slowToString(); |
| } |
| - String renameTypeName(TypeAnnotation typeAnnotation) { |
| - if (contextElements === null |
| - || contextElements.getType(typeAnnotation) === null) { |
| - // We have no info about this type from resolver. |
| - // This happens for class member fields. |
| - // TODO(smok): Maybe resolver should have this information, fix if so. |
| - if (context.isField() |
| - && context.variables.computeType(compiler) !== null) { |
| - // A field. |
| - return renameType(context.variables.type); |
| + bool isNamedConstructor(Element element) { |
| + return element.isGenerativeConstructor() |
| + && element.asFunctionElement().cachedNode.name is Send; |
| + } |
| + |
| + String renameSendMethod(Send send) { |
| + if (contextElements[send] === null) { |
|
Anton Muhin
2012/07/27 11:15:34
nit: single line
Roman
2012/07/27 11:32:45
Done.
|
| + return null; |
| + } else { |
| + Element element = contextElements[send]; |
| + if (element.isTopLevel()) { |
| + return renameElement(element); |
| + } else if (isNamedConstructor(element) |
| + && !Initializers.isConstructorRedirect(send) |
|
Anton Muhin
2012/07/27 11:15:34
why those &&! conditions?
Roman
2012/07/27 11:32:45
We don't want to rename redirects to this(arg) in
|
| + && !Initializers.isSuperConstructorCall(send)) { |
| + FunctionExpression constructor = element.asFunctionElement().cachedNode; |
| + return '${renameType(element.getEnclosingClass().type)}' |
| + '.${getFactoryName(constructor)}'; |
| } else { |
| - return typeAnnotation.typeName.unparse(); |
| + return null; |
| } |
| } |
| + } |
| - // TODO(smok): Check if resolver can help us identifying factory |
| - // constructors. |
| - Type type = contextElements.getType(typeAnnotation); |
| - if (typeAnnotation.typeName is Send |
| - && typeAnnotation.typeName.receiver.source.slowToString() |
| - == type.name.slowToString()) { |
| - // Got factory invocation. Need to rename first part. |
| - return "${renameType(type)}." |
| - "${typeAnnotation.typeName.selector.source.slowToString()}"; |
| + String renameTypeName(TypeAnnotation typeAnnotation) { |
| + Type type; |
| + if (context.isClass()) { |
| + // This only happens if we're unparsing class declaration. |
| + type = new TypeResolver(compiler) |
| + .resolveTypeAnnotation(typeAnnotation, null, context); |
| + } else { |
| + type = compiler.resolveTypeAnnotation(context, typeAnnotation); |
| } |
| return renameType(type); |
| } |
| @@ -66,8 +69,8 @@ class ConflictingRenamer extends Renamer { |
| String renameIdentifier(Identifier node) { |
| if (context.isGenerativeConstructor()) { |
| - // This is either a factory constructor or simple one. |
| - // TODO(smok): Check if resolver can help us identifying factory |
| + // This is either a named constructor or simple one. |
| + // TODO(smok): Check if resolver can help us identifying named |
| // constructors. |
| var enclosingClass = context.getEnclosingClass(); |
| if (node.token.slowToString() == context.name.slowToString() |