| 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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 Method _buildStubMethod(js.Name name, js.Expression code, | 799 Method _buildStubMethod(js.Name name, js.Expression code, |
| 800 {MemberElement element}) { | 800 {MemberElement element}) { |
| 801 return new StubMethod(name, code, element: element); | 801 return new StubMethod(name, code, element: element); |
| 802 } | 802 } |
| 803 | 803 |
| 804 // The getInterceptor methods directly access the prototype of classes. | 804 // The getInterceptor methods directly access the prototype of classes. |
| 805 // We must evaluate these classes eagerly so that the prototype is | 805 // We must evaluate these classes eagerly so that the prototype is |
| 806 // accessible. | 806 // accessible. |
| 807 void _markEagerInterceptorClasses() { | 807 void _markEagerInterceptorClasses() { |
| 808 Map<js.Name, Set<ClassElement>> specializedGetInterceptors = | 808 Map<js.Name, Set<ClassElement>> specializedGetInterceptors = |
| 809 backend.specializedGetInterceptors; | 809 backend.interceptorData.specializedGetInterceptors; |
| 810 for (Set<ClassElement> classes in specializedGetInterceptors.values) { | 810 for (Set<ClassElement> classes in specializedGetInterceptors.values) { |
| 811 for (ClassElement element in classes) { | 811 for (ClassElement element in classes) { |
| 812 Class cls = _classes[element]; | 812 Class cls = _classes[element]; |
| 813 if (cls != null) cls.isEager = true; | 813 if (cls != null) cls.isEager = true; |
| 814 } | 814 } |
| 815 } | 815 } |
| 816 } | 816 } |
| 817 | 817 |
| 818 Iterable<StaticStubMethod> _generateGetInterceptorMethods() { | 818 Iterable<StaticStubMethod> _generateGetInterceptorMethods() { |
| 819 InterceptorStubGenerator stubGenerator = | 819 InterceptorStubGenerator stubGenerator = |
| 820 new InterceptorStubGenerator(_compiler, namer, backend, closedWorld); | 820 new InterceptorStubGenerator(_compiler, namer, backend, closedWorld); |
| 821 | 821 |
| 822 String holderName = | 822 String holderName = |
| 823 namer.globalObjectForLibrary(helpers.interceptorsLibrary); | 823 namer.globalObjectForLibrary(helpers.interceptorsLibrary); |
| 824 // TODO(floitsch): we shouldn't update the registry in the middle of | 824 // TODO(floitsch): we shouldn't update the registry in the middle of |
| 825 // generating the interceptor methods. | 825 // generating the interceptor methods. |
| 826 Holder holder = _registry.registerHolder(holderName); | 826 Holder holder = _registry.registerHolder(holderName); |
| 827 | 827 |
| 828 Map<js.Name, Set<ClassElement>> specializedGetInterceptors = | 828 Map<js.Name, Set<ClassElement>> specializedGetInterceptors = |
| 829 backend.specializedGetInterceptors; | 829 backend.interceptorData.specializedGetInterceptors; |
| 830 List<js.Name> names = specializedGetInterceptors.keys.toList()..sort(); | 830 List<js.Name> names = specializedGetInterceptors.keys.toList()..sort(); |
| 831 return names.map((js.Name name) { | 831 return names.map((js.Name name) { |
| 832 Set<ClassElement> classes = specializedGetInterceptors[name]; | 832 Set<ClassElement> classes = specializedGetInterceptors[name]; |
| 833 js.Expression code = stubGenerator.generateGetInterceptorMethod(classes); | 833 js.Expression code = stubGenerator.generateGetInterceptorMethod(classes); |
| 834 return new StaticStubMethod(name, holder, code); | 834 return new StaticStubMethod(name, holder, code); |
| 835 }); | 835 }); |
| 836 } | 836 } |
| 837 | 837 |
| 838 List<Field> _buildFields(Element holder, bool visitStatics) { | 838 List<Field> _buildFields(Element holder, bool visitStatics) { |
| 839 List<Field> fields = <Field>[]; | 839 List<Field> fields = <Field>[]; |
| 840 new FieldVisitor(_compiler, namer, closedWorld) | 840 new FieldVisitor(_compiler, namer, closedWorld) |
| 841 .visitFields(holder, visitStatics, (FieldElement field, | 841 .visitFields(holder, visitStatics, (FieldElement field, |
| 842 js.Name name, | 842 js.Name name, |
| 843 js.Name accessorName, | 843 js.Name accessorName, |
| 844 bool needsGetter, | 844 bool needsGetter, |
| 845 bool needsSetter, | 845 bool needsSetter, |
| 846 bool needsCheckedSetter) { | 846 bool needsCheckedSetter) { |
| 847 assert(invariant(field, field.isDeclaration)); | 847 assert(invariant(field, field.isDeclaration)); |
| 848 | 848 |
| 849 int getterFlags = 0; | 849 int getterFlags = 0; |
| 850 if (needsGetter) { | 850 if (needsGetter) { |
| 851 if (visitStatics || !backend.fieldHasInterceptedGetter(field)) { | 851 if (visitStatics || |
| 852 !backend.interceptorData.fieldHasInterceptedGetter(field)) { |
| 852 getterFlags = 1; | 853 getterFlags = 1; |
| 853 } else { | 854 } else { |
| 854 getterFlags += 2; | 855 getterFlags += 2; |
| 855 // TODO(sra): 'isInterceptorClass' might not be the correct test | 856 // TODO(sra): 'isInterceptorClass' might not be the correct test |
| 856 // for methods forced to use the interceptor convention because | 857 // for methods forced to use the interceptor convention because |
| 857 // the method's class was elsewhere mixed-in to an interceptor. | 858 // the method's class was elsewhere mixed-in to an interceptor. |
| 858 if (!backend.isInterceptorClass(holder)) { | 859 if (!backend.interceptorData.isInterceptorClass(holder)) { |
| 859 getterFlags += 1; | 860 getterFlags += 1; |
| 860 } | 861 } |
| 861 } | 862 } |
| 862 } | 863 } |
| 863 | 864 |
| 864 int setterFlags = 0; | 865 int setterFlags = 0; |
| 865 if (needsSetter) { | 866 if (needsSetter) { |
| 866 if (visitStatics || !backend.fieldHasInterceptedSetter(field)) { | 867 if (visitStatics || |
| 868 !backend.interceptorData.fieldHasInterceptedSetter(field)) { |
| 867 setterFlags = 1; | 869 setterFlags = 1; |
| 868 } else { | 870 } else { |
| 869 setterFlags += 2; | 871 setterFlags += 2; |
| 870 if (!backend.isInterceptorClass(holder)) { | 872 if (!backend.interceptorData.isInterceptorClass(holder)) { |
| 871 setterFlags += 1; | 873 setterFlags += 1; |
| 872 } | 874 } |
| 873 } | 875 } |
| 874 } | 876 } |
| 875 | 877 |
| 876 fields.add(new Field(field, name, accessorName, getterFlags, setterFlags, | 878 fields.add(new Field(field, name, accessorName, getterFlags, setterFlags, |
| 877 needsCheckedSetter)); | 879 needsCheckedSetter)); |
| 878 }); | 880 }); |
| 879 | 881 |
| 880 return fields; | 882 return fields; |
| 881 } | 883 } |
| 882 | 884 |
| 883 Iterable<StaticStubMethod> _generateOneShotInterceptors() { | 885 Iterable<StaticStubMethod> _generateOneShotInterceptors() { |
| 884 InterceptorStubGenerator stubGenerator = | 886 InterceptorStubGenerator stubGenerator = |
| 885 new InterceptorStubGenerator(_compiler, namer, backend, closedWorld); | 887 new InterceptorStubGenerator(_compiler, namer, backend, closedWorld); |
| 886 | 888 |
| 887 String holderName = | 889 String holderName = |
| 888 namer.globalObjectForLibrary(helpers.interceptorsLibrary); | 890 namer.globalObjectForLibrary(helpers.interceptorsLibrary); |
| 889 // TODO(floitsch): we shouldn't update the registry in the middle of | 891 // TODO(floitsch): we shouldn't update the registry in the middle of |
| 890 // generating the interceptor methods. | 892 // generating the interceptor methods. |
| 891 Holder holder = _registry.registerHolder(holderName); | 893 Holder holder = _registry.registerHolder(holderName); |
| 892 | 894 |
| 893 List<js.Name> names = backend.oneShotInterceptors.keys.toList()..sort(); | 895 List<js.Name> names = |
| 896 backend.interceptorData.oneShotInterceptors.keys.toList()..sort(); |
| 894 return names.map((js.Name name) { | 897 return names.map((js.Name name) { |
| 895 js.Expression code = stubGenerator.generateOneShotInterceptor(name); | 898 js.Expression code = stubGenerator.generateOneShotInterceptor(name); |
| 896 return new StaticStubMethod(name, holder, code); | 899 return new StaticStubMethod(name, holder, code); |
| 897 }); | 900 }); |
| 898 } | 901 } |
| 899 | 902 |
| 900 StaticDartMethod _buildStaticMethod(MethodElement element) { | 903 StaticDartMethod _buildStaticMethod(MethodElement element) { |
| 901 js.Name name = namer.methodPropertyName(element); | 904 js.Name name = namer.methodPropertyName(element); |
| 902 String holder = namer.globalObjectFor(element); | 905 String holder = namer.globalObjectFor(element); |
| 903 js.Expression code = backend.generatedCode[element]; | 906 js.Expression code = backend.generatedCode[element]; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 Constant constant = new Constant(name, holder, constantValue); | 966 Constant constant = new Constant(name, holder, constantValue); |
| 964 _constants[constantValue] = constant; | 967 _constants[constantValue] = constant; |
| 965 } | 968 } |
| 966 } | 969 } |
| 967 | 970 |
| 968 Holder _registerStaticStateHolder() { | 971 Holder _registerStaticStateHolder() { |
| 969 return _registry.registerHolder(namer.staticStateHolder, | 972 return _registry.registerHolder(namer.staticStateHolder, |
| 970 isStaticStateHolder: true); | 973 isStaticStateHolder: true); |
| 971 } | 974 } |
| 972 } | 975 } |
| OLD | NEW |