OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
6 | 6 |
7 import '../../closure.dart' show ClosureFieldElement; | 7 import '../../closure.dart' show ClosureFieldElement; |
8 import '../../common.dart'; | 8 import '../../common.dart'; |
9 import '../../common/names.dart' show Names, Selectors; | 9 import '../../common/names.dart' show Names, Selectors; |
10 import '../../compiler.dart' show Compiler; | 10 import '../../compiler.dart' show Compiler; |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 495 } |
496 | 496 |
497 Class _buildClass(ClassElement element) { | 497 Class _buildClass(ClassElement element) { |
498 bool onlyForRti = collector.classesOnlyNeededForRti.contains(element); | 498 bool onlyForRti = collector.classesOnlyNeededForRti.contains(element); |
499 bool hasRtiField = backend.rtiNeed.classNeedsRtiField(element); | 499 bool hasRtiField = backend.rtiNeed.classNeedsRtiField(element); |
500 if (backend.nativeData.isJsInteropClass(element)) { | 500 if (backend.nativeData.isJsInteropClass(element)) { |
501 // TODO(jacobr): check whether the class has any active static fields | 501 // TODO(jacobr): check whether the class has any active static fields |
502 // if it does not we can suppress it completely. | 502 // if it does not we can suppress it completely. |
503 onlyForRti = true; | 503 onlyForRti = true; |
504 } | 504 } |
| 505 bool isClosureBaseClass = element == _compiler.commonElements.closureClass; |
505 | 506 |
506 List<Method> methods = []; | 507 List<Method> methods = []; |
507 List<StubMethod> callStubs = <StubMethod>[]; | 508 List<StubMethod> callStubs = <StubMethod>[]; |
508 | 509 |
509 ClassStubGenerator classStubGenerator = new ClassStubGenerator( | 510 ClassStubGenerator classStubGenerator = new ClassStubGenerator( |
510 namer, backend, worldBuilder, closedWorld, | 511 namer, backend, worldBuilder, closedWorld, |
511 enableMinification: _compiler.options.enableMinification); | 512 enableMinification: _compiler.options.enableMinification); |
512 RuntimeTypeGenerator runtimeTypeGenerator = | 513 RuntimeTypeGenerator runtimeTypeGenerator = |
513 new RuntimeTypeGenerator(_compiler, _task, namer); | 514 new RuntimeTypeGenerator(_compiler, _task, namer); |
514 | 515 |
(...skipping 29 matching lines...) Expand all Loading... |
544 String selectorName = selector.name; | 545 String selectorName = selector.name; |
545 if (selector.isSetter) selectorName = "$selectorName="; | 546 if (selector.isSetter) selectorName = "$selectorName="; |
546 if (backend.mirrorsData.symbolsUsed.contains(selectorName)) { | 547 if (backend.mirrorsData.symbolsUsed.contains(selectorName)) { |
547 _symbolsMap[name] = selectorName; | 548 _symbolsMap[name] = selectorName; |
548 } | 549 } |
549 noSuchMethodStubs.add( | 550 noSuchMethodStubs.add( |
550 classStubGenerator.generateStubForNoSuchMethod(name, selector)); | 551 classStubGenerator.generateStubForNoSuchMethod(name, selector)); |
551 }); | 552 }); |
552 } | 553 } |
553 | 554 |
554 if (element == _compiler.commonElements.closureClass) { | 555 if (isClosureBaseClass) { |
555 // We add a special getter here to allow for tearing off a closure from | 556 // We add a special getter to allow for tearing off a closure from itself. |
556 // itself. | |
557 js.Name name = namer.getterForMember(Names.call); | 557 js.Name name = namer.getterForMember(Names.call); |
558 js.Fun function = js.js('function() { return this; }'); | 558 js.Fun function = js.js('function() { return this; }'); |
559 callStubs.add(_buildStubMethod(name, function)); | 559 callStubs.add(_buildStubMethod(name, function)); |
560 } | 560 } |
561 | 561 |
562 ClassElement implementation = element.implementation; | 562 ClassElement implementation = element.implementation; |
563 | 563 |
564 // MixinApplications run through the members of their mixin. Here, we are | 564 // MixinApplications run through the members of their mixin. Here, we are |
565 // only interested in direct members. | 565 // only interested in direct members. |
566 if (!onlyForRti && !element.isMixinApplication) { | 566 if (!onlyForRti && !element.isMixinApplication) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 // TODO(floitsch): we shouldn't update the registry in the middle of | 610 // TODO(floitsch): we shouldn't update the registry in the middle of |
611 // building a class. | 611 // building a class. |
612 Holder holder = _registry.registerHolder(holderName); | 612 Holder holder = _registry.registerHolder(holderName); |
613 bool isInstantiated = !backend.nativeData.isJsInteropClass(element) && | 613 bool isInstantiated = !backend.nativeData.isJsInteropClass(element) && |
614 worldBuilder.directlyInstantiatedClasses.contains(element); | 614 worldBuilder.directlyInstantiatedClasses.contains(element); |
615 | 615 |
616 Class result; | 616 Class result; |
617 if (element.isMixinApplication && !onlyForRti) { | 617 if (element.isMixinApplication && !onlyForRti) { |
618 assert(!backend.nativeData.isNativeClass(element)); | 618 assert(!backend.nativeData.isNativeClass(element)); |
619 assert(methods.isEmpty); | 619 assert(methods.isEmpty); |
| 620 assert(!isClosureBaseClass); |
620 | 621 |
621 result = new MixinApplication( | 622 result = new MixinApplication( |
622 element, | 623 element, |
623 name, | 624 name, |
624 holder, | 625 holder, |
625 instanceFields, | 626 instanceFields, |
626 staticFieldsForReflection, | 627 staticFieldsForReflection, |
627 callStubs, | 628 callStubs, |
628 checkedSetters, | 629 checkedSetters, |
629 isChecks, | 630 isChecks, |
(...skipping 10 matching lines...) Expand all Loading... |
640 instanceFields, | 641 instanceFields, |
641 staticFieldsForReflection, | 642 staticFieldsForReflection, |
642 callStubs, | 643 callStubs, |
643 noSuchMethodStubs, | 644 noSuchMethodStubs, |
644 checkedSetters, | 645 checkedSetters, |
645 isChecks, | 646 isChecks, |
646 typeTests.functionTypeIndex, | 647 typeTests.functionTypeIndex, |
647 isDirectlyInstantiated: isInstantiated, | 648 isDirectlyInstantiated: isInstantiated, |
648 hasRtiField: hasRtiField, | 649 hasRtiField: hasRtiField, |
649 onlyForRti: onlyForRti, | 650 onlyForRti: onlyForRti, |
650 isNative: backend.nativeData.isNativeClass(element)); | 651 isNative: backend.nativeData.isNativeClass(element), |
| 652 isClosureBaseClass: isClosureBaseClass); |
651 } | 653 } |
652 _classes[element] = result; | 654 _classes[element] = result; |
653 return result; | 655 return result; |
654 } | 656 } |
655 | 657 |
656 bool _methodNeedsStubs(FunctionElement method) { | 658 bool _methodNeedsStubs(FunctionElement method) { |
657 return !method.functionSignature.optionalParameters.isEmpty; | 659 return !method.functionSignature.optionalParameters.isEmpty; |
658 } | 660 } |
659 | 661 |
660 bool _methodCanBeReflected(MethodElement method) { | 662 bool _methodCanBeReflected(MethodElement method) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 Constant constant = new Constant(name, holder, constantValue); | 973 Constant constant = new Constant(name, holder, constantValue); |
972 _constants[constantValue] = constant; | 974 _constants[constantValue] = constant; |
973 } | 975 } |
974 } | 976 } |
975 | 977 |
976 Holder _registerStaticStateHolder() { | 978 Holder _registerStaticStateHolder() { |
977 return _registry.registerHolder(namer.staticStateHolder, | 979 return _registry.registerHolder(namer.staticStateHolder, |
978 isStaticStateHolder: true); | 980 isStaticStateHolder: true); |
979 } | 981 } |
980 } | 982 } |
OLD | NEW |