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

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

Issue 10911211: Runtime support for the new parameter specification. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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) 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 String libName = getName(lib); 91 String libName = getName(lib);
92 // If a library name does not start with the [LIBRARY_PREFIX] then our 92 // If a library name does not start with the [LIBRARY_PREFIX] then our
93 // assumptions about clashing with mangled private members do not hold. 93 // assumptions about clashing with mangled private members do not hold.
94 assert(libName.startsWith(LIBRARY_PREFIX)); 94 assert(libName.startsWith(LIBRARY_PREFIX));
95 return '_$libName$nameString'; 95 return '_$libName$nameString';
96 } else { 96 } else {
97 return name.slowToString(); 97 return name.slowToString();
98 } 98 }
99 } 99 }
100 100
101 String instanceMethodName(LibraryElement lib, SourceString name, int arity) { 101 String instanceMethodName(FunctionElement element) {
102 return '${privateName(lib, name)}\$$arity'; 102 SourceString name = element.name;
103 LibraryElement lib = element.getLibrary();
104 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
105 ConstructorBodyElement bodyElement = element;
106 name = bodyElement.constructor.name;
107 }
108 FunctionSignature signature = element.computeSignature(compiler);
109 String methodName =
110 '${privateName(lib, name)}\$${signature.parameterCount}';
111 if (!signature.optionalParametersAreNamed) {
112 return methodName;
113 } else {
114 StringBuffer suffix = new StringBuffer();
115 signature.forEachOptionalParameter((Element element) {
116 String jsName = JsNames.getValid(element.name.slowToString());
117 suffix.add('\$$jsName');
118 });
119 return '$methodName$suffix';
120 }
121 }
122
123 String instanceMethodNameByArity(SourceString name, int arity) {
124 return '${name.slowToString()}\$$arity';
ahe 2012/09/13 14:29:10 assert(!name.isPrivate());
ngeoffray 2012/09/17 12:21:01 Done.
103 } 125 }
104 126
105 String instanceMethodInvocationName(LibraryElement lib, SourceString name, 127 String instanceMethodInvocationName(LibraryElement lib, SourceString name,
106 Selector selector) { 128 Selector selector) {
107 // TODO(floitsch): mangle, while preserving uniqueness. 129 // TODO(floitsch): mangle, while preserving uniqueness.
108 StringBuffer buffer = new StringBuffer(); 130 StringBuffer buffer = new StringBuffer();
109 List<SourceString> names = selector.getOrderedNamedArguments(); 131 List<SourceString> names = selector.getOrderedNamedArguments();
110 for (SourceString argumentName in names) { 132 for (SourceString argumentName in names) {
111 buffer.add(@'$'); 133 buffer.add(@'$');
112 argumentName.printOn(buffer); 134 argumentName.printOn(buffer);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 /** 222 /**
201 * Returns a preferred JS-id for the given element. The returned id is 223 * Returns a preferred JS-id for the given element. The returned id is
202 * guaranteed to be a valid JS-id. Globals and static fields are furthermore 224 * guaranteed to be a valid JS-id. Globals and static fields are furthermore
203 * guaranteed to be unique. 225 * guaranteed to be unique.
204 * 226 *
205 * For accessing statics consider calling 227 * For accessing statics consider calling
206 * [isolateAccess]/[isolateBailoutAccess] or [isolatePropertyAccess] instead. 228 * [isolateAccess]/[isolateBailoutAccess] or [isolatePropertyAccess] instead.
207 */ 229 */
208 String getName(Element element) { 230 String getName(Element element) {
209 if (element.isInstanceMember()) { 231 if (element.isInstanceMember()) {
210 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { 232 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY
211 ConstructorBodyElement bodyElement = element; 233 || element.kind == ElementKind.FUNCTION) {
212 SourceString name = bodyElement.constructor.name; 234 return instanceMethodName(element);
213 return instanceMethodName(element.getLibrary(),
214 name, bodyElement.parameterCount(compiler));
215 } else if (element.kind == ElementKind.FUNCTION) {
216 FunctionElement functionElement = element;
217 return instanceMethodName(element.getLibrary(),
218 element.name,
219 functionElement.parameterCount(compiler));
220 } else if (element.kind == ElementKind.GETTER) { 235 } else if (element.kind == ElementKind.GETTER) {
221 return getterName(element.getLibrary(), element.name); 236 return getterName(element.getLibrary(), element.name);
222 } else if (element.kind == ElementKind.SETTER) { 237 } else if (element.kind == ElementKind.SETTER) {
223 return setterName(element.getLibrary(), element.name); 238 return setterName(element.getLibrary(), element.name);
224 } else if (element.kind == ElementKind.FIELD) { 239 } else if (element.kind == ElementKind.FIELD) {
225 return instanceFieldName(element.getLibrary(), element.name); 240 return instanceFieldName(element.getLibrary(), element.name);
226 } else { 241 } else {
227 compiler.internalError('getName for bad kind: ${element.kind}', 242 compiler.internalError('getName for bad kind: ${element.kind}',
228 node: element.parseNode(compiler)); 243 node: element.parseNode(compiler));
229 } 244 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 302 }
288 303
289 String safeName(String name) { 304 String safeName(String name) {
290 if (jsReserved.contains(name) || name.startsWith('\$')) { 305 if (jsReserved.contains(name) || name.startsWith('\$')) {
291 name = "\$$name"; 306 name = "\$$name";
292 assert(!jsReserved.contains(name)); 307 assert(!jsReserved.contains(name));
293 } 308 }
294 return name; 309 return name;
295 } 310 }
296 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698