Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 11308257: - Parse the return type of JS during resolution to know what can be instantiated there. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 js_backend; 5 part of js_backend;
6 6
7 typedef void Recompile(Element element); 7 typedef void Recompile(Element element);
8 8
9 class ReturnInfo { 9 class ReturnInfo {
10 HType returnType; 10 HType returnType;
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 754 }
755 755
756 void initializeInterceptorElements() { 756 void initializeInterceptorElements() {
757 objectInterceptorClass = 757 objectInterceptorClass =
758 compiler.findInterceptor(const SourceString('ObjectInterceptor')); 758 compiler.findInterceptor(const SourceString('ObjectInterceptor'));
759 getInterceptorMethod = 759 getInterceptorMethod =
760 compiler.findInterceptor(const SourceString('getInterceptor')); 760 compiler.findInterceptor(const SourceString('getInterceptor'));
761 List<ClassElement> classes = [ 761 List<ClassElement> classes = [
762 jsStringClass = compiler.findInterceptor(const SourceString('JSString')), 762 jsStringClass = compiler.findInterceptor(const SourceString('JSString')),
763 jsArrayClass = compiler.findInterceptor(const SourceString('JSArray')), 763 jsArrayClass = compiler.findInterceptor(const SourceString('JSArray')),
764 jsNumberClass = compiler.findInterceptor(const SourceString('JSNumber')), 764 // The int class must be before the double class, because the
765 // emitter relies on this list for the order of type checks.
765 jsIntClass = compiler.findInterceptor(const SourceString('JSInt')), 766 jsIntClass = compiler.findInterceptor(const SourceString('JSInt')),
766 jsDoubleClass = compiler.findInterceptor(const SourceString('JSDouble')), 767 jsDoubleClass = compiler.findInterceptor(const SourceString('JSDouble')),
768 jsNumberClass = compiler.findInterceptor(const SourceString('JSNumber')),
767 jsNullClass = compiler.findInterceptor(const SourceString('JSNull')), 769 jsNullClass = compiler.findInterceptor(const SourceString('JSNull')),
768 jsFunctionClass = 770 jsFunctionClass =
769 compiler.findInterceptor(const SourceString('JSFunction')), 771 compiler.findInterceptor(const SourceString('JSFunction')),
770 jsBoolClass = compiler.findInterceptor(const SourceString('JSBool'))]; 772 jsBoolClass = compiler.findInterceptor(const SourceString('JSBool'))];
771 773
772 jsArrayClass.ensureResolved(compiler); 774 jsArrayClass.ensureResolved(compiler);
773 jsArrayLength = 775 jsArrayLength =
774 jsArrayClass.lookupLocalMember(const SourceString('length')); 776 jsArrayClass.lookupLocalMember(const SourceString('length'));
775 777
776 jsStringClass.ensureResolved(compiler); 778 jsStringClass.ensureResolved(compiler);
777 jsStringLength = 779 jsStringLength =
778 jsStringClass.lookupLocalMember(const SourceString('length')); 780 jsStringClass.lookupLocalMember(const SourceString('length'));
779 781
780 for (ClassElement cls in classes) { 782 for (ClassElement cls in classes) {
781 if (cls != null) interceptedClasses[cls] = null; 783 if (cls != null) interceptedClasses[cls] = null;
782 } 784 }
783 } 785 }
784 786
785 void addInterceptors(ClassElement cls) { 787 void addInterceptors(ClassElement cls, Enqueuer enqueuer) {
786 cls.ensureResolved(compiler); 788 if (enqueuer.isResolutionQueue) {
787 cls.forEachMember((ClassElement classElement, Element member) { 789 cls.ensureResolved(compiler);
788 Set<Element> set = interceptedElements.putIfAbsent( 790 cls.forEachMember((ClassElement classElement, Element member) {
789 member.name, () => new Set<Element>()); 791 Set<Element> set = interceptedElements.putIfAbsent(
790 set.add(member); 792 member.name, () => new Set<Element>());
791 }, 793 set.add(member);
792 includeSuperMembers: true); 794 },
795 includeSuperMembers: true);
796 }
797 enqueuer.registerInstantiatedClass(cls);
793 } 798 }
794 799
795 String registerSpecializedGetInterceptor(Set<ClassElement> classes) { 800 String registerSpecializedGetInterceptor(Set<ClassElement> classes) {
796 compiler.enqueuer.codegen.registerInstantiatedClass(objectInterceptorClass); 801 compiler.enqueuer.codegen.registerInstantiatedClass(objectInterceptorClass);
797 if (classes.contains(compiler.objectClass)) { 802 if (classes.contains(compiler.objectClass)) {
798 // We can't use a specialized [getInterceptorMethod], so we make 803 // We can't use a specialized [getInterceptorMethod], so we make
799 // sure we emit the one with all checks. 804 // sure we emit the one with all checks.
800 String name = namer.getName(getInterceptorMethod); 805 String name = namer.getName(getInterceptorMethod);
801 specializedGetInterceptors.putIfAbsent(name, () { 806 specializedGetInterceptors.putIfAbsent(name, () {
802 // It is important to take the order provided by this list, 807 // It is important to take the order provided by the map,
803 // because we want the int type check to happen before the 808 // because we want the int type check to happen before the
804 // double type check: the double type check covers the int 809 // double type check: the double type check covers the int
805 // type check. 810 // type check. Also we don't need to do a number type check
806 return interceptedClasses.keys; 811 // because that is covered by the double type check.
812 List<ClassElement> keys = <ClassElement>[];
813 interceptedClasses.forEach((ClassElement cls, _) {
814 if (cls != jsNumberClass) keys.add(cls);
815 });
816 return keys;
807 }); 817 });
808 return namer.isolateAccess(getInterceptorMethod); 818 return namer.isolateAccess(getInterceptorMethod);
809 } else { 819 } else {
810 String name = namer.getSpecializedName(getInterceptorMethod, classes); 820 String name = namer.getSpecializedName(getInterceptorMethod, classes);
811 specializedGetInterceptors[name] = classes; 821 specializedGetInterceptors[name] = classes;
812 return '${namer.CURRENT_ISOLATE}.$name'; 822 return '${namer.CURRENT_ISOLATE}.$name';
813 } 823 }
814 } 824 }
815 825
816 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) { 826 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {
817 ClassElement result = null; 827 ClassElement result = null;
818 if (!_interceptorsAreInitialized) { 828 if (!_interceptorsAreInitialized) {
819 initializeInterceptorElements(); 829 initializeInterceptorElements();
820 _interceptorsAreInitialized = true; 830 _interceptorsAreInitialized = true;
821 } 831 }
822 if (cls == compiler.stringClass) { 832 if (cls == compiler.stringClass) {
823 result = jsStringClass; 833 addInterceptors(jsStringClass, enqueuer);
824 } else if (cls == compiler.listClass) { 834 } else if (cls == compiler.listClass) {
825 result = jsArrayClass; 835 addInterceptors(jsArrayClass, enqueuer);
826 } else if (cls == compiler.intClass) { 836 } else if (cls == compiler.intClass) {
827 result = jsIntClass; 837 addInterceptors(jsIntClass, enqueuer);
828 enqueuer.registerInstantiatedClass(jsNumberClass); 838 addInterceptors(jsNumberClass, enqueuer);
829 } else if (cls == compiler.doubleClass) { 839 } else if (cls == compiler.doubleClass) {
830 result = jsDoubleClass; 840 addInterceptors(jsDoubleClass, enqueuer);
831 enqueuer.registerInstantiatedClass(jsNumberClass); 841 addInterceptors(jsNumberClass, enqueuer);
832 } else if (cls == compiler.functionClass) { 842 } else if (cls == compiler.functionClass) {
833 result = jsFunctionClass; 843 addInterceptors(jsFunctionClass, enqueuer);
834 } else if (cls == compiler.boolClass) { 844 } else if (cls == compiler.boolClass) {
835 result = jsBoolClass; 845 addInterceptors(jsBoolClass, enqueuer);
836 } else if (cls == compiler.nullClass) { 846 } else if (cls == compiler.nullClass) {
837 result = jsNullClass; 847 addInterceptors(jsNullClass, enqueuer);
848 } else if (cls == compiler.numClass) {
849 addInterceptors(jsIntClass, enqueuer);
850 addInterceptors(jsDoubleClass, enqueuer);
851 addInterceptors(jsNumberClass, enqueuer);
838 } 852 }
839
840 if (result == null) return;
841 if (enqueuer.isResolutionQueue) addInterceptors(result);
842 enqueuer.registerInstantiatedClass(result);
843 } 853 }
844 854
845 Element get cyclicThrowHelper { 855 Element get cyclicThrowHelper {
846 return compiler.findHelper(const SourceString("throwCyclicInit")); 856 return compiler.findHelper(const SourceString("throwCyclicInit"));
847 } 857 }
848 858
849 JavaScriptItemCompilationContext createItemCompilationContext() { 859 JavaScriptItemCompilationContext createItemCompilationContext() {
850 return new JavaScriptItemCompilationContext(); 860 return new JavaScriptItemCompilationContext();
851 } 861 }
852 862
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 print("Inferred return types:"); 1114 print("Inferred return types:");
1105 print("----------------------"); 1115 print("----------------------");
1106 dumpReturnTypes(); 1116 dumpReturnTypes();
1107 print(""); 1117 print("");
1108 print("Inferred field types:"); 1118 print("Inferred field types:");
1109 print("------------------------"); 1119 print("------------------------");
1110 fieldTypes.dump(); 1120 fieldTypes.dump();
1111 print(""); 1121 print("");
1112 } 1122 }
1113 } 1123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698