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

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

Issue 10861016: Introduce renameNodes helper to factor out common pattern. (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 renameNodes(Collection<Node> nodes, renamer) {
54 renames[node] = ''; 54 for (Node node in nodes) {
55 }); 55 renames[node] = renamer(node);
56 placeholderCollector.unresolvedNodes.forEach((Node node) { 56 }
57 renames[node] = generateUniqueName('Unresolved'); 57 }
58 }); 58
59 renameNodes(placeholderCollector.nullNodes, (_) => '');
Roman 2012/08/21 08:02:44 did you use '_' instead of 'node' to save 3 chars
Anton Muhin 2012/08/21 09:11:10 That's the common idiom to mark unused argument.
60 renameNodes(placeholderCollector.unresolvedNodes,
61 (_) => generateUniqueName('Unresolved'));
59 placeholderCollector.elementNodes.forEach( 62 placeholderCollector.elementNodes.forEach(
60 (Element element, Set<Node> nodes) { 63 (Element element, Set<Node> nodes) {
61 String renamedElement = renameElement(element); 64 String renamedElement = renameElement(element);
62 nodes.forEach((Node node) { 65 renameNodes(nodes, (_) => renamedElement);
63 renames[node] = renamedElement;
64 });
65 }); 66 });
66 placeholderCollector.localPlaceholders.forEach( 67 placeholderCollector.localPlaceholders.forEach(
67 (FunctionElement element, Set<LocalPlaceholder> localPlaceholders) { 68 (FunctionElement element, Set<LocalPlaceholder> localPlaceholders) {
68 // TODO(smok): Check for conflicts with class fields and take usages 69 // TODO(smok): Check for conflicts with class fields and take usages
69 // into account. 70 // into account.
70 localPlaceholders.forEach((LocalPlaceholder placeholder) { 71 localPlaceholders.forEach((LocalPlaceholder placeholder) {
71 placeholder.nodes.forEach((Node node) { 72 renameNodes(placeholder.nodes, (_) => placeholder.identifier);
72 renames[node] = placeholder.identifier;
73 });
74 }); 73 });
75 }); 74 });
76 placeholderCollector.privateNodes.forEach( 75 placeholderCollector.privateNodes.forEach(
77 (LibraryElement library, Set<Identifier> nodes) { 76 (LibraryElement library, Set<Identifier> nodes) {
78 nodes.forEach((Identifier node) { 77 renameNodes(nodes, (node) =>
79 renames[node] = 78 renamePrivateIdentifier(library, node.source.slowToString()));
80 renamePrivateIdentifier(library, node.source.slowToString());
81 });
82 }); 79 });
83 } 80 }
84 81
85 typedef String Generator(String originalName, bool isForbidden(String name)); 82 typedef String Generator(String originalName, bool isForbidden(String name));
86 83
87 /** Always tries to return original identifier name unless it is forbidden. */ 84 /** Always tries to return original identifier name unless it is forbidden. */
88 String conservativeGenerator( 85 String conservativeGenerator(
89 String originalName, bool isForbidden(String name)) { 86 String originalName, bool isForbidden(String name)) {
90 String newName = originalName; 87 String newName = originalName;
91 while (isForbidden(newName)) { 88 while (isForbidden(newName)) {
(...skipping 29 matching lines...) Expand all
121 int length = alphabet.length; 118 int length = alphabet.length;
122 StringBuffer resultBuilder = new StringBuffer(); 119 StringBuffer resultBuilder = new StringBuffer();
123 while (index >= length) { 120 while (index >= length) {
124 resultBuilder.add(alphabet[index % length]); 121 resultBuilder.add(alphabet[index % length]);
125 index ~/= length; 122 index ~/= length;
126 } 123 }
127 resultBuilder.add(alphabet[index]); 124 resultBuilder.add(alphabet[index]);
128 return resultBuilder.toString(); 125 return resultBuilder.toString();
129 } 126 }
130 } 127 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698