| 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 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
| 7 * from the given element. | 7 * from the given element. |
| 8 */ | 8 */ |
| 9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
| 10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 if (member.isInstanceMember()) { | 303 if (member.isInstanceMember()) { |
| 304 addInstanceMember(member, attachTo, buffer); | 304 addInstanceMember(member, attachTo, buffer); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 for (Element member in classElement.backendMembers) { | 307 for (Element member in classElement.backendMembers) { |
| 308 if (member.isInstanceMember()) { | 308 if (member.isInstanceMember()) { |
| 309 addInstanceMember(member, attachTo, buffer); | 309 addInstanceMember(member, attachTo, buffer); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 generateTypeTests(classElement, (Element other) { | 312 generateTypeTests(classElement, (Element other) { |
| 313 buffer.add('${attachTo(namer.operatorIs(other))} = true;\n'); | 313 buffer.add('${attachTo(namer.operatorIs(other))} = '); |
| 314 if (nativeEmitter.requiresNativeIsCheck(other)) { |
| 315 buffer.add('function() { return true; }'); |
| 316 } else { |
| 317 buffer.add('true'); |
| 318 } |
| 319 buffer.add(';\n'); |
| 314 }); | 320 }); |
| 315 | 321 |
| 316 if (classElement === compiler.objectClass && compiler.enabledNoSuchMethod) { | 322 if (classElement === compiler.objectClass && compiler.enabledNoSuchMethod) { |
| 317 // Emit the noSuchMethods on the Object prototype now, so that | 323 // Emit the noSuchMethods on the Object prototype now, so that |
| 318 // the code in the dynamicMethod can find them. Note that the | 324 // the code in the dynamicMethod can find them. Note that the |
| 319 // code in dynamicMethod is invoked before analyzing the full JS | 325 // code in dynamicMethod is invoked before analyzing the full JS |
| 320 // script. | 326 // script. |
| 321 emitNoSuchMethodCalls(buffer); | 327 emitNoSuchMethodCalls(buffer); |
| 322 } | 328 } |
| 323 } | 329 } |
| 324 | 330 |
| 325 void generateTypeTests(ClassElement cls, | 331 void generateTypeTests(ClassElement cls, |
| 326 void generateTypeTest(ClassElement element)) { | 332 void generateTypeTest(ClassElement element)) { |
| 327 if (compiler.universe.isChecks.contains(cls)) { | 333 if (compiler.universe.isChecks.contains(cls)) { |
| 328 generateTypeTest(cls); | 334 generateTypeTest(cls); |
| 329 } | 335 } |
| 330 generateInterfacesIsTests(cls, generateTypeTest); | 336 generateInterfacesIsTests(cls, generateTypeTest, new Set<Element>()); |
| 331 } | 337 } |
| 332 | 338 |
| 333 void generateInterfacesIsTests(ClassElement cls, | 339 void generateInterfacesIsTests(ClassElement cls, |
| 334 void generateTypeTest(ClassElement element)) { | 340 void generateTypeTest(ClassElement element), |
| 341 Set<Element> alreadyGenerated) { |
| 335 for (Type interfaceType in cls.interfaces) { | 342 for (Type interfaceType in cls.interfaces) { |
| 336 Element element = interfaceType.element; | 343 Element element = interfaceType.element; |
| 337 if (compiler.universe.isChecks.contains(element)) { | 344 if (!alreadyGenerated.contains(element) && |
| 345 compiler.universe.isChecks.contains(element)) { |
| 346 alreadyGenerated.add(element); |
| 338 generateTypeTest(element); | 347 generateTypeTest(element); |
| 339 } | 348 } |
| 340 generateInterfacesIsTests(element, generateTypeTest); | 349 generateInterfacesIsTests(element, generateTypeTest, alreadyGenerated); |
| 341 } | 350 } |
| 342 } | 351 } |
| 343 | 352 |
| 344 void emitClasses(StringBuffer buffer) { | 353 void emitClasses(StringBuffer buffer) { |
| 345 for (ClassElement element in compiler.universe.instantiatedClasses) { | 354 for (ClassElement element in compiler.universe.instantiatedClasses) { |
| 346 ensureGenerated(element, buffer); | 355 ensureGenerated(element, buffer); |
| 347 } | 356 } |
| 348 } | 357 } |
| 349 | 358 |
| 350 void emitStaticFunctionsWithNamer(StringBuffer buffer, | 359 void emitStaticFunctionsWithNamer(StringBuffer buffer, |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 buffer.add('${namer.isolateAccess(main)}();\n'); | 693 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 685 } | 694 } |
| 686 } | 695 } |
| 687 | 696 |
| 688 String assembleProgram() { | 697 String assembleProgram() { |
| 689 measure(() { | 698 measure(() { |
| 690 StringBuffer buffer = new StringBuffer(); | 699 StringBuffer buffer = new StringBuffer(); |
| 691 buffer.add('function ${namer.ISOLATE}() {'); | 700 buffer.add('function ${namer.ISOLATE}() {'); |
| 692 emitStaticNonFinalFieldInitializations(buffer); | 701 emitStaticNonFinalFieldInitializations(buffer); |
| 693 buffer.add('}\n\n'); | 702 buffer.add('}\n\n'); |
| 703 nativeEmitter.emitIsChecks(buffer); |
| 694 emitClasses(buffer); | 704 emitClasses(buffer); |
| 695 emitStaticFunctions(buffer); | 705 emitStaticFunctions(buffer); |
| 696 emitStaticFunctionGetters(buffer); | 706 emitStaticFunctionGetters(buffer); |
| 697 emitCompileTimeConstants(buffer); | 707 emitCompileTimeConstants(buffer); |
| 698 emitStaticFinalFieldInitializations(buffer); | 708 emitStaticFinalFieldInitializations(buffer); |
| 699 nativeEmitter.emitDynamicDispatchMetadata(buffer); | 709 nativeEmitter.emitDynamicDispatchMetadata(buffer); |
| 700 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 710 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 701 emitMain(buffer); | 711 emitMain(buffer); |
| 702 compiler.assembledCode = buffer.toString(); | 712 compiler.assembledCode = buffer.toString(); |
| 703 }); | 713 }); |
| 704 return compiler.assembledCode; | 714 return compiler.assembledCode; |
| 705 } | 715 } |
| 706 } | 716 } |
| OLD | NEW |