| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 if (member.isInstanceMember()) { | 401 if (member.isInstanceMember()) { |
| 402 addInstanceMember(member, prototype, buffer); | 402 addInstanceMember(member, prototype, buffer); |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 for (Element member in classElement.backendMembers) { | 405 for (Element member in classElement.backendMembers) { |
| 406 if (member.isInstanceMember()) { | 406 if (member.isInstanceMember()) { |
| 407 addInstanceMember(member, prototype, buffer); | 407 addInstanceMember(member, prototype, buffer); |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 buffer.add('$prototype.${namer.operatorIs(classElement)} = true;\n'); | 410 buffer.add('$prototype.${namer.operatorIs(classElement)} = true;\n'); |
| 411 for (Type ifc in classElement.interfaces) { | 411 generateInterfacesIsTests(buffer, prototype, classElement); |
| 412 buffer.add('$prototype.${namer.operatorIs(ifc.element)} = true;\n'); | |
| 413 } | |
| 414 if (superclass === null) { | 412 if (superclass === null) { |
| 415 // JS "toString" wrapper. This gives better exceptions. | 413 // JS "toString" wrapper. This gives better exceptions. |
| 416 buffer.add('$prototype.toString = function() {\n'); | 414 buffer.add('$prototype.toString = function() {\n'); |
| 417 buffer.add(' try {'); | 415 buffer.add(' try {\n'); |
| 418 buffer.add(' return ${namer.CURRENT_ISOLATE}'); | 416 buffer.add(' return ${namer.CURRENT_ISOLATE}'); |
| 419 buffer.add('.builtin\$toString\$0\$1(this);'); | 417 buffer.add('.builtin\$toString\$0\$1(this);\n'); |
| 420 buffer.add(' } catch (ex) {'); | 418 buffer.add(' } catch (ex) {\n'); |
| 421 buffer.add(' return "uncaught exception in toString";'); | 419 buffer.add(' return "uncaught exception in toString";\n'); |
| 422 buffer.add(' }'); | 420 buffer.add(' }\n'); |
| 423 buffer.add('};\n'); | 421 buffer.add('};\n'); |
| 424 } | 422 } |
| 425 } | 423 } |
| 426 | 424 |
| 425 void generateInterfacesIsTests(StringBuffer buffer, String prototype, |
| 426 ClassElement cls) { |
| 427 for (Type ifc in cls.interfaces) { |
| 428 buffer.add('$prototype.${namer.operatorIs(ifc.element)} = true;\n'); |
| 429 generateInterfacesIsTests(buffer, prototype, ifc.element); |
| 430 } |
| 431 } |
| 432 |
| 427 void emitClasses(StringBuffer buffer) { | 433 void emitClasses(StringBuffer buffer) { |
| 428 Set seenClasses = new Set<ClassElement>(); | 434 Set seenClasses = new Set<ClassElement>(); |
| 429 for (ClassElement element in compiler.universe.instantiatedClasses) { | 435 for (ClassElement element in compiler.universe.instantiatedClasses) { |
| 430 generateClass(element, buffer, seenClasses); | 436 generateClass(element, buffer, seenClasses); |
| 431 } | 437 } |
| 432 } | 438 } |
| 433 | 439 |
| 434 void emitStaticFunctionsWithNamer(StringBuffer buffer, | 440 void emitStaticFunctionsWithNamer(StringBuffer buffer, |
| 435 Map<Element, String> generatedCode, | 441 Map<Element, String> generatedCode, |
| 436 String functionNamer(Element element)) { | 442 String functionNamer(Element element)) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 emitCompileTimeConstants(buffer); | 729 emitCompileTimeConstants(buffer); |
| 724 emitStaticFinalFieldInitializations(buffer); | 730 emitStaticFinalFieldInitializations(buffer); |
| 725 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 731 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 726 Element main = compiler.mainApp.find(Compiler.MAIN); | 732 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 727 buffer.add('${namer.isolateAccess(main)}();\n'); | 733 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 728 compiler.assembledCode = buffer.toString(); | 734 compiler.assembledCode = buffer.toString(); |
| 729 }); | 735 }); |
| 730 return compiler.assembledCode; | 736 return compiler.assembledCode; |
| 731 } | 737 } |
| 732 } | 738 } |
| OLD | NEW |