OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of dart2js.js_emitter.startup_emitter.model_emitter; | 5 part of dart2js.js_emitter.startup_emitter.model_emitter; |
6 | 6 |
7 /// The name of the property that stores the tear-off getter on a static | 7 /// The name of the property that stores the tear-off getter on a static |
8 /// function. | 8 /// function. |
9 /// | 9 /// |
10 /// This property is only used when isolates are used. | 10 /// This property is only used when isolates are used. |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 } | 815 } |
816 | 816 |
817 return properties; | 817 return properties; |
818 } | 818 } |
819 | 819 |
820 /// Emits the inheritance block of the fragment. | 820 /// Emits the inheritance block of the fragment. |
821 /// | 821 /// |
822 /// In this section prototype chains are updated and mixin functions are | 822 /// In this section prototype chains are updated and mixin functions are |
823 /// copied. | 823 /// copied. |
824 js.Statement emitInheritance(Fragment fragment) { | 824 js.Statement emitInheritance(Fragment fragment) { |
825 List<js.Expression> inheritCalls = <js.Expression>[]; | 825 List<js.Statement> inheritCalls = <js.Statement>[]; |
826 List<js.Expression> mixinCalls = <js.Expression>[]; | 826 List<js.Statement> mixinCalls = <js.Statement>[]; |
827 | |
828 Map<Class, List<Class>> subclasses = <Class, List<Class>>{}; | |
827 | 829 |
828 Set<Class> classesInFragment = new Set<Class>(); | 830 Set<Class> classesInFragment = new Set<Class>(); |
829 for (Library library in fragment.libraries) { | 831 for (Library library in fragment.libraries) { |
830 classesInFragment.addAll(library.classes); | 832 classesInFragment.addAll(library.classes); |
831 } | 833 } |
832 | 834 |
833 Set<Class> emittedClasses = new Set<Class>(); | 835 Set<Class> emittedClasses = new Set<Class>(); |
834 | 836 |
835 void emitInheritanceForClass(cls) { | 837 void emitInheritanceForClass(cls) { |
Siggi Cherem (dart-lang)
2017/04/17 20:16:20
nit: maybe rename:
emittedClasses => seen
emitIn
sra1
2017/04/17 21:44:05
Done.
| |
836 if (cls == null || emittedClasses.contains(cls)) return; | 838 if (cls == null || emittedClasses.contains(cls)) return; |
837 | 839 |
838 Class superclass = cls.superclass; | 840 Class superclass = cls.superclass; |
839 if (classesInFragment.contains(superclass)) { | 841 if (classesInFragment.contains(superclass)) { |
840 emitInheritanceForClass(superclass); | 842 emitInheritanceForClass(superclass); |
841 } | 843 } |
842 | 844 |
843 js.Expression superclassReference = (superclass == null) | 845 subclasses.putIfAbsent(superclass, () => <Class>[]).add(cls); |
844 ? new js.LiteralNull() | |
845 : classReference(superclass); | |
846 | |
847 inheritCalls.add( | |
848 js.js('inherit(#, #)', [classReference(cls), superclassReference])); | |
849 | 846 |
850 emittedClasses.add(cls); | 847 emittedClasses.add(cls); |
851 } | 848 } |
852 | 849 |
853 for (Library library in fragment.libraries) { | 850 for (Library library in fragment.libraries) { |
854 for (Class cls in library.classes) { | 851 for (Class cls in library.classes) { |
855 emitInheritanceForClass(cls); | 852 emitInheritanceForClass(cls); |
856 | 853 |
857 if (cls.isMixinApplication) { | 854 if (cls.isMixinApplication) { |
858 MixinApplication mixin = cls; | 855 MixinApplication mixin = cls; |
859 mixinCalls.add(js.js('mixin(#, #)', | 856 mixinCalls.add(js.js.statement('mixin(#, #)', |
860 [classReference(cls), classReference(mixin.mixinClass)])); | 857 [classReference(cls), classReference(mixin.mixinClass)])); |
861 } | 858 } |
862 } | 859 } |
863 } | 860 } |
864 | 861 |
862 js.Expression temp = null; | |
863 for (Class superclass in subclasses.keys) { | |
864 List<Class> list = subclasses[superclass]; | |
865 js.Expression superclassReference = (superclass == null) | |
866 ? new js.LiteralNull() | |
867 : classReference(superclass); | |
868 if (list.length == 1) { | |
869 inheritCalls.add(js.js.statement('inherit(#, #)', | |
870 [classReference(list.single), superclassReference])); | |
871 } else { | |
872 if (temp == null) { | |
873 inheritCalls.add(js.js.statement('var _ = #', superclassReference)); | |
874 temp = js.js('_'); | |
875 } else { | |
876 inheritCalls.add(js.js.statement('_ = #', superclassReference)); | |
877 } | |
878 for (Class cls in list) { | |
879 inheritCalls | |
880 .add(js.js.statement('inherit(#, _)', classReference(cls))); | |
881 } | |
882 } | |
883 } | |
884 | |
865 return wrapPhase( | 885 return wrapPhase( |
866 'inheritance', | 886 'inheritance', js.js.statement('{#; #;}', [inheritCalls, mixinCalls])); |
867 js.js.statement('{#; #;}', [ | |
868 inheritCalls.map((e) => new js.ExpressionStatement(e)), | |
869 mixinCalls.map((e) => new js.ExpressionStatement(e)) | |
870 ])); | |
871 } | 887 } |
872 | 888 |
873 /// Emits the setup of method aliases. | 889 /// Emits the setup of method aliases. |
874 /// | 890 /// |
875 /// This step consists of simply copying JavaScript functions to their | 891 /// This step consists of simply copying JavaScript functions to their |
876 /// aliased names so they point to the same function. | 892 /// aliased names so they point to the same function. |
877 js.Statement emitInstanceMethodAliases(Fragment fragment) { | 893 js.Statement emitInstanceMethodAliases(Fragment fragment) { |
878 List<js.Statement> assignments = <js.Statement>[]; | 894 List<js.Statement> assignments = <js.Statement>[]; |
879 | 895 |
880 for (Library library in fragment.libraries) { | 896 for (Library library in fragment.libraries) { |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1392 } | 1408 } |
1393 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1409 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
1394 js.objectLiteral(interceptorsByTag))); | 1410 js.objectLiteral(interceptorsByTag))); |
1395 statements.add( | 1411 statements.add( |
1396 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); | 1412 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); |
1397 statements.addAll(subclassAssignments); | 1413 statements.addAll(subclassAssignments); |
1398 | 1414 |
1399 return wrapPhase('nativeSupport', new js.Block(statements)); | 1415 return wrapPhase('nativeSupport', new js.Block(statements)); |
1400 } | 1416 } |
1401 } | 1417 } |
OLD | NEW |