Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: lib/compiler/implementation/dart_backend/renamer.dart

Issue 11345031: [dart2dart] Support cosntructor redirects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix dart_backend_test Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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) {
Anton Muhin 2012/10/30 15:23:44 where do we add super./this. prefix?
Roman 2012/10/30 15:52:09 Nowhere, the placeholder is placed for selector no
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 if (placeholder.isRedirectingCall) throw 'e';
Anton Muhin 2012/10/30 15:23:44 isn't assert enough?
Roman 2012/10/30 15:52:09 Sorry, that was my way to ensure that placeholder
127 result.add(renameType(placeholder.type, renameElement));
124 } 128 }
125 return result.toString(); 129 return result.toString();
126 } 130 }
127 131
128 Function makeElementRenamer(rename, generateUniqueName) => (element) { 132 Function makeElementRenamer(rename, generateUniqueName) => (element) {
129 assert(Elements.isStaticOrTopLevel(element) 133 assert(Elements.isStaticOrTopLevel(element)
130 || element is TypeVariableElement); 134 || element is TypeVariableElement);
131 // TODO(smok): We may want to reuse class static field and method names. 135 // TODO(smok): We may want to reuse class static field and method names.
132 String originalName = element.name.slowToString(); 136 String originalName = element.name.slowToString();
133 LibraryElement library = element.getLibrary(); 137 LibraryElement library = element.getLibrary();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 identifier, usedMemberIdentifiers.contains); 278 identifier, usedMemberIdentifiers.contains);
275 renameNodes(nodes, (_) => newIdentifier); 279 renameNodes(nodes, (_) => newIdentifier);
276 }); 280 });
277 } 281 }
278 282
279 // Rename constructors. 283 // Rename constructors.
280 placeholderCollector.constructorPlaceholders.forEach( 284 placeholderCollector.constructorPlaceholders.forEach(
281 (Element constructor, List<ConstructorPlaceholder> placeholders) { 285 (Element constructor, List<ConstructorPlaceholder> placeholders) {
282 for (ConstructorPlaceholder ph in placeholders) { 286 for (ConstructorPlaceholder ph in placeholders) {
283 renames[ph.node] = 287 renames[ph.node] =
284 renameConstructor(constructor, ph.type, rename, renameElement); 288 renameConstructor(constructor, ph, rename, renameElement);
285 } 289 }
286 }); 290 });
287 sortedForEach(placeholderCollector.privateNodes, (library, nodes) { 291 sortedForEach(placeholderCollector.privateNodes, (library, nodes) {
288 renameNodes(nodes, (node) => rename(library, node.source.slowToString())); 292 renameNodes(nodes, (node) => rename(library, node.source.slowToString()));
289 }); 293 });
290 renameNodes(placeholderCollector.unresolvedNodes, 294 renameNodes(placeholderCollector.unresolvedNodes,
291 (_) => generateUniqueName('Unresolved')); 295 (_) => generateUniqueName('Unresolved'));
292 renameNodes(placeholderCollector.nullNodes, (_) => ''); 296 renameNodes(placeholderCollector.nullNodes, (_) => '');
293 if (cutDeclarationTypes) { 297 if (cutDeclarationTypes) {
294 for (DeclarationTypePlaceholder placeholder in 298 for (DeclarationTypePlaceholder placeholder in
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 index ~/= firstCharAlphabet.length; 345 index ~/= firstCharAlphabet.length;
342 int length = otherCharsAlphabet.length; 346 int length = otherCharsAlphabet.length;
343 while (index >= length) { 347 while (index >= length) {
344 resultBuilder.add(otherCharsAlphabet[index % length]); 348 resultBuilder.add(otherCharsAlphabet[index % length]);
345 index ~/= length; 349 index ~/= length;
346 } 350 }
347 resultBuilder.add(otherCharsAlphabet[index]); 351 resultBuilder.add(otherCharsAlphabet[index]);
348 return resultBuilder.toString(); 352 return resultBuilder.toString();
349 } 353 }
350 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698