| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 f(element, map[element]); | 82 f(element, map[element]); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 String renameType(DartType type, Function renameElement) { | 86 String renameType(DartType type, Function renameElement) { |
| 87 // TODO(smok): Do not rename type if it is in platform library or | 87 // TODO(smok): Do not rename type if it is in platform library or |
| 88 // js-helpers. | 88 // js-helpers. |
| 89 StringBuffer result = new StringBuffer(renameElement(type.element)); | 89 StringBuffer result = new StringBuffer(renameElement(type.element)); |
| 90 if (type is InterfaceType) { | 90 if (type is InterfaceType) { |
| 91 if (!type.isRaw) { | 91 if (!type.isRaw) { |
| 92 result.add('<'); | 92 result.write('<'); |
| 93 Link<DartType> argumentsLink = type.typeArguments; | 93 Link<DartType> argumentsLink = type.typeArguments; |
| 94 result.add(renameType(argumentsLink.head, renameElement)); | 94 result.write(renameType(argumentsLink.head, renameElement)); |
| 95 for (Link<DartType> link = argumentsLink.tail; !link.isEmpty; | 95 for (Link<DartType> link = argumentsLink.tail; !link.isEmpty; |
| 96 link = link.tail) { | 96 link = link.tail) { |
| 97 result.add(','); | 97 result.write(','); |
| 98 result.add(renameType(link.head, renameElement)); | 98 result.write(renameType(link.head, renameElement)); |
| 99 } | 99 } |
| 100 result.add('>'); | 100 result.write('>'); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 return result.toString(); | 103 return result.toString(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 String renameConstructor(Element element, ConstructorPlaceholder placeholder, | 106 String renameConstructor(Element element, ConstructorPlaceholder placeholder, |
| 107 Function renameString, Function renameElement) { | 107 Function renameString, Function renameElement) { |
| 108 assert(element.isConstructor()); | 108 assert(element.isConstructor()); |
| 109 StringBuffer result = new StringBuffer(); | 109 StringBuffer result = new StringBuffer(); |
| 110 String name = element.name.slowToString(); | 110 String name = element.name.slowToString(); |
| 111 if (element.name != element.getEnclosingClass().name) { | 111 if (element.name != element.getEnclosingClass().name) { |
| 112 // Named constructor or factory. Is there a more reliable way to check | 112 // Named constructor or factory. Is there a more reliable way to check |
| 113 // this case? | 113 // this case? |
| 114 if (!placeholder.isRedirectingCall) { | 114 if (!placeholder.isRedirectingCall) { |
| 115 result.add(renameType(placeholder.type, renameElement)); | 115 result.write(renameType(placeholder.type, renameElement)); |
| 116 result.add('.'); | 116 result.write('.'); |
| 117 } | 117 } |
| 118 String prefix = '${element.getEnclosingClass().name.slowToString()}\$'; | 118 String prefix = '${element.getEnclosingClass().name.slowToString()}\$'; |
| 119 if (!name.startsWith(prefix)) { | 119 if (!name.startsWith(prefix)) { |
| 120 // Factory for another interface (that is going away soon). | 120 // Factory for another interface (that is going away soon). |
| 121 compiler.internalErrorOnElement(element, | 121 compiler.internalErrorOnElement(element, |
| 122 "Factory constructors for external interfaces are not supported."); | 122 "Factory constructors for external interfaces are not supported."); |
| 123 } | 123 } |
| 124 name = name.substring(prefix.length); | 124 name = name.substring(prefix.length); |
| 125 if (!element.getLibrary().isPlatformLibrary) { | 125 if (!element.getLibrary().isPlatformLibrary) { |
| 126 name = renameString(element.getLibrary(), name); | 126 name = renameString(element.getLibrary(), name); |
| 127 } | 127 } |
| 128 result.add(name); | 128 result.write(name); |
| 129 } else { | 129 } else { |
| 130 assert(!placeholder.isRedirectingCall); | 130 assert(!placeholder.isRedirectingCall); |
| 131 result.add(renameType(placeholder.type, renameElement)); | 131 result.write(renameType(placeholder.type, renameElement)); |
| 132 } | 132 } |
| 133 return result.toString(); | 133 return result.toString(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 Function makeElementRenamer(rename, generateUniqueName) => (element) { | 136 Function makeElementRenamer(rename, generateUniqueName) => (element) { |
| 137 assert(Elements.isErroneousElement(element) || | 137 assert(Elements.isErroneousElement(element) || |
| 138 Elements.isStaticOrTopLevel(element) || | 138 Elements.isStaticOrTopLevel(element) || |
| 139 element is TypeVariableElement); | 139 element is TypeVariableElement); |
| 140 // TODO(smok): We may want to reuse class static field and method names. | 140 // TODO(smok): We may want to reuse class static field and method names. |
| 141 String originalName = element.name.slowToString(); | 141 String originalName = element.name.slowToString(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 * Generates next mini ID with current index and alphabet. | 339 * Generates next mini ID with current index and alphabet. |
| 340 * Advances current index. | 340 * Advances current index. |
| 341 * In other words, it converts index to visual representation | 341 * In other words, it converts index to visual representation |
| 342 * as if digits are given characters. | 342 * as if digits are given characters. |
| 343 */ | 343 */ |
| 344 String getNextId() { | 344 String getNextId() { |
| 345 // It's like converting index in decimal to [chars] radix. | 345 // It's like converting index in decimal to [chars] radix. |
| 346 int index = nextIdIndex++; | 346 int index = nextIdIndex++; |
| 347 StringBuffer resultBuilder = new StringBuffer(); | 347 StringBuffer resultBuilder = new StringBuffer(); |
| 348 if (index < firstCharAlphabet.length) return firstCharAlphabet[index]; | 348 if (index < firstCharAlphabet.length) return firstCharAlphabet[index]; |
| 349 resultBuilder.add(firstCharAlphabet[index % firstCharAlphabet.length]); | 349 resultBuilder.write(firstCharAlphabet[index % firstCharAlphabet.length]); |
| 350 index ~/= firstCharAlphabet.length; | 350 index ~/= firstCharAlphabet.length; |
| 351 int length = otherCharsAlphabet.length; | 351 int length = otherCharsAlphabet.length; |
| 352 while (index >= length) { | 352 while (index >= length) { |
| 353 resultBuilder.add(otherCharsAlphabet[index % length]); | 353 resultBuilder.write(otherCharsAlphabet[index % length]); |
| 354 index ~/= length; | 354 index ~/= length; |
| 355 } | 355 } |
| 356 resultBuilder.add(otherCharsAlphabet[index]); | 356 resultBuilder.write(otherCharsAlphabet[index]); |
| 357 return resultBuilder.toString(); | 357 return resultBuilder.toString(); |
| 358 } | 358 } |
| 359 } | 359 } |
| OLD | NEW |