Chromium Code Reviews| 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_incremental.library_updater; | 5 library dart2js_incremental.library_updater; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 | 569 |
| 570 List<jsAst.Statement> updates = <jsAst.Statement>[]; | 570 List<jsAst.Statement> updates = <jsAst.Statement>[]; |
| 571 | 571 |
| 572 Set newClasses = | 572 Set newClasses = |
| 573 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); | 573 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); |
| 574 newClasses.removeAll(existingClasses); | 574 newClasses.removeAll(existingClasses); |
| 575 | 575 |
| 576 List<jsAst.Statement> inherits = <jsAst.Statement>[]; | 576 List<jsAst.Statement> inherits = <jsAst.Statement>[]; |
| 577 | 577 |
| 578 for (ClassElementX cls in newClasses) { | 578 for (ClassElementX cls in newClasses) { |
| 579 jsAst.Node classAccess = namer.elementAccess(cls); | 579 jsAst.Node classAccess = emitter.globalPropertyAccess(cls); |
|
floitsch
2014/12/03 17:02:26
classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 580 String name = namer.getNameOfClass(cls); | 580 String name = namer.getNameOfClass(cls); |
| 581 | 581 |
| 582 updates.add( | 582 updates.add( |
| 583 js.statement( | 583 js.statement( |
| 584 r'# = #', [classAccess, invokeDefineClass(cls)])); | 584 r'# = #', [classAccess, invokeDefineClass(cls)])); |
| 585 | 585 |
| 586 ClassElement superclass = cls.superclass; | 586 ClassElement superclass = cls.superclass; |
| 587 if (superclass != null) { | 587 if (superclass != null) { |
| 588 jsAst.Node superAccess = namer.elementAccess(superclass); | 588 jsAst.Node superAccess = emitter.globalPropertyAccess(superclass); |
|
floitsch
2014/12/03 17:02:27
classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 589 inherits.add( | 589 inherits.add( |
| 590 js.statement( | 590 js.statement( |
| 591 r'self.$dart_unsafe_eval.inheritFrom(#, #)', | 591 r'self.$dart_unsafe_eval.inheritFrom(#, #)', |
| 592 [classAccess, superAccess])); | 592 [classAccess, superAccess])); |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 | 595 |
| 596 // Call inheritFrom after all classes have been created. This way we don't | 596 // Call inheritFrom after all classes have been created. This way we don't |
| 597 // need to sort the classes by having superclasses defined before their | 597 // need to sort the classes by having superclasses defined before their |
| 598 // subclasses. | 598 // subclasses. |
| 599 updates.addAll(inherits); | 599 updates.addAll(inherits); |
| 600 | 600 |
| 601 for (ClassElementX cls in changedClasses) { | 601 for (ClassElementX cls in changedClasses) { |
| 602 ClassElement superclass = cls.superclass; | 602 ClassElement superclass = cls.superclass; |
| 603 jsAst.Node superAccess = | 603 jsAst.Node superAccess = |
| 604 superclass == null ? js('null') : namer.elementAccess(superclass); | 604 superclass == null ? js('null') |
| 605 jsAst.Node classAccess = namer.elementAccess(cls); | 605 : emitter.globalPropertyAccess(superclass); |
|
floitsch
2014/12/03 17:02:27
classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 606 jsAst.Node classAccess = emitter.globalPropertyAccess(cls); | |
|
floitsch
2014/12/03 17:02:27
classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 606 updates.add( | 607 updates.add( |
| 607 js.statement( | 608 js.statement( |
| 608 r'# = self.$dart_unsafe_eval.schemaChange(#, #, #)', | 609 r'# = self.$dart_unsafe_eval.schemaChange(#, #, #)', |
| 609 [classAccess, invokeDefineClass(cls), classAccess, superAccess])); | 610 [classAccess, invokeDefineClass(cls), classAccess, superAccess])); |
| 610 } | 611 } |
| 611 | 612 |
| 612 for (RemovalUpdate update in removals) { | 613 for (RemovalUpdate update in removals) { |
| 613 update.writeUpdateJsOn(updates); | 614 update.writeUpdateJsOn(updates); |
| 614 } | 615 } |
| 615 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 616 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 | 651 |
| 651 String name = info.name; | 652 String name = info.name; |
| 652 jsAst.Node function = info.code; | 653 jsAst.Node function = info.code; |
| 653 bool isStatic = !element.isInstanceMember; | 654 bool isStatic = !element.isInstanceMember; |
| 654 | 655 |
| 655 /// Either a global object (non-instance members) or a prototype (instance | 656 /// Either a global object (non-instance members) or a prototype (instance |
| 656 /// members). | 657 /// members). |
| 657 jsAst.Node holder; | 658 jsAst.Node holder; |
| 658 | 659 |
| 659 if (element.isInstanceMember) { | 660 if (element.isInstanceMember) { |
| 660 holder = js('#.prototype', namer.elementAccess(element.enclosingClass)); | 661 holder = js('#.prototype', |
| 662 emitter.globalPropertyAccess(element.enclosingClass)); | |
|
floitsch
2014/12/03 17:02:27
classAccess, jsConstructorAccess, or prototypeAcce
zarah
2014/12/05 08:22:52
Done.
| |
| 661 } else { | 663 } else { |
| 662 holder = js('#', namer.globalObjectFor(element)); | 664 holder = js('#', namer.globalObjectFor(element)); |
| 663 } | 665 } |
| 664 | 666 |
| 665 jsAst.Expression globalFunctionsAccess = | 667 jsAst.Expression globalFunctionsAccess = |
| 666 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); | 668 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); |
| 667 | 669 |
| 668 return js.statement( | 670 return js.statement( |
| 669 r'self.$dart_unsafe_eval.addMethod(#, #, #, #, #)', | 671 r'self.$dart_unsafe_eval.addMethod(#, #, #, #, #)', |
| 670 [partialDescriptor, js.string(name), holder, | 672 [partialDescriptor, js.string(name), holder, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 | 801 |
| 800 PartialFunctionElement get before => element; | 802 PartialFunctionElement get before => element; |
| 801 | 803 |
| 802 PartialFunctionElement get after => null; | 804 PartialFunctionElement get after => null; |
| 803 | 805 |
| 804 void captureState() { | 806 void captureState() { |
| 805 if (wasStateCaptured) throw "captureState was called twice."; | 807 if (wasStateCaptured) throw "captureState was called twice."; |
| 806 wasStateCaptured = true; | 808 wasStateCaptured = true; |
| 807 | 809 |
| 808 if (element.isInstanceMember) { | 810 if (element.isInstanceMember) { |
| 809 elementAccess = namer.elementAccess(element.enclosingClass); | 811 elementAccess = emitter.globalPropertyAccess(element.enclosingClass); |
|
floitsch
2014/12/03 17:02:26
classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 810 name = namer.getNameOfMember(element); | 812 name = namer.getNameOfMember(element); |
| 811 } else { | 813 } else { |
| 812 elementAccess = namer.elementAccess(element); | 814 elementAccess = emitter.globalPropertyAccess(element); |
|
floitsch
2014/12/03 17:02:26
I believe staticFunctionAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 813 } | 815 } |
| 814 } | 816 } |
| 815 | 817 |
| 816 PartialFunctionElement apply() { | 818 PartialFunctionElement apply() { |
| 817 if (!wasStateCaptured) throw "captureState must be called before apply."; | 819 if (!wasStateCaptured) throw "captureState must be called before apply."; |
| 818 removeFromEnclosing(); | 820 removeFromEnclosing(); |
| 819 reuseElement(); | 821 reuseElement(); |
| 820 return null; | 822 return null; |
| 821 } | 823 } |
| 822 | 824 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 848 : super(compiler); | 850 : super(compiler); |
| 849 | 851 |
| 850 PartialClassElement get before => element; | 852 PartialClassElement get before => element; |
| 851 | 853 |
| 852 PartialClassElement get after => null; | 854 PartialClassElement get after => null; |
| 853 | 855 |
| 854 void captureState() { | 856 void captureState() { |
| 855 if (wasStateCaptured) throw "captureState was called twice."; | 857 if (wasStateCaptured) throw "captureState was called twice."; |
| 856 wasStateCaptured = true; | 858 wasStateCaptured = true; |
| 857 | 859 |
| 858 accessToStatics.add(namer.elementAccess(element)); | 860 accessToStatics.add(emitter.globalPropertyAccess(element)); |
|
floitsch
2014/12/03 17:02:26
not sure.
probably classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 859 | 861 |
| 860 element.forEachLocalMember((ElementX member) { | 862 element.forEachLocalMember((ElementX member) { |
| 861 if (!member.isInstanceMember) { | 863 if (!member.isInstanceMember) { |
| 862 accessToStatics.add(namer.elementAccess(member)); | 864 accessToStatics.add(emitter.globalPropertyAccess(member)); |
|
floitsch
2014/12/03 17:02:26
staticFunctionAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 863 } | 865 } |
| 864 }); | 866 }); |
| 865 } | 867 } |
| 866 | 868 |
| 867 PartialClassElement apply() { | 869 PartialClassElement apply() { |
| 868 if (!wasStateCaptured) { | 870 if (!wasStateCaptured) { |
| 869 throw new StateError("captureState must be called before apply."); | 871 throw new StateError("captureState must be called before apply."); |
| 870 } | 872 } |
| 871 | 873 |
| 872 removeFromEnclosing(); | 874 removeFromEnclosing(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 : super(compiler); | 911 : super(compiler); |
| 910 | 912 |
| 911 PartialFieldList get before => element.declarationSite; | 913 PartialFieldList get before => element.declarationSite; |
| 912 | 914 |
| 913 PartialFieldList get after => null; | 915 PartialFieldList get after => null; |
| 914 | 916 |
| 915 void captureState() { | 917 void captureState() { |
| 916 if (wasStateCaptured) throw "captureState was called twice."; | 918 if (wasStateCaptured) throw "captureState was called twice."; |
| 917 wasStateCaptured = true; | 919 wasStateCaptured = true; |
| 918 | 920 |
| 919 elementAccess = namer.elementAccess(element.enclosingClass); | 921 elementAccess = emitter.globalPropertyAccess(element.enclosingClass); |
|
floitsch
2014/12/03 17:02:27
classAccess
zarah
2014/12/05 08:22:52
Done.
| |
| 920 getterName = namer.getterName(element); | 922 getterName = namer.getterName(element); |
| 921 setterName = namer.setterName(element); | 923 setterName = namer.setterName(element); |
| 922 } | 924 } |
| 923 | 925 |
| 924 FieldElementX apply() { | 926 FieldElementX apply() { |
| 925 if (!wasStateCaptured) { | 927 if (!wasStateCaptured) { |
| 926 throw new StateError("captureState must be called before apply."); | 928 throw new StateError("captureState must be called before apply."); |
| 927 } | 929 } |
| 928 | 930 |
| 929 removeFromEnclosing(); | 931 removeFromEnclosing(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 List<String> computeFields(ClassElement cls) { | 1147 List<String> computeFields(ClassElement cls) { |
| 1146 // TODO(ahe): Rewrite for new emitter. | 1148 // TODO(ahe): Rewrite for new emitter. |
| 1147 ClassBuilder builder = new ClassBuilder(cls, namer); | 1149 ClassBuilder builder = new ClassBuilder(cls, namer); |
| 1148 classEmitter.emitFields(cls, builder, ""); | 1150 classEmitter.emitFields(cls, builder, ""); |
| 1149 return builder.fields; | 1151 return builder.fields; |
| 1150 } | 1152 } |
| 1151 } | 1153 } |
| 1152 | 1154 |
| 1153 // TODO(ahe): Remove this method. | 1155 // TODO(ahe): Remove this method. |
| 1154 NO_WARN(x) => x; | 1156 NO_WARN(x) => x; |
| OLD | NEW |