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

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

Issue 10834416: Rename elements after sorting. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months 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 /** 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 void renamePlaceholders( 9 void renamePlaceholders(
10 Compiler compiler, 10 Compiler compiler,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if (isDartCoreLib(compiler, library)) { 43 if (isDartCoreLib(compiler, library)) {
44 final prefix = 44 final prefix =
45 imports.putIfAbsent(library, () => generateUniqueName('p')); 45 imports.putIfAbsent(library, () => generateUniqueName('p'));
46 return '$prefix.$originalName'; 46 return '$prefix.$originalName';
47 } 47 }
48 48
49 return getName(library, originalName, 49 return getName(library, originalName,
50 () => generateUniqueName(originalName)); 50 () => generateUniqueName(originalName));
51 } 51 }
52 52
53 placeholderCollector.nullNodes.forEach((Node node) { 53 for (Node node in placeholderCollector.nullNodes) {
54 renames[node] = ''; 54 renames[node] = '';
55 }
56 for (Node node in placeholderCollector.unresolvedNodes) {
Roman 2012/08/21 07:59:46 Should we use sortedForEach here too? Otherwise it
Anton Muhin 2012/08/21 10:15:26 Okay. I'll implement somewhat suboptimal solution
57 renames[node] = generateUniqueName('Unresolved');
58 }
59
60 sortedForEach(mapping, f) {
Roman 2012/08/21 07:59:46 Great method, but can you please make it more read
Anton Muhin 2012/08/21 10:15:26 Done.
61 for (final e in sortElements(mapping.getKeys())) f(e, mapping[e]);
62 }
63
64 sortedForEach(placeholderCollector.elementNodes, (element, nodes) {
65 String newName = renameElement(element);
66 for (Node node in nodes) {
67 renames[node] = newName;
68 }
55 }); 69 });
56 placeholderCollector.unresolvedNodes.forEach((Node node) { 70 sortedForEach(placeholderCollector.localPlaceholders,
57 renames[node] = generateUniqueName('Unresolved'); 71 (element, placeholders) {
72 // TODO(smok): Check for conflicts with class fields and take usages
73 // into account.
74 for (LocalPlaceholder placeholder in placeholders) {
75 for (Node node in placeholder.nodes) {
76 renames[node] = placeholder.identifier;
77 }
78 }
58 }); 79 });
59 placeholderCollector.elementNodes.forEach( 80 sortedForEach(placeholderCollector.privateNodes, (library, nodes) {
60 (Element element, Set<Node> nodes) { 81 for (Node node in nodes) {
61 String renamedElement = renameElement(element); 82 renames[node] =
62 nodes.forEach((Node node) { 83 renamePrivateIdentifier(library, node.source.slowToString());
63 renames[node] = renamedElement; 84 }
64 });
65 });
66 placeholderCollector.localPlaceholders.forEach(
67 (FunctionElement element, Set<LocalPlaceholder> localPlaceholders) {
68 // TODO(smok): Check for conflicts with class fields and take usages
69 // into account.
70 localPlaceholders.forEach((LocalPlaceholder placeholder) {
71 placeholder.nodes.forEach((Node node) {
72 renames[node] = placeholder.identifier;
73 });
74 });
75 });
76 placeholderCollector.privateNodes.forEach(
77 (LibraryElement library, Set<Identifier> nodes) {
78 nodes.forEach((Identifier node) {
79 renames[node] =
80 renamePrivateIdentifier(library, node.source.slowToString());
81 });
82 }); 85 });
83 } 86 }
84 87
85 typedef String Generator(String originalName, bool isForbidden(String name)); 88 typedef String Generator(String originalName, bool isForbidden(String name));
86 89
87 /** Always tries to return original identifier name unless it is forbidden. */ 90 /** Always tries to return original identifier name unless it is forbidden. */
88 String conservativeGenerator( 91 String conservativeGenerator(
89 String originalName, bool isForbidden(String name)) { 92 String originalName, bool isForbidden(String name)) {
90 String newName = originalName; 93 String newName = originalName;
91 while (isForbidden(newName)) { 94 while (isForbidden(newName)) {
(...skipping 29 matching lines...) Expand all
121 int length = alphabet.length; 124 int length = alphabet.length;
122 StringBuffer resultBuilder = new StringBuffer(); 125 StringBuffer resultBuilder = new StringBuffer();
123 while (index >= length) { 126 while (index >= length) {
124 resultBuilder.add(alphabet[index % length]); 127 resultBuilder.add(alphabet[index % length]);
125 index ~/= length; 128 index ~/= length;
126 } 129 }
127 resultBuilder.add(alphabet[index]); 130 resultBuilder.add(alphabet[index]);
128 return resultBuilder.toString(); 131 return resultBuilder.toString();
129 } 132 }
130 } 133 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/backend.dart ('k') | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698