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

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

Issue 23593002: Only emit members in mirror helper symbolsmap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 forbiddenIdentifiers.addAll(Keyword.keywords.keys); 173 forbiddenIdentifiers.addAll(Keyword.keywords.keys);
174 forbiddenIdentifiers.addAll(fixedMemberNames); 174 forbiddenIdentifiers.addAll(fixedMemberNames);
175 generateUniqueName = (_) => 175 generateUniqueName = (_) =>
176 generator.generate((name) => 176 generator.generate((name) =>
177 forbiddenIdentifiers.contains(name) 177 forbiddenIdentifiers.contains(name)
178 || allNamedParameterIdentifiers.contains(name)); 178 || allNamedParameterIdentifiers.contains(name));
179 rename = makeRenamer(generateUniqueName); 179 rename = makeRenamer(generateUniqueName);
180 renameElement = makeElementRenamer(rename, generateUniqueName); 180 renameElement = makeElementRenamer(rename, generateUniqueName);
181 181
182 List<Set<Node>> allLocals = new List<Set<Node>>(); 182 List<Set<Node>> allLocals = new List<Set<Node>>();
183 // If we are using the mirror_helper library we need all names to be 183
184 // globally unique. 184 // Build a sorted (by usage) list of local nodes that will be renamed to
Johnni Winther 2013/08/28 07:04:23 "a sorted ... local nodes" -> "a list sorted by us
zarah 2013/08/28 10:18:14 Done.
185 if (uniqueGlobalNaming) { 185 // the same identifier. So the top-used local variables in all functions
186 //TODO(zarah): Change this so that local variables don't get unique names. 186 // will be renamed first and will all share the same new identifier.
187 for (var functionScope in placeholderCollector.functionScopes.values) { 187 for (var functionScope in placeholderCollector.functionScopes.values) {
188 functionScope.localPlaceholders.forEach( 188 // Add current sorted local identifiers to the whole sorted list
189 (ph) => allLocals.add(ph.nodes.toSet())); 189 // of all local identifiers for all functions.
190 List<LocalPlaceholder> currentSortedPlaceholders =
191 sorted(functionScope.localPlaceholders,
192 compareBy((LocalPlaceholder ph) => -ph.nodes.length));
193 List<Set<Node>> currentSortedNodes =
194 currentSortedPlaceholders.map((ph) => ph.nodes).toList();
195 // Make room in all sorted locals list for new stuff.
196 while (currentSortedNodes.length > allLocals.length) {
197 allLocals.add(new Set<Node>());
190 } 198 }
191 } else { 199 for (int i = 0; i < currentSortedNodes.length; i++) {
192 // Build a sorted (by usage) list of local nodes that will be renamed to 200 allLocals[i].addAll(currentSortedNodes[i]);
193 // the same identifier. So the top-used local variables in all functions
194 // will be renamed first and will all share the same new identifier.
195 for (var functionScope in placeholderCollector.functionScopes.values) {
196 // Add current sorted local identifiers to the whole sorted list
197 // of all local identifiers for all functions.
198 List<LocalPlaceholder> currentSortedPlaceholders =
199 sorted(functionScope.localPlaceholders,
200 compareBy((LocalPlaceholder ph) => -ph.nodes.length));
201 List<Set<Node>> currentSortedNodes =
202 currentSortedPlaceholders.map((ph) => ph.nodes).toList();
203 // Make room in all sorted locals list for new stuff.
204 while (currentSortedNodes.length > allLocals.length) {
205 allLocals.add(new Set<Node>());
206 }
207 for (int i = 0; i < currentSortedNodes.length; i++) {
208 allLocals[i].addAll(currentSortedNodes[i]);
209 }
210 } 201 }
211 } 202 }
212 203
213 // Rename elements, members and locals together based on their usage count, 204 // Rename elements, members and locals together based on their usage count,
214 // otherwise when we rename elements first there will be no good identifiers 205 // otherwise when we rename elements first there will be no good identifiers
215 // left for members even if they are used often. 206 // left for members even if they are used often.
216 String elementRenamer(ElementRenamable elementRenamable) => 207 String elementRenamer(ElementRenamable elementRenamable) =>
217 renameElement(elementRenamable.element); 208 renameElement(elementRenamable.element);
218 String memberRenamer(MemberRenamable memberRenamable) => 209 String memberRenamer(MemberRenamable memberRenamable) =>
219 generator.generate(forbiddenIdentifiers.contains); 210 generator.generate(forbiddenIdentifiers.contains);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 index ~/= firstCharAlphabet.length; 349 index ~/= firstCharAlphabet.length;
359 int length = otherCharsAlphabet.length; 350 int length = otherCharsAlphabet.length;
360 while (index >= length) { 351 while (index >= length) {
361 resultBuilder.write(otherCharsAlphabet[index % length]); 352 resultBuilder.write(otherCharsAlphabet[index % length]);
362 index ~/= length; 353 index ~/= length;
363 } 354 }
364 resultBuilder.write(otherCharsAlphabet[index]); 355 resultBuilder.write(otherCharsAlphabet[index]);
365 return resultBuilder.toString(); 356 return resultBuilder.toString();
366 } 357 }
367 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698