| 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 part of dart_backend; | 5 part of dart_backend; |
| 6 | 6 |
| 7 Function get _compareNodes => | 7 Function get _compareNodes => |
| 8 compareBy((n) => n.getBeginToken().charOffset); | 8 compareBy((n) => n.getBeginToken().charOffset); |
| 9 | 9 |
| 10 typedef String _Renamer(Renamable renamable); | 10 typedef String _Renamer(Renamable renamable); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 for (Link<DartType> link = argumentsLink.tail; !link.isEmpty; | 94 for (Link<DartType> link = argumentsLink.tail; !link.isEmpty; |
| 95 link = link.tail) { | 95 link = link.tail) { |
| 96 result.add(','); | 96 result.add(','); |
| 97 result.add(renameType(link.head, renameElement)); | 97 result.add(renameType(link.head, renameElement)); |
| 98 } | 98 } |
| 99 result.add('>'); | 99 result.add('>'); |
| 100 } | 100 } |
| 101 return result.toString(); | 101 return result.toString(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 String renameConstructor(Element element, DartType type, | 104 String renameConstructor(Element element, ConstructorPlaceholder placeholder, |
| 105 Function renameString, Function renameElement) { | 105 Function renameString, Function renameElement) { |
| 106 assert(element.isConstructor()); | 106 assert(element.isConstructor()); |
| 107 StringBuffer result = new StringBuffer(); | 107 StringBuffer result = new StringBuffer(); |
| 108 String name = element.name.slowToString(); | 108 String name = element.name.slowToString(); |
| 109 if (element.name != element.getEnclosingClass().name) { | 109 if (element.name != element.getEnclosingClass().name) { |
| 110 // Named constructor or factory. Is there a more reliable way to check | 110 // Named constructor or factory. Is there a more reliable way to check |
| 111 // this case? | 111 // this case? |
| 112 result.add(renameType(type, renameElement)); | 112 if (!placeholder.isRedirectingCall) { |
| 113 result.add('.'); | 113 result.add(renameType(placeholder.type, renameElement)); |
| 114 result.add('.'); |
| 115 } |
| 114 String prefix = '${element.getEnclosingClass().name.slowToString()}\$'; | 116 String prefix = '${element.getEnclosingClass().name.slowToString()}\$'; |
| 115 if (!name.startsWith(prefix)) { | 117 if (!name.startsWith(prefix)) { |
| 116 // Factory for another interface (that is going away soon). | 118 // Factory for another interface (that is going away soon). |
| 117 compiler.internalErrorOnElement(element, | 119 compiler.internalErrorOnElement(element, |
| 118 "Factory constructors for external interfaces are not supported."); | 120 "Factory constructors for external interfaces are not supported."); |
| 119 } | 121 } |
| 120 name = name.substring(prefix.length); | 122 name = name.substring(prefix.length); |
| 121 result.add(name); | 123 result.add(name); |
| 122 } else { | 124 } else { |
| 123 result.add(renameType(type, renameElement)); | 125 assert(!placeholder.isRedirectingCall); |
| 126 result.add(renameType(placeholder.type, renameElement)); |
| 124 } | 127 } |
| 125 return result.toString(); | 128 return result.toString(); |
| 126 } | 129 } |
| 127 | 130 |
| 128 Function makeElementRenamer(rename, generateUniqueName) => (element) { | 131 Function makeElementRenamer(rename, generateUniqueName) => (element) { |
| 129 assert(Elements.isStaticOrTopLevel(element) | 132 assert(Elements.isStaticOrTopLevel(element) |
| 130 || element is TypeVariableElement); | 133 || element is TypeVariableElement); |
| 131 // TODO(smok): We may want to reuse class static field and method names. | 134 // TODO(smok): We may want to reuse class static field and method names. |
| 132 String originalName = element.name.slowToString(); | 135 String originalName = element.name.slowToString(); |
| 133 LibraryElement library = element.getLibrary(); | 136 LibraryElement library = element.getLibrary(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 identifier, usedMemberIdentifiers.contains); | 277 identifier, usedMemberIdentifiers.contains); |
| 275 renameNodes(nodes, (_) => newIdentifier); | 278 renameNodes(nodes, (_) => newIdentifier); |
| 276 }); | 279 }); |
| 277 } | 280 } |
| 278 | 281 |
| 279 // Rename constructors. | 282 // Rename constructors. |
| 280 placeholderCollector.constructorPlaceholders.forEach( | 283 placeholderCollector.constructorPlaceholders.forEach( |
| 281 (Element constructor, List<ConstructorPlaceholder> placeholders) { | 284 (Element constructor, List<ConstructorPlaceholder> placeholders) { |
| 282 for (ConstructorPlaceholder ph in placeholders) { | 285 for (ConstructorPlaceholder ph in placeholders) { |
| 283 renames[ph.node] = | 286 renames[ph.node] = |
| 284 renameConstructor(constructor, ph.type, rename, renameElement); | 287 renameConstructor(constructor, ph, rename, renameElement); |
| 285 } | 288 } |
| 286 }); | 289 }); |
| 287 sortedForEach(placeholderCollector.privateNodes, (library, nodes) { | 290 sortedForEach(placeholderCollector.privateNodes, (library, nodes) { |
| 288 renameNodes(nodes, (node) => rename(library, node.source.slowToString())); | 291 renameNodes(nodes, (node) => rename(library, node.source.slowToString())); |
| 289 }); | 292 }); |
| 290 renameNodes(placeholderCollector.unresolvedNodes, | 293 renameNodes(placeholderCollector.unresolvedNodes, |
| 291 (_) => generateUniqueName('Unresolved')); | 294 (_) => generateUniqueName('Unresolved')); |
| 292 renameNodes(placeholderCollector.nullNodes, (_) => ''); | 295 renameNodes(placeholderCollector.nullNodes, (_) => ''); |
| 293 if (cutDeclarationTypes) { | 296 if (cutDeclarationTypes) { |
| 294 for (DeclarationTypePlaceholder placeholder in | 297 for (DeclarationTypePlaceholder placeholder in |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 index ~/= firstCharAlphabet.length; | 344 index ~/= firstCharAlphabet.length; |
| 342 int length = otherCharsAlphabet.length; | 345 int length = otherCharsAlphabet.length; |
| 343 while (index >= length) { | 346 while (index >= length) { |
| 344 resultBuilder.add(otherCharsAlphabet[index % length]); | 347 resultBuilder.add(otherCharsAlphabet[index % length]); |
| 345 index ~/= length; | 348 index ~/= length; |
| 346 } | 349 } |
| 347 resultBuilder.add(otherCharsAlphabet[index]); | 350 resultBuilder.add(otherCharsAlphabet[index]); |
| 348 return resultBuilder.toString(); | 351 return resultBuilder.toString(); |
| 349 } | 352 } |
| 350 } | 353 } |
| OLD | NEW |