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

Side by Side Diff: lib/compiler/implementation/namer.dart

Issue 10557003: Fix most warnings and other minor cleanups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 * Assigns JavaScript identifiers to Dart variables, class-names and members. 6 * Assigns JavaScript identifiers to Dart variables, class-names and members.
7 */ 7 */
8 class Namer { 8 class Namer {
9 final Compiler compiler; 9 final Compiler compiler;
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 String libName = getName(cls.getLibrary()); 87 String libName = getName(cls.getLibrary());
88 String clsName = getName(cls); 88 String clsName = getName(cls);
89 proposedName = '$libName\$$clsName\$$proposedName'; 89 proposedName = '$libName\$$clsName\$$proposedName';
90 } 90 }
91 return safeName(proposedName); 91 return safeName(proposedName);
92 } 92 }
93 93
94 String setterName(LibraryElement lib, SourceString name) { 94 String setterName(LibraryElement lib, SourceString name) {
95 // We dynamically create setters from the field-name. The setter name must 95 // We dynamically create setters from the field-name. The setter name must
96 // therefore be derived from the instance field-name. 96 // therefore be derived from the instance field-name.
97 String safeName = safeName(privateName(lib, name)); 97 String fieldName = safeName(privateName(lib, name));
98 return 'set\$$safeName'; 98 return 'set\$$fieldName';
99 } 99 }
100 100
101 String getterName(LibraryElement lib, SourceString name) { 101 String getterName(LibraryElement lib, SourceString name) {
102 // We dynamically create getters from the field-name. The getter name must 102 // We dynamically create getters from the field-name. The getter name must
103 // therefore be derived from the instance field-name. 103 // therefore be derived from the instance field-name.
104 String safeName = safeName(privateName(lib, name)); 104 String fieldName = safeName(privateName(lib, name));
105 return 'get\$$safeName'; 105 return 'get\$$fieldName';
106 } 106 }
107 107
108 String getFreshGlobalName(String proposedName) { 108 String getFreshGlobalName(String proposedName) {
109 int usedCount = usedGlobals[proposedName]; 109 int usedCount = usedGlobals[proposedName];
110 if (usedCount === null) { 110 if (usedCount === null) {
111 // No element with this name has been used before. 111 // No element with this name has been used before.
112 usedGlobals[proposedName] = 1; 112 usedGlobals[proposedName] = 1;
113 return proposedName; 113 return proposedName;
114 } else { 114 } else {
115 // Not the first time we see this name. Append a number to make it unique. 115 // Not the first time we see this name. Append a number to make it unique.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 return setterName(element.getLibrary(), element.name); 189 return setterName(element.getLibrary(), element.name);
190 } else { 190 } else {
191 return instanceFieldName(element.getEnclosingClass(), element.name); 191 return instanceFieldName(element.getEnclosingClass(), element.name);
192 } 192 }
193 } else { 193 } else {
194 // Dealing with a top-level or static element. 194 // Dealing with a top-level or static element.
195 String cached = globals[element]; 195 String cached = globals[element];
196 if (cached !== null) return cached; 196 if (cached !== null) return cached;
197 197
198 String guess = _computeGuess(element); 198 String guess = _computeGuess(element);
199 switch (element.kind) { 199 ElementKind kind = element.kind;
200 case ElementKind.VARIABLE: 200 if (kind === ElementKind.VARIABLE ||
201 case ElementKind.PARAMETER: 201 kind === ElementKind.PARAMETER) {
202 // The name is not guaranteed to be unique. 202 // The name is not guaranteed to be unique.
203 return guess; 203 return guess;
204
205 case ElementKind.GENERATIVE_CONSTRUCTOR:
206 case ElementKind.FUNCTION:
207 case ElementKind.CLASS:
208 case ElementKind.FIELD:
209 case ElementKind.GETTER:
210 case ElementKind.SETTER:
211 case ElementKind.TYPEDEF:
212 case ElementKind.LIBRARY:
213 String result = getFreshGlobalName(guess);
214 globals[element] = result;
215 return result;
216
217 default:
218 compiler.internalError('getName for unknown kind: ${element.kind}',
219 node: element.parseNode(compiler));
220 } 204 }
205 if (kind === ElementKind.GENERATIVE_CONSTRUCTOR ||
206 kind === ElementKind.FUNCTION ||
207 kind === ElementKind.CLASS ||
208 kind === ElementKind.FIELD ||
209 kind === ElementKind.GETTER ||
210 kind === ElementKind.SETTER ||
211 kind === ElementKind.TYPEDEF ||
212 kind === ElementKind.LIBRARY) {
213 String result = getFreshGlobalName(guess);
214 globals[element] = result;
215 return result;
216 }
217 compiler.internalError('getName for unknown kind: ${element.kind}',
218 node: element.parseNode(compiler));
221 } 219 }
222 } 220 }
223 221
224 String isolatePropertiesAccess(Element element) { 222 String isolatePropertiesAccess(Element element) {
225 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; 223 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}";
226 } 224 }
227 225
228 String isolatePropertiesAccessForConstant(String constantName) { 226 String isolatePropertiesAccessForConstant(String constantName) {
229 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; 227 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName";
230 } 228 }
(...skipping 11 matching lines...) Expand all
242 } 240 }
243 241
244 String safeName(String name) { 242 String safeName(String name) {
245 if (jsReserved.contains(name) || name.startsWith('\$')) { 243 if (jsReserved.contains(name) || name.startsWith('\$')) {
246 name = "\$$name"; 244 name = "\$$name";
247 assert(!jsReserved.contains(name)); 245 assert(!jsReserved.contains(name));
248 } 246 }
249 return name; 247 return name;
250 } 248 }
251 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698