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

Side by Side Diff: frog/leg/emitter.dart

Issue 9325023: Support noSuchMethod for methods that take named parameters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 | tests/language/language-leg.status » ('j') | 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 /** 5 /**
6 * Generates the code for all used classes in the program. Static fields (even 6 * Generates the code for all used classes in the program. Static fields (even
7 * in classes) are ignored, since they can be treated as non-class elements. 7 * in classes) are ignored, since they can be treated as non-class elements.
8 * 8 *
9 * The code for the containing (used) methods must exist in the [:universe:]. 9 * The code for the containing (used) methods must exist in the [:universe:].
10 */ 10 */
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // TODO(ngeoffray): We don't need to generate these methods if 294 // TODO(ngeoffray): We don't need to generate these methods if
295 // nobody overwrites noSuchMethod. 295 // nobody overwrites noSuchMethod.
296 296
297 ClassElement objectClass = 297 ClassElement objectClass =
298 compiler.coreLibrary.find(const SourceString('Object')); 298 compiler.coreLibrary.find(const SourceString('Object'));
299 String className = namer.isolatePropertyAccess(objectClass); 299 String className = namer.isolatePropertyAccess(objectClass);
300 String prototype = '$className.prototype'; 300 String prototype = '$className.prototype';
301 String noSuchMethodName = 301 String noSuchMethodName =
302 namer.instanceMethodName(Compiler.NO_SUCH_METHOD, 2); 302 namer.instanceMethodName(Compiler.NO_SUCH_METHOD, 2);
303 303
304 void generateMethod(String methodName, String jsName, int arity) { 304 void generateMethod(String methodName, String jsName, Selector selector) {
305 buffer.add('$prototype.$jsName = function'); 305 buffer.add('$prototype.$jsName = function');
306 StringBuffer args = new StringBuffer(); 306 StringBuffer args = new StringBuffer();
307 for (int i = 0; i < arity; i++) { 307 for (int i = 0; i < selector.argumentCount; i++) {
308 if (i != 0) args.add(', '); 308 if (i != 0) args.add(', ');
309 args.add('arg$i'); 309 args.add('arg$i');
310 } 310 }
311 buffer.add(' ($args) {\n'); 311 buffer.add(' ($args) {\n');
312 buffer.add(" return this.$noSuchMethodName('$methodName', [$args]);\n"); 312 buffer.add(" return this.$noSuchMethodName('$methodName', [$args]);\n");
floitsch 2012/02/03 13:24:26 in the current form NSM is useless since you would
ngeoffray 2012/02/03 13:42:27 Correct, we need to implement a mirror thingy...
313 buffer.add('}\n'); 313 buffer.add('}\n');
314 } 314 }
315 315
316 compiler.universe.invokedNames.forEach((SourceString methodName, 316 compiler.universe.invokedNames.forEach((SourceString methodName,
317 Set<Selector> selectors) { 317 Set<Selector> selectors) {
318 if (objectClass.lookupLocalMember(methodName) === null 318 if (objectClass.lookupLocalMember(methodName) === null
319 && methodName != Namer.OPERATOR_EQUALS) { 319 && methodName != Namer.OPERATOR_EQUALS) {
320 for (Selector selector in selectors) { 320 for (Selector selector in selectors) {
321 int arity = selector.argumentCount; 321 String jsName =
322 String jsName = namer.instanceMethodName(methodName, arity); 322 namer.instanceMethodInvocationName(methodName, selector);
323 generateMethod(methodName.stringValue, jsName, arity); 323 generateMethod(methodName.stringValue, jsName, selector);
324 } 324 }
325 } 325 }
326 }); 326 });
327 327
328 compiler.universe.invokedGetters.forEach((SourceString getterName) { 328 compiler.universe.invokedGetters.forEach((SourceString getterName) {
329 String jsName = namer.getterName(getterName); 329 String jsName = namer.getterName(getterName);
330 generateMethod('get $getterName', jsName, 0); 330 generateMethod('get $getterName', jsName, Selector.GETTER);
331 }); 331 });
332 332
333 compiler.universe.invokedSetters.forEach((SourceString setterName) { 333 compiler.universe.invokedSetters.forEach((SourceString setterName) {
334 String jsName = namer.setterName(setterName); 334 String jsName = namer.setterName(setterName);
335 generateMethod('set $setterName', jsName, 1); 335 generateMethod('set $setterName', jsName, Selector.SETTER);
336 }); 336 });
337 } 337 }
338 338
339 String assembleProgram() { 339 String assembleProgram() {
340 measure(() { 340 measure(() {
341 StringBuffer buffer = new StringBuffer(); 341 StringBuffer buffer = new StringBuffer();
342 buffer.add('function ${namer.ISOLATE}() {'); 342 buffer.add('function ${namer.ISOLATE}() {');
343 emitStaticNonFinalFieldInitializations(buffer); 343 emitStaticNonFinalFieldInitializations(buffer);
344 buffer.add('}\n\n'); 344 buffer.add('}\n\n');
345 emitClasses(buffer); 345 emitClasses(buffer);
346 emitNoSuchMethodCalls(buffer); 346 emitNoSuchMethodCalls(buffer);
347 emitStaticFunctions(buffer); 347 emitStaticFunctions(buffer);
348 emitStaticFinalFieldInitializations(buffer); 348 emitStaticFinalFieldInitializations(buffer);
349 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 349 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
350 Element main = compiler.mainApp.find(Compiler.MAIN); 350 Element main = compiler.mainApp.find(Compiler.MAIN);
351 buffer.add('${namer.isolateAccess(main)}();\n'); 351 buffer.add('${namer.isolateAccess(main)}();\n');
352 compiler.assembledCode = buffer.toString(); 352 compiler.assembledCode = buffer.toString();
353 }); 353 });
354 return compiler.assembledCode; 354 return compiler.assembledCode;
355 } 355 }
356 } 356 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698