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

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

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. 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 Function get _compareNodes => 5 Function get _compareNodes =>
6 compareBy((n) => n.getBeginToken().charOffset); 6 compareBy((n) => n.getBeginToken().charOffset);
7 7
8 typedef String _Renamer(Renamable renamable); 8 typedef String _Renamer(Renamable renamable);
9 abstract class Renamable { 9 abstract class Renamable {
10 const int RENAMABLE_TYPE_ELEMENT = 1; 10 const int RENAMABLE_TYPE_ELEMENT = 1;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 final Map<LibraryElement, Map<String, String>> renamed 69 final Map<LibraryElement, Map<String, String>> renamed
70 = new Map<LibraryElement, Map<String, String>>(); 70 = new Map<LibraryElement, Map<String, String>>();
71 71
72 renameNodes(Collection<Node> nodes, renamer) { 72 renameNodes(Collection<Node> nodes, renamer) {
73 for (Node node in sorted(nodes, _compareNodes)) { 73 for (Node node in sorted(nodes, _compareNodes)) {
74 renames[node] = renamer(node); 74 renames[node] = renamer(node);
75 } 75 }
76 } 76 }
77 77
78 sortedForEach(Map<Element, Dynamic> map, f) { 78 sortedForEach(Map<Element, Dynamic> map, f) {
79 for (Element element in sortElements(map.getKeys())) { 79 for (Element element in sortElements(map.keys)) {
80 f(element, map[element]); 80 f(element, map[element]);
81 } 81 }
82 } 82 }
83 83
84 Function makeElementRenamer(rename, generateUniqueName) => (element) { 84 Function makeElementRenamer(rename, generateUniqueName) => (element) {
85 assert(Elements.isStaticOrTopLevel(element) 85 assert(Elements.isStaticOrTopLevel(element)
86 || element is TypeVariableElement); 86 || element is TypeVariableElement);
87 // TODO(smok): We may want to reuse class static field and method names. 87 // TODO(smok): We may want to reuse class static field and method names.
88 String originalName = element.name.slowToString(); 88 String originalName = element.name.slowToString();
89 LibraryElement library = element.getLibrary(); 89 LibraryElement library = element.getLibrary();
(...skipping 15 matching lines...) Expand all
105 105
106 // Renamer function that takes library and original name and returns a new 106 // Renamer function that takes library and original name and returns a new
107 // name for given identifier. 107 // name for given identifier.
108 Function rename; 108 Function rename;
109 // A function that takes original identifier name and generates a new unique 109 // A function that takes original identifier name and generates a new unique
110 // identifier. 110 // identifier.
111 Function generateUniqueName; 111 Function generateUniqueName;
112 if (compiler.enableMinification) { 112 if (compiler.enableMinification) {
113 MinifyingGenerator generator = new MinifyingGenerator(); 113 MinifyingGenerator generator = new MinifyingGenerator();
114 Set<String> forbiddenIdentifiers = new Set<String>.from(['main']); 114 Set<String> forbiddenIdentifiers = new Set<String>.from(['main']);
115 forbiddenIdentifiers.addAll(Keyword.keywords.getKeys()); 115 forbiddenIdentifiers.addAll(Keyword.keywords.keys);
116 forbiddenIdentifiers.addAll(fixedMemberNames); 116 forbiddenIdentifiers.addAll(fixedMemberNames);
117 generateUniqueName = (_) => 117 generateUniqueName = (_) =>
118 generator.generate(forbiddenIdentifiers.contains); 118 generator.generate(forbiddenIdentifiers.contains);
119 rename = makeRenamer(generateUniqueName); 119 rename = makeRenamer(generateUniqueName);
120 Function renameElement = makeElementRenamer(rename, generateUniqueName); 120 Function renameElement = makeElementRenamer(rename, generateUniqueName);
121 121
122 Set<String> allParameterIdentifiers = new Set<String>(); 122 Set<String> allParameterIdentifiers = new Set<String>();
123 for (var functionScope in placeholderCollector.functionScopes.getValues()) { 123 for (var functionScope in placeholderCollector.functionScopes.values) {
124 allParameterIdentifiers.addAll(functionScope.parameterIdentifiers); 124 allParameterIdentifiers.addAll(functionScope.parameterIdentifiers);
125 } 125 }
126 // Build a sorted (by usage) list of local nodes that will be renamed to 126 // Build a sorted (by usage) list of local nodes that will be renamed to
127 // the same identifier. So the top-used local variables in all functions 127 // the same identifier. So the top-used local variables in all functions
128 // will be renamed first and will all share the same new identifier. 128 // will be renamed first and will all share the same new identifier.
129 List<Set<Node>> allSortedLocals = new List<Set<Node>>(); 129 List<Set<Node>> allSortedLocals = new List<Set<Node>>();
130 for (var functionScope in placeholderCollector.functionScopes.getValues()) { 130 for (var functionScope in placeholderCollector.functionScopes.values) {
131 // Add current sorted local identifiers to the whole sorted list 131 // Add current sorted local identifiers to the whole sorted list
132 // of all local identifiers for all functions. 132 // of all local identifiers for all functions.
133 List<LocalPlaceholder> currentSortedPlaceholders = 133 List<LocalPlaceholder> currentSortedPlaceholders =
134 sorted(functionScope.localPlaceholders, 134 sorted(functionScope.localPlaceholders,
135 compareBy((LocalPlaceholder ph) => -ph.nodes.length)); 135 compareBy((LocalPlaceholder ph) => -ph.nodes.length));
136 List<Set<Node>> currentSortedNodes = 136 List<Set<Node>> currentSortedNodes =
137 currentSortedPlaceholders.map((ph) => ph.nodes); 137 currentSortedPlaceholders.map((ph) => ph.nodes);
138 // Make room in all sorted locals list for new stuff. 138 // Make room in all sorted locals list for new stuff.
139 while (currentSortedNodes.length > allSortedLocals.length) { 139 while (currentSortedNodes.length > allSortedLocals.length) {
140 allSortedLocals.add(new Set<Node>()); 140 allSortedLocals.add(new Set<Node>());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 index ~/= firstCharAlphabet.length; 285 index ~/= firstCharAlphabet.length;
286 int length = otherCharsAlphabet.length; 286 int length = otherCharsAlphabet.length;
287 while (index >= length) { 287 while (index >= length) {
288 resultBuilder.add(otherCharsAlphabet[index % length]); 288 resultBuilder.add(otherCharsAlphabet[index % length]);
289 index ~/= length; 289 index ~/= length;
290 } 290 }
291 resultBuilder.add(otherCharsAlphabet[index]); 291 resultBuilder.add(otherCharsAlphabet[index]);
292 return resultBuilder.toString(); 292 return resultBuilder.toString();
293 } 293 }
294 } 294 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/backend.dart ('k') | lib/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698