Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 if (member.kind == ElementKind.FUNCTION) { | 363 if (member.kind == ElementKind.FUNCTION) { |
| 364 if (compiler.universe.invokedGetters.contains(member.name)) { | 364 if (compiler.universe.invokedGetters.contains(member.name)) { |
| 365 emitDynamicFunctionGetter(buffer, currentClass, member); | 365 emitDynamicFunctionGetter(buffer, currentClass, member); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 | 372 |
| 373 void emitGetterMethod(StringBuffer buffer, | |
|
ngeoffray
2012/02/17 10:19:26
emitCallStubForGetter
floitsch
2012/02/17 13:19:32
Done.
| |
| 374 ClassElement enclosingClass, | |
| 375 Element member, | |
| 376 Set<Selector> selectors) { | |
| 377 | |
| 378 String prototype = | |
| 379 "${namer.isolatePropertyAccess(enclosingClass)}.prototype"; | |
| 380 String getter; | |
| 381 if (member.kind == ElementKind.GETTER) { | |
| 382 getter = "this.${namer.getterName(member.name)}()"; | |
| 383 } else { | |
| 384 getter = "this.${namer.instanceFieldName(member.name)}"; | |
| 385 } | |
| 386 for (Selector selector in selectors) { | |
| 387 String invocationName = | |
| 388 namer.instanceMethodInvocationName(member.name, selector); | |
| 389 SourceString callName = Namer.CLOSURE_INVOCATION_NAME; | |
| 390 String closureCallName = | |
| 391 namer.instanceMethodInvocationName(callName, selector); | |
| 392 List<String> arguments = <String>[]; | |
| 393 for (int i = 0; i < selector.argumentCount; i++) { | |
| 394 arguments.add("arg$i"); | |
| 395 } | |
| 396 String joined = Strings.join(arguments, ", "); | |
| 397 buffer.add("$prototype.$invocationName = function($joined) {\n"); | |
| 398 buffer.add(" return $getter.$closureCallName($joined);\n"); | |
| 399 buffer.add("};\n"); | |
| 400 } | |
| 401 } | |
| 402 | |
| 403 void emitGetterMethods(StringBuffer buffer) { | |
|
ngeoffray
2012/02/17 10:19:26
emitCallStubForGetters
floitsch
2012/02/17 13:19:32
Done.
| |
| 404 for (ClassElement classElement in compiler.universe.instantiatedClasses) { | |
| 405 for (ClassElement currentClass = classElement; | |
| 406 currentClass !== null; | |
| 407 currentClass = currentClass.superclass) { | |
| 408 // TODO(floitsch): we don't need to deal with members that have been | |
| 409 // overwritten by subclasses. | |
| 410 for (Element member in currentClass.members) { | |
| 411 if (!member.isInstanceMember()) continue; | |
| 412 if (member.kind == ElementKind.GETTER || | |
| 413 member.kind == ElementKind.FIELD) { | |
| 414 Set<Selector> selectors = | |
| 415 compiler.universe.invokedNames[member.name]; | |
| 416 if (selectors == null || selectors.isEmpty()) continue; | |
| 417 emitGetterMethod(buffer, currentClass, member, selectors); | |
| 418 } | |
| 419 } | |
| 420 } | |
| 421 } | |
| 422 } | |
| 423 | |
| 373 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { | 424 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { |
| 374 // Adds initializations inside the Isolate constructor. | 425 // Adds initializations inside the Isolate constructor. |
| 375 // Example: | 426 // Example: |
| 376 // function Isolate() { | 427 // function Isolate() { |
| 377 // this.staticNonFinal = Isolate.prototype.someVal; | 428 // this.staticNonFinal = Isolate.prototype.someVal; |
| 378 // ... | 429 // ... |
| 379 // } | 430 // } |
| 380 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; | 431 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; |
| 381 List<VariableElement> staticNonFinalFields = | 432 List<VariableElement> staticNonFinalFields = |
| 382 constants.getStaticNonFinalFieldsForEmission(); | 433 constants.getStaticNonFinalFieldsForEmission(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 measure(() { | 507 measure(() { |
| 457 StringBuffer buffer = new StringBuffer(); | 508 StringBuffer buffer = new StringBuffer(); |
| 458 buffer.add('function ${namer.ISOLATE}() {'); | 509 buffer.add('function ${namer.ISOLATE}() {'); |
| 459 emitStaticNonFinalFieldInitializations(buffer); | 510 emitStaticNonFinalFieldInitializations(buffer); |
| 460 buffer.add('}\n\n'); | 511 buffer.add('}\n\n'); |
| 461 emitClasses(buffer); | 512 emitClasses(buffer); |
| 462 emitNoSuchMethodCalls(buffer); | 513 emitNoSuchMethodCalls(buffer); |
| 463 emitStaticFunctions(buffer); | 514 emitStaticFunctions(buffer); |
| 464 emitStaticFunctionGetters(buffer); | 515 emitStaticFunctionGetters(buffer); |
| 465 emitDynamicFunctionGetters(buffer); | 516 emitDynamicFunctionGetters(buffer); |
| 517 emitGetterMethods(buffer); | |
| 466 emitStaticFinalFieldInitializations(buffer); | 518 emitStaticFinalFieldInitializations(buffer); |
| 467 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 519 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 468 Element main = compiler.mainApp.find(Compiler.MAIN); | 520 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 469 buffer.add('${namer.isolateAccess(main)}();\n'); | 521 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 470 compiler.assembledCode = buffer.toString(); | 522 compiler.assembledCode = buffer.toString(); |
| 471 }); | 523 }); |
| 472 return compiler.assembledCode; | 524 return compiler.assembledCode; |
| 473 } | 525 } |
| 474 } | 526 } |
| OLD | NEW |