Chromium Code Reviews| 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 extends Renamer { | 9 class ConflictingRenamer extends Renamer { |
| 10 final Compiler compiler; | 10 final Compiler compiler; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 if (element.isTopLevel()) { | 36 if (element.isTopLevel()) { |
| 37 return renameElement(element); | 37 return renameElement(element); |
| 38 } else if ( | 38 } else if ( |
| 39 (element.isGenerativeConstructor() || element.isFactoryConstructor()) | 39 (element.isGenerativeConstructor() || element.isFactoryConstructor()) |
| 40 && element.asFunctionElement().cachedNode.name is Send | 40 && element.asFunctionElement().cachedNode.name is Send |
| 41 // Don't want to rename redirects to :this(args). | 41 // Don't want to rename redirects to :this(args). |
| 42 && !Initializers.isConstructorRedirect(send) | 42 && !Initializers.isConstructorRedirect(send) |
| 43 // Don't want to rename super calls. | 43 // Don't want to rename super calls. |
| 44 && !Initializers.isSuperConstructorCall(send)) { | 44 && !Initializers.isSuperConstructorCall(send)) { |
| 45 FunctionExpression constructor = element.asFunctionElement().cachedNode; | 45 FunctionExpression constructor = element.asFunctionElement().cachedNode; |
| 46 return '${renameType(element.getEnclosingClass().type)}' | 46 TypeAnnotation typeAnnotation; |
| 47 '.${getFactoryName(constructor)}'; | 47 if (send.selector is TypeAnnotation) { |
|
Roman
2012/07/31 15:35:39
Please add comments for these ifs about what origi
Anton Muhin
2012/07/31 15:46:47
Done.
| |
| 48 typeAnnotation = send.selector; | |
| 49 } else if (send.selector.receiver is TypeAnnotation) { | |
| 50 typeAnnotation = send.selector.receiver; | |
| 51 } else { | |
| 52 compiler.cancel( | |
| 53 reason: "Don't know how to deduce type", | |
| 54 element: element, | |
| 55 node: send); | |
| 56 } | |
| 57 final type = new Unparser(this).unparse(typeAnnotation); | |
| 58 return '$type.${getFactoryName(constructor)}'; | |
| 48 } else { | 59 } else { |
| 49 return null; | 60 return null; |
| 50 } | 61 } |
| 51 } | 62 } |
| 52 | 63 |
| 53 String renameTypeName(TypeAnnotation typeAnnotation) { | 64 String renameTypeName(TypeAnnotation typeAnnotation) { |
| 54 Type type; | 65 Type type; |
| 55 if (context.isClass()) { | 66 if (context.isClass()) { |
| 56 // This only happens if we're unparsing class declaration. | 67 // This only happens if we're unparsing class declaration. |
| 57 type = new TypeResolver(compiler) | 68 type = new TypeResolver(compiler) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 final library = element.getLibrary(); | 111 final library = element.getLibrary(); |
| 101 if (library === compiler.coreLibrary) return originalName; | 112 if (library === compiler.coreLibrary) return originalName; |
| 102 if (isDartCoreLib(compiler, library)) { | 113 if (isDartCoreLib(compiler, library)) { |
| 103 final prefix = | 114 final prefix = |
| 104 imports.putIfAbsent(library, () => generateUniqueName('p')); | 115 imports.putIfAbsent(library, () => generateUniqueName('p')); |
| 105 return '$prefix.$originalName'; | 116 return '$prefix.$originalName'; |
| 106 } | 117 } |
| 107 return renamed[element] = generateUniqueName(originalName); | 118 return renamed[element] = generateUniqueName(originalName); |
| 108 } | 119 } |
| 109 } | 120 } |
| OLD | NEW |