| 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.classAccess(cls); |
| 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.classAccess(superclass); |
| 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.classAccess(superclass); |
| 606 jsAst.Node classAccess = emitter.classAccess(cls); |
| 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', emitter.classAccess(element.enclosingClass)); |
| 661 } else { | 662 } else { |
| 662 holder = js('#', namer.globalObjectFor(element)); | 663 holder = js('#', namer.globalObjectFor(element)); |
| 663 } | 664 } |
| 664 | 665 |
| 665 jsAst.Expression globalFunctionsAccess = | 666 jsAst.Expression globalFunctionsAccess = |
| 666 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); | 667 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); |
| 667 | 668 |
| 668 return js.statement( | 669 return js.statement( |
| 669 r'self.$dart_unsafe_eval.addMethod(#, #, #, #, #)', | 670 r'self.$dart_unsafe_eval.addMethod(#, #, #, #, #)', |
| 670 [partialDescriptor, js.string(name), holder, | 671 [partialDescriptor, js.string(name), holder, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 800 |
| 800 PartialFunctionElement get before => element; | 801 PartialFunctionElement get before => element; |
| 801 | 802 |
| 802 PartialFunctionElement get after => null; | 803 PartialFunctionElement get after => null; |
| 803 | 804 |
| 804 void captureState() { | 805 void captureState() { |
| 805 if (wasStateCaptured) throw "captureState was called twice."; | 806 if (wasStateCaptured) throw "captureState was called twice."; |
| 806 wasStateCaptured = true; | 807 wasStateCaptured = true; |
| 807 | 808 |
| 808 if (element.isInstanceMember) { | 809 if (element.isInstanceMember) { |
| 809 elementAccess = namer.elementAccess(element.enclosingClass); | 810 elementAccess = emitter.classAccess(element.enclosingClass); |
| 810 name = namer.getNameOfMember(element); | 811 name = namer.getNameOfMember(element); |
| 811 } else { | 812 } else { |
| 812 elementAccess = namer.elementAccess(element); | 813 elementAccess = emitter.staticFunctionAccess(element); |
| 813 } | 814 } |
| 814 } | 815 } |
| 815 | 816 |
| 816 PartialFunctionElement apply() { | 817 PartialFunctionElement apply() { |
| 817 if (!wasStateCaptured) throw "captureState must be called before apply."; | 818 if (!wasStateCaptured) throw "captureState must be called before apply."; |
| 818 removeFromEnclosing(); | 819 removeFromEnclosing(); |
| 819 reuseElement(); | 820 reuseElement(); |
| 820 return null; | 821 return null; |
| 821 } | 822 } |
| 822 | 823 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 847 RemovedClassUpdate(Compiler compiler, this.element) | 848 RemovedClassUpdate(Compiler compiler, this.element) |
| 848 : super(compiler); | 849 : super(compiler); |
| 849 | 850 |
| 850 PartialClassElement get before => element; | 851 PartialClassElement get before => element; |
| 851 | 852 |
| 852 PartialClassElement get after => null; | 853 PartialClassElement get after => null; |
| 853 | 854 |
| 854 void captureState() { | 855 void captureState() { |
| 855 if (wasStateCaptured) throw "captureState was called twice."; | 856 if (wasStateCaptured) throw "captureState was called twice."; |
| 856 wasStateCaptured = true; | 857 wasStateCaptured = true; |
| 857 | 858 accessToStatics.add(emitter.classAccess(element)); |
| 858 accessToStatics.add(namer.elementAccess(element)); | |
| 859 | 859 |
| 860 element.forEachLocalMember((ElementX member) { | 860 element.forEachLocalMember((ElementX member) { |
| 861 if (!member.isInstanceMember) { | 861 if (!member.isInstanceMember) { |
| 862 accessToStatics.add(namer.elementAccess(member)); | 862 accessToStatics.add(emitter.staticFunctionAccess(member)); |
| 863 } | 863 } |
| 864 }); | 864 }); |
| 865 } | 865 } |
| 866 | 866 |
| 867 PartialClassElement apply() { | 867 PartialClassElement apply() { |
| 868 if (!wasStateCaptured) { | 868 if (!wasStateCaptured) { |
| 869 throw new StateError("captureState must be called before apply."); | 869 throw new StateError("captureState must be called before apply."); |
| 870 } | 870 } |
| 871 | 871 |
| 872 removeFromEnclosing(); | 872 removeFromEnclosing(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 : super(compiler); | 909 : super(compiler); |
| 910 | 910 |
| 911 PartialFieldList get before => element.declarationSite; | 911 PartialFieldList get before => element.declarationSite; |
| 912 | 912 |
| 913 PartialFieldList get after => null; | 913 PartialFieldList get after => null; |
| 914 | 914 |
| 915 void captureState() { | 915 void captureState() { |
| 916 if (wasStateCaptured) throw "captureState was called twice."; | 916 if (wasStateCaptured) throw "captureState was called twice."; |
| 917 wasStateCaptured = true; | 917 wasStateCaptured = true; |
| 918 | 918 |
| 919 elementAccess = namer.elementAccess(element.enclosingClass); | 919 elementAccess = emitter.classAccess(element.enclosingClass); |
| 920 getterName = namer.getterName(element); | 920 getterName = namer.getterName(element); |
| 921 setterName = namer.setterName(element); | 921 setterName = namer.setterName(element); |
| 922 } | 922 } |
| 923 | 923 |
| 924 FieldElementX apply() { | 924 FieldElementX apply() { |
| 925 if (!wasStateCaptured) { | 925 if (!wasStateCaptured) { |
| 926 throw new StateError("captureState must be called before apply."); | 926 throw new StateError("captureState must be called before apply."); |
| 927 } | 927 } |
| 928 | 928 |
| 929 removeFromEnclosing(); | 929 removeFromEnclosing(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 List<String> computeFields(ClassElement cls) { | 1145 List<String> computeFields(ClassElement cls) { |
| 1146 // TODO(ahe): Rewrite for new emitter. | 1146 // TODO(ahe): Rewrite for new emitter. |
| 1147 ClassBuilder builder = new ClassBuilder(cls, namer); | 1147 ClassBuilder builder = new ClassBuilder(cls, namer); |
| 1148 classEmitter.emitFields(cls, builder, ""); | 1148 classEmitter.emitFields(cls, builder, ""); |
| 1149 return builder.fields; | 1149 return builder.fields; |
| 1150 } | 1150 } |
| 1151 } | 1151 } |
| 1152 | 1152 |
| 1153 // TODO(ahe): Remove this method. | 1153 // TODO(ahe): Remove this method. |
| 1154 NO_WARN(x) => x; | 1154 NO_WARN(x) => x; |
| OLD | NEW |