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

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

Issue 11040063: Do not allow platform prefices to conflict with fixed members. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.getKeys());
116 forbiddenIdentifiers.addAll(fixedMemberNames);
116 generateUniqueName = (_) => 117 generateUniqueName = (_) =>
117 generator.generate(forbiddenIdentifiers.contains); 118 generator.generate(forbiddenIdentifiers.contains);
118 rename = makeRenamer(generateUniqueName); 119 rename = makeRenamer(generateUniqueName);
119 Function renameElement = makeElementRenamer(rename, generateUniqueName); 120 Function renameElement = makeElementRenamer(rename, generateUniqueName);
120 121
121 Set<String> allParameterIdentifiers = new Set<String>(); 122 Set<String> allParameterIdentifiers = new Set<String>();
122 for (var functionScope in placeholderCollector.functionScopes.getValues()) { 123 for (var functionScope in placeholderCollector.functionScopes.getValues()) {
123 allParameterIdentifiers.addAll(functionScope.parameterIdentifiers); 124 allParameterIdentifiers.addAll(functionScope.parameterIdentifiers);
124 } 125 }
125 // 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
(...skipping 16 matching lines...) Expand all
142 allSortedLocals[i].addAll(currentSortedNodes[i]); 143 allSortedLocals[i].addAll(currentSortedNodes[i]);
143 } 144 }
144 } 145 }
145 146
146 // Rename elements, members and locals together based on their usage count, 147 // Rename elements, members and locals together based on their usage count,
147 // otherwise when we rename elements first there will be no good identifiers 148 // otherwise when we rename elements first there will be no good identifiers
148 // left for members even if they are used often. 149 // left for members even if they are used often.
149 String elementRenamer(ElementRenamable elementRenamable) => 150 String elementRenamer(ElementRenamable elementRenamable) =>
150 renameElement(elementRenamable.element); 151 renameElement(elementRenamable.element);
151 String memberRenamer(MemberRenamable memberRenamable) => 152 String memberRenamer(MemberRenamable memberRenamable) =>
152 generator.generate((name) => 153 generator.generate(forbiddenIdentifiers.contains);
153 forbiddenIdentifiers.contains(name)
154 || fixedMemberNames.contains(name));
155 String localRenamer(LocalRenamable localRenamable) => 154 String localRenamer(LocalRenamable localRenamable) =>
156 generator.generate((name) => 155 generator.generate((name) =>
157 allParameterIdentifiers.contains(name) 156 allParameterIdentifiers.contains(name)
158 || forbiddenIdentifiers.contains(name) 157 || forbiddenIdentifiers.contains(name));
159 || fixedMemberNames.contains(name));
160 List<Renamable> renamables = []; 158 List<Renamable> renamables = [];
161 placeholderCollector.elementNodes.forEach( 159 placeholderCollector.elementNodes.forEach(
162 (Element element, Set<Node> nodes) { 160 (Element element, Set<Node> nodes) {
163 renamables.add(new ElementRenamable(element, nodes, elementRenamer)); 161 renamables.add(new ElementRenamable(element, nodes, elementRenamer));
164 }); 162 });
165 placeholderCollector.memberPlaceholders.forEach( 163 placeholderCollector.memberPlaceholders.forEach(
166 (String memberName, Set<Identifier> identifiers) { 164 (String memberName, Set<Identifier> identifiers) {
167 renamables.add( 165 renamables.add(
168 new MemberRenamable(memberName, identifiers, memberRenamer)); 166 new MemberRenamable(memberName, identifiers, memberRenamer));
169 }); 167 });
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 index ~/= firstCharAlphabet.length; 286 index ~/= firstCharAlphabet.length;
289 int length = otherCharsAlphabet.length; 287 int length = otherCharsAlphabet.length;
290 while (index >= length) { 288 while (index >= length) {
291 resultBuilder.add(otherCharsAlphabet[index % length]); 289 resultBuilder.add(otherCharsAlphabet[index % length]);
292 index ~/= length; 290 index ~/= length;
293 } 291 }
294 resultBuilder.add(otherCharsAlphabet[index]); 292 resultBuilder.add(otherCharsAlphabet[index]);
295 return resultBuilder.toString(); 293 return resultBuilder.toString();
296 } 294 }
297 } 295 }
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