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

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

Issue 10831154: Make field-get/set work without elements. (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
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // TODO(floitsch): mangle, while preserving uniqueness. 106 // TODO(floitsch): mangle, while preserving uniqueness.
107 StringBuffer buffer = new StringBuffer(); 107 StringBuffer buffer = new StringBuffer();
108 List<SourceString> names = selector.getOrderedNamedArguments(); 108 List<SourceString> names = selector.getOrderedNamedArguments();
109 for (SourceString argumentName in names) { 109 for (SourceString argumentName in names) {
110 buffer.add(@'$'); 110 buffer.add(@'$');
111 argumentName.printOn(buffer); 111 argumentName.printOn(buffer);
112 } 112 }
113 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; 113 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer';
114 } 114 }
115 115
116 String instanceFieldName(ClassElement cls, SourceString name) { 116 String instanceFieldName(LibraryElement libraryElement, SourceString name) {
117 String proposedName = privateName(cls.getLibrary(), name); 117 String proposedName = privateName(libraryElement, name);
118 if (cls.lookupSuperMember(name) !== null) {
119 String libName = getName(cls.getLibrary());
120 String clsName = getName(cls);
121 proposedName = '$libName\$$clsName\$$proposedName';
122 }
123 return safeName(proposedName); 118 return safeName(proposedName);
124 } 119 }
125 120
121 String shadowedFieldName(Element fieldElement) {
122 ClassElement cls = fieldElement.getEnclosingClass();
123 LibraryElement libraryElement = fieldElement.getLibrary();
124 String libName = getName(libraryElement);
125 String clsName = getName(cls);
126 String instanceName = instanceFieldName(libraryElement, fieldElement.name);
127 return safeName('$libName\$$clsName\$$instanceName');
128 }
129
126 String setterName(LibraryElement lib, SourceString name) { 130 String setterName(LibraryElement lib, SourceString name) {
127 // We dynamically create setters from the field-name. The setter name must 131 // We dynamically create setters from the field-name. The setter name must
128 // therefore be derived from the instance field-name. 132 // therefore be derived from the instance field-name.
129 String fieldName = safeName(privateName(lib, name)); 133 String fieldName = safeName(privateName(lib, name));
130 return 'set\$$fieldName'; 134 return 'set\$$fieldName';
131 } 135 }
132 136
133 String getterName(LibraryElement lib, SourceString name) { 137 String getterName(LibraryElement lib, SourceString name) {
134 // We dynamically create getters from the field-name. The getter name must 138 // We dynamically create getters from the field-name. The getter name must
135 // therefore be derived from the instance field-name. 139 // therefore be derived from the instance field-name.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } else if (element.kind == ElementKind.FUNCTION) { 214 } else if (element.kind == ElementKind.FUNCTION) {
211 FunctionElement functionElement = element; 215 FunctionElement functionElement = element;
212 return instanceMethodName(element.getLibrary(), 216 return instanceMethodName(element.getLibrary(),
213 element.name, 217 element.name,
214 functionElement.parameterCount(compiler)); 218 functionElement.parameterCount(compiler));
215 } else if (element.kind == ElementKind.GETTER) { 219 } else if (element.kind == ElementKind.GETTER) {
216 return getterName(element.getLibrary(), element.name); 220 return getterName(element.getLibrary(), element.name);
217 } else if (element.kind == ElementKind.SETTER) { 221 } else if (element.kind == ElementKind.SETTER) {
218 return setterName(element.getLibrary(), element.name); 222 return setterName(element.getLibrary(), element.name);
219 } else { 223 } else {
220 return instanceFieldName(element.getEnclosingClass(), element.name); 224 compiler.internalError('getName for bad kind: ${element.kind}',
225 node: element.parseNode(compiler));
221 } 226 }
222 } else { 227 } else {
223 // Dealing with a top-level or static element. 228 // Dealing with a top-level or static element.
224 String cached = globals[element]; 229 String cached = globals[element];
225 if (cached !== null) return cached; 230 if (cached !== null) return cached;
226 231
227 String guess = _computeGuess(element); 232 String guess = _computeGuess(element);
228 ElementKind kind = element.kind; 233 ElementKind kind = element.kind;
229 if (kind === ElementKind.VARIABLE || 234 if (kind === ElementKind.VARIABLE ||
230 kind === ElementKind.PARAMETER) { 235 kind === ElementKind.PARAMETER) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 274 }
270 275
271 String safeName(String name) { 276 String safeName(String name) {
272 if (jsReserved.contains(name) || name.startsWith('\$')) { 277 if (jsReserved.contains(name) || name.startsWith('\$')) {
273 name = "\$$name"; 278 name = "\$$name";
274 assert(!jsReserved.contains(name)); 279 assert(!jsReserved.contains(name));
275 } 280 }
276 return name; 281 return name;
277 } 282 }
278 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698