Chromium Code Reviews

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

Issue 12334070: Support runtime check of function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix status files Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | 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 class JavaScriptItemCompilationContext extends ItemCompilationContext { 7 class JavaScriptItemCompilationContext extends ItemCompilationContext {
8 final Set<HInstruction> boundsChecked; 8 final Set<HInstruction> boundsChecked;
9 9
10 JavaScriptItemCompilationContext() 10 JavaScriptItemCompilationContext()
11 : boundsChecked = new Set<HInstruction>(); 11 : boundsChecked = new Set<HInstruction>();
12 } 12 }
13 13
14
15 class CheckedModeHelper {
16 final SourceString name;
17
18 const CheckedModeHelper(SourceString this.name);
19
20 Element getElement(Compiler compiler) => compiler.findHelper(name);
21
22 jsAst.Expression generateCall(SsaCodeGenerator codegen,
23 HTypeConversion node) {
24 Element helperElement = getElement(codegen.compiler);
25 codegen.world.registerStaticUse(helperElement);
26 List<jsAst.Expression> arguments = <jsAst.Expression>[];
27 codegen.use(node.checkedInput);
28 arguments.add(codegen.pop());
29 generateAdditionalArguments(codegen, node, arguments);
30 String helperName = codegen.backend.namer.isolateAccess(helperElement);
31 return new jsAst.Call(new jsAst.VariableUse(helperName), arguments);
32 }
33
34 void generateAdditionalArguments(SsaCodeGenerator codegen,
35 HTypeConversion node,
36 List<jsAst.Expression> arguments) {
37 assert(!node.typeExpression.isMalformed);
38 // No additional arguments needed.
39 }
40 }
41
42 class PropertyCheckedModeHelper extends CheckedModeHelper {
43 const PropertyCheckedModeHelper(SourceString name) : super(name);
44
45 void generateAdditionalArguments(SsaCodeGenerator codegen,
46 HTypeConversion node,
47 List<jsAst.Expression> arguments) {
48 DartType type = node.typeExpression;
49 assert(!type.isMalformed);
50 String additionalArgument = codegen.backend.namer.operatorIsType(type);
51 arguments.add(js.string(additionalArgument));
52 }
53 }
54
55 class TypeVariableCheckedModeHelper extends CheckedModeHelper {
56 const TypeVariableCheckedModeHelper(SourceString name) : super(name);
57
58 void generateAdditionalArguments(SsaCodeGenerator codegen,
59 HTypeConversion node,
60 List<jsAst.Expression> arguments) {
61 assert(node.typeExpression.kind == TypeKind.TYPE_VARIABLE);
62 codegen.use(node.typeRepresentation);
63 arguments.add(codegen.pop());
64 }
65 }
66
67 class SubtypeCheckedModeHelper extends CheckedModeHelper {
68 const SubtypeCheckedModeHelper(SourceString name) : super(name);
69
70 void generateAdditionalArguments(SsaCodeGenerator codegen,
71 HTypeConversion node,
72 List<jsAst.Expression> arguments) {
73 DartType type = node.typeExpression;
74 Element element = type.element;
75 String isField = codegen.backend.namer.operatorIs(element);
76 arguments.add(js.string(isField));
77 codegen.use(node.typeRepresentation);
78 arguments.add(codegen.pop());
79 String asField = codegen.backend.namer.substitutionName(element);
80 arguments.add(js.string(asField));
81 }
82 }
83
84 class FunctionTypeCheckedModeHelper extends CheckedModeHelper {
85 const FunctionTypeCheckedModeHelper(SourceString name) : super(name);
86
87 void generateAdditionalArguments(SsaCodeGenerator codegen,
88 HTypeConversion node,
89 List<jsAst.Expression> arguments) {
90 DartType type = node.typeExpression;
91 String signatureName = codegen.backend.namer.getFunctionTypeName(type);
92 arguments.add(js.string(signatureName));
93
94 if (type.containsTypeVariables) {
95 ClassElement contextClass = Types.getClassContext(type);
96 String contextName = codegen.backend.namer.getName(contextClass);
97 arguments.add(js.string(contextName));
98
99 if (node.contextIsTypeArguments) {
100 arguments.add(new jsAst.LiteralNull());
101 codegen.use(node.context);
102 arguments.add(codegen.pop());
103 } else {
104 codegen.use(node.context);
105 arguments.add(codegen.pop());
106 }
107 }
108 }
109 }
110
111 class MalformedCheckedModeHelper extends CheckedModeHelper {
112 const MalformedCheckedModeHelper(SourceString name) : super(name);
113
114 void generateAdditionalArguments(SsaCodeGenerator codegen,
115 HTypeConversion node,
116 List<jsAst.Expression> arguments) {
117 DartType type = node.typeExpression;
118 assert(type.isMalformed);
119 String reasons = Types.fetchReasonsFromMalformedType(type);
120 arguments.add(js.string('$type'));
121 // TODO(johnniwinther): Handle escaping correctly.
122 arguments.add(js.string(reasons));
123 }
124 }
125
126
14 class JavaScriptBackend extends Backend { 127 class JavaScriptBackend extends Backend {
15 SsaBuilderTask builder; 128 SsaBuilderTask builder;
16 SsaOptimizerTask optimizer; 129 SsaOptimizerTask optimizer;
17 SsaCodeGeneratorTask generator; 130 SsaCodeGeneratorTask generator;
18 CodeEmitterTask emitter; 131 CodeEmitterTask emitter;
19 132
20 /** 133 /**
21 * The generated code as a js AST for compiled methods. 134 * The generated code as a js AST for compiled methods.
22 */ 135 */
23 Map<Element, jsAst.Expression> get generatedCode { 136 Map<Element, jsAst.Expression> get generatedCode {
(...skipping 587 matching lines...)
611 } 724 }
612 725
613 void registerSetRuntimeType(TreeElements elements) { 726 void registerSetRuntimeType(TreeElements elements) {
614 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 727 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
615 } 728 }
616 729
617 void registerGetRuntimeTypeArgument(TreeElements elements) { 730 void registerGetRuntimeTypeArgument(TreeElements elements) {
618 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 731 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
619 } 732 }
620 733
621 void registerRuntimeType(TreeElements elements) { 734 void registerGenericCallMethod(Element callMethod,
735 Enqueuer enqueuer, TreeElements elements) {
736 if (enqueuer.isResolutionQueue || methodNeedsRti(callMethod)) {
737 registerApplySignature(enqueuer, elements);
738 }
739 }
740
741 void registerGenericClosure(Element closure,
742 Enqueuer enqueuer, TreeElements elements) {
743 if (enqueuer.isResolutionQueue || methodNeedsRti(closure)) {
744 registerApplySignature(enqueuer, elements);
745 }
746 }
747
748 void registerApplySignature(Enqueuer enqueuer, TreeElements elements) {
749 // Calls to [:applySignature:] are generated by the emitter and we therefore
750 // need to enqueue the used elements in the codegen enqueuer as well as in
751 // the resolution enqueuer.
752 enqueue(enqueuer, getSetRuntimeTypeInfo(), elements);
753 enqueue(enqueuer, getGetRuntimeTypeInfo(), elements);
754 enqueue(enqueuer, getApplySignature(), elements);
755 enqueue(enqueuer, getGetRuntimeTypeArguments(), elements);
756 enqueuer.registerInstantiatedClass(compiler.listClass, elements);
757 }
758
759 void registerRuntimeType(Enqueuer enqueuer, TreeElements elements) {
760 registerApplySignature(enqueuer, elements);
622 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 761 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
623 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 762 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
624 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 763 registerGetRuntimeTypeArgument(elements);
625 compiler.enqueuer.resolution.registerInstantiatedClass( 764 compiler.enqueuer.resolution.registerInstantiatedClass(
626 compiler.listClass, elements); 765 compiler.listClass, elements);
627 } 766 }
628 767
629 void registerTypeVariableExpression(TreeElements elements) { 768 void registerTypeVariableExpression(TreeElements elements) {
630 registerRuntimeType(elements); 769 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
770 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
771 registerGetRuntimeTypeArgument(elements);
772 compiler.enqueuer.resolution.registerInstantiatedClass(
773 compiler.listClass, elements);
631 enqueueInResolution(getRuntimeTypeToString(), elements); 774 enqueueInResolution(getRuntimeTypeToString(), elements);
632 enqueueInResolution(getCreateRuntimeType(), elements); 775 enqueueInResolution(getCreateRuntimeType(), elements);
633 } 776 }
634 777
635 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { 778 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) {
779 type = type.unalias(compiler);
636 world.registerInstantiatedClass(compiler.boolClass, elements); 780 world.registerInstantiatedClass(compiler.boolClass, elements);
781 bool inCheckedMode = compiler.enableTypeAssertions;
782 // [registerIsCheck] is also called for checked mode checks, so we
783 // need to register checked mode helpers.
784 if (inCheckedMode) {
785 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false);
786 if (helper != null) world.addToWorkList(helper.getElement(compiler));
787 // We also need the native variant of the check (for DOM types).
788 helper = getNativeCheckedModeHelper(type, typeCast: false);
789 if (helper != null) world.addToWorkList(helper.getElement(compiler));
790 if (type.isMalformed) {
791 enqueueInResolution(getThrowMalformedSubtypeError(), elements);
792 return;
793 }
794 } else {
795 if (type.isMalformed) {
karlklose 2013/06/19 14:37:05 Merge into an else if.
Johnni Winther 2013/06/21 12:19:15 Done.
796 registerThrowRuntimeError(elements);
797 return;
798 }
799 }
800 if (type.element.isNative()) {
801 // We will neeed to add the "$is" and "$as" properties on the
802 // JavaScript object prototype, so we make sure
803 // [:defineProperty:] is compiled.
804 world.addToWorkList(
karlklose 2013/06/19 14:37:05 Merge error?
Johnni Winther 2013/06/21 12:19:15 Bad move.
805 compiler.findHelper(const SourceString('defineProperty')));
806 }
637 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 807 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
638 bool inCheckedMode = compiler.enableTypeAssertions; 808 if (!type.isRaw || type.containsTypeVariables) {
639 if (!type.isRaw || isTypeVariable) {
640 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 809 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
641 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 810 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
642 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 811 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
643 if (inCheckedMode) { 812 if (inCheckedMode) {
644 enqueueInResolution(getAssertSubtype(), elements); 813 enqueueInResolution(getAssertSubtype(), elements);
645 } 814 }
646 enqueueInResolution(getCheckSubtype(), elements); 815 enqueueInResolution(getCheckSubtype(), elements);
647 if (isTypeVariable) { 816 if (isTypeVariable) {
648 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements); 817 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements);
649 if (inCheckedMode) { 818 if (inCheckedMode) {
650 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements); 819 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements);
651 } 820 }
652 } 821 }
653 world.registerInstantiatedClass(compiler.listClass, elements); 822 world.registerInstantiatedClass(compiler.listClass, elements);
654 } 823 }
655 // [registerIsCheck] is also called for checked mode checks, so we 824 if (type is FunctionType) {
656 // need to register checked mode helpers. 825 enqueueInResolution(getCheckFunctionSubtype(), elements);
657 if (inCheckedMode) {
658 Element e = getCheckedModeHelper(type, typeCast: false);
659 if (e != null) world.addToWorkList(e);
660 // We also need the native variant of the check (for DOM types).
661 e = getNativeCheckedModeHelper(type, typeCast: false);
662 if (e != null) world.addToWorkList(e);
663 } 826 }
664 if (type.element.isNative()) { 827 }
665 // We will neeed to add the "$is" and "$as" properties on the 828
666 // JavaScript object prototype, so we make sure 829 void registerAsCheck(DartType type, TreeElements elements) {
667 // [:defineProperty:] is compiled. 830 type = type.unalias(compiler);
668 world.addToWorkList( 831 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true);
669 compiler.findHelper(const SourceString('defineProperty'))); 832 enqueueInResolution(helper.getElement(compiler), elements);
833 // We also need the native variant of the check (for DOM types).
834 helper = getNativeCheckedModeHelper(type, typeCast: true);
835 if (helper != null) {
836 enqueueInResolution(helper.getElement(compiler), elements);
670 } 837 }
671 } 838 }
672 839
673 void registerAsCheck(DartType type, TreeElements elements) {
674 Element e = getCheckedModeHelper(type, typeCast: true);
675 enqueueInResolution(e, elements);
676 // We also need the native variant of the check (for DOM types).
677 e = getNativeCheckedModeHelper(type, typeCast: true);
678 enqueueInResolution(e, elements);
679 }
680
681 void registerThrowNoSuchMethod(TreeElements elements) { 840 void registerThrowNoSuchMethod(TreeElements elements) {
682 enqueueInResolution(getThrowNoSuchMethod(), elements); 841 enqueueInResolution(getThrowNoSuchMethod(), elements);
683 } 842 }
684 843
685 void registerThrowRuntimeError(TreeElements elements) { 844 void registerThrowRuntimeError(TreeElements elements) {
686 enqueueInResolution(getThrowRuntimeError(), elements); 845 enqueueInResolution(getThrowRuntimeError(), elements);
687 } 846 }
688 847
689 void registerAbstractClassInstantiation(TreeElements elements) { 848 void registerAbstractClassInstantiation(TreeElements elements) {
690 enqueueInResolution(getThrowAbstractClassInstantiationError(), elements); 849 enqueueInResolution(getThrowAbstractClassInstantiationError(), elements);
(...skipping 61 matching lines...)
752 } 911 }
753 912
754 bool isDefaultEqualityImplementation(Element element) { 913 bool isDefaultEqualityImplementation(Element element) {
755 assert(element.name == const SourceString('==')); 914 assert(element.name == const SourceString('=='));
756 ClassElement classElement = element.getEnclosingClass(); 915 ClassElement classElement = element.getEnclosingClass();
757 return classElement == compiler.objectClass 916 return classElement == compiler.objectClass
758 || classElement == jsInterceptorClass 917 || classElement == jsInterceptorClass
759 || classElement == jsNullClass; 918 || classElement == jsNullClass;
760 } 919 }
761 920
921 bool methodNeedsRti(Element cls) {
922 return rti.methodsNeedingRti.contains(cls) || compiler.enabledRuntimeType;
923 }
924
925 void enqueue(Enqueuer enqueuer, Element e, TreeElements elements) {
926 enqueuer.addToWorkList(e);
927 elements.registerDependency(e);
928 }
929
762 void enqueueInResolution(Element e, TreeElements elements) { 930 void enqueueInResolution(Element e, TreeElements elements) {
763 if (e == null) return; 931 if (e == null) return;
764 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution; 932 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution;
765 enqueuer.addToWorkList(e); 933 enqueue(enqueuer, e, elements);
766 elements.registerDependency(e);
767 } 934 }
768 935
769 void registerConstantMap(TreeElements elements) { 936 void registerConstantMap(TreeElements elements) {
770 Element e = compiler.findHelper(const SourceString('ConstantMap')); 937 Element e = compiler.findHelper(const SourceString('ConstantMap'));
771 if (e != null) { 938 if (e != null) {
772 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements); 939 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements);
773 } 940 }
774 e = compiler.findHelper(const SourceString('ConstantProtoMap')); 941 e = compiler.findHelper(const SourceString('ConstantProtoMap'));
775 if (e != null) { 942 if (e != null) {
776 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements); 943 compiler.enqueuer.resolution.registerInstantiatedClass(e, elements);
(...skipping 78 matching lines...)
855 return element; 1022 return element;
856 } 1023 }
857 } 1024 }
858 1025
859 /** 1026 /**
860 * Returns the checked mode helper that will be needed to do a type check/type 1027 * Returns the checked mode helper that will be needed to do a type check/type
861 * cast on [type] at runtime. Note that this method is being called both by 1028 * cast on [type] at runtime. Note that this method is being called both by
862 * the resolver with interface types (int, String, ...), and by the SSA 1029 * the resolver with interface types (int, String, ...), and by the SSA
863 * backend with implementation types (JSInt, JSString, ...). 1030 * backend with implementation types (JSInt, JSString, ...).
864 */ 1031 */
865 Element getCheckedModeHelper(DartType type, {bool typeCast}) { 1032 CheckedModeHelper getCheckedModeHelper(DartType type, {bool typeCast}) {
866 SourceString name = getCheckedModeHelperName( 1033 return getCheckedModeHelperInternal(
867 type, typeCast: typeCast, nativeCheckOnly: false); 1034 type, typeCast: typeCast, nativeCheckOnly: false);
868 return compiler.findHelper(name);
869 } 1035 }
870 1036
871 /** 1037 /**
872 * Returns the native checked mode helper that will be needed to do a type 1038 * Returns the native checked mode helper that will be needed to do a type
873 * check/type cast on [type] at runtime. If no native helper exists for 1039 * check/type cast on [type] at runtime. If no native helper exists for
874 * [type], [:null:] is returned. 1040 * [type], [:null:] is returned.
875 */ 1041 */
876 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { 1042 CheckedModeHelper getNativeCheckedModeHelper(DartType type, {bool typeCast}) {
877 SourceString sourceName = getCheckedModeHelperName( 1043 return getCheckedModeHelperInternal(
878 type, typeCast: typeCast, nativeCheckOnly: true); 1044 type, typeCast: typeCast, nativeCheckOnly: true);
879 if (sourceName == null) return null;
880 return compiler.findHelper(sourceName);
881 } 1045 }
882 1046
883 /** 1047 /**
884 * Returns the name of the type check/type cast helper method for [type]. If 1048 * Returns the checked mode helper for the type check/type cast for [type]. If
885 * [nativeCheckOnly] is [:true:], only names for native helpers are returned. 1049 * [nativeCheckOnly] is [:true:], only names for native helpers are returned.
886 */ 1050 */
887 SourceString getCheckedModeHelperName(DartType type, 1051 CheckedModeHelper getCheckedModeHelperInternal(DartType type,
888 {bool typeCast, 1052 {bool typeCast,
889 bool nativeCheckOnly}) { 1053 bool nativeCheckOnly}) {
1054 assert(type.kind != TypeKind.TYPEDEF);
890 Element element = type.element; 1055 Element element = type.element;
891 bool nativeCheck = nativeCheckOnly || 1056 bool nativeCheck = nativeCheckOnly ||
892 emitter.nativeEmitter.requiresNativeIsCheck(element); 1057 emitter.nativeEmitter.requiresNativeIsCheck(element);
893 if (type.isMalformed) { 1058 if (type.isMalformed) {
894 // Check for malformed types first, because the type may be a list type 1059 // Check for malformed types first, because the type may be a list type
895 // with a malformed argument type. 1060 // with a malformed argument type.
896 if (nativeCheckOnly) return null; 1061 if (nativeCheckOnly) return null;
897 return typeCast 1062 return typeCast
898 ? const SourceString('malformedTypeCast') 1063 ? const MalformedCheckedModeHelper(const SourceString('malformedTypeCa st'))
899 : const SourceString('malformedTypeCheck'); 1064 : const MalformedCheckedModeHelper(const SourceString('malformedTypeCh eck'));
900 } else if (type == compiler.types.voidType) { 1065 } else if (type == compiler.types.voidType) {
901 assert(!typeCast); // Cannot cast to void. 1066 assert(!typeCast); // Cannot cast to void.
902 if (nativeCheckOnly) return null; 1067 if (nativeCheckOnly) return null;
903 return const SourceString('voidTypeCheck'); 1068 return const CheckedModeHelper(const SourceString('voidTypeCheck'));
904 } else if (element == jsStringClass || element == compiler.stringClass) { 1069 } else if (element == jsStringClass || element == compiler.stringClass) {
905 if (nativeCheckOnly) return null; 1070 if (nativeCheckOnly) return null;
906 return typeCast 1071 return typeCast
907 ? const SourceString("stringTypeCast") 1072 ? const CheckedModeHelper(const SourceString("stringTypeCast"))
908 : const SourceString('stringTypeCheck'); 1073 : const CheckedModeHelper(const SourceString('stringTypeCheck'));
909 } else if (element == jsDoubleClass || element == compiler.doubleClass) { 1074 } else if (element == jsDoubleClass || element == compiler.doubleClass) {
910 if (nativeCheckOnly) return null; 1075 if (nativeCheckOnly) return null;
911 return typeCast 1076 return typeCast
912 ? const SourceString("doubleTypeCast") 1077 ? const CheckedModeHelper(const SourceString("doubleTypeCast"))
913 : const SourceString('doubleTypeCheck'); 1078 : const CheckedModeHelper(const SourceString('doubleTypeCheck'));
914 } else if (element == jsNumberClass || element == compiler.numClass) { 1079 } else if (element == jsNumberClass || element == compiler.numClass) {
915 if (nativeCheckOnly) return null; 1080 if (nativeCheckOnly) return null;
916 return typeCast 1081 return typeCast
917 ? const SourceString("numTypeCast") 1082 ? const CheckedModeHelper(const SourceString("numTypeCast"))
918 : const SourceString('numTypeCheck'); 1083 : const CheckedModeHelper(const SourceString('numTypeCheck'));
919 } else if (element == jsBoolClass || element == compiler.boolClass) { 1084 } else if (element == jsBoolClass || element == compiler.boolClass) {
920 if (nativeCheckOnly) return null; 1085 if (nativeCheckOnly) return null;
921 return typeCast 1086 return typeCast
922 ? const SourceString("boolTypeCast") 1087 ? const CheckedModeHelper(const SourceString("boolTypeCast"))
923 : const SourceString('boolTypeCheck'); 1088 : const CheckedModeHelper(const SourceString('boolTypeCheck'));
924 } else if (element == jsIntClass || element == compiler.intClass) { 1089 } else if (element == jsIntClass || element == compiler.intClass) {
925 if (nativeCheckOnly) return null; 1090 if (nativeCheckOnly) return null;
926 return typeCast ? 1091 return typeCast
927 const SourceString("intTypeCast") : 1092 ? const CheckedModeHelper(const SourceString("intTypeCast"))
928 const SourceString('intTypeCheck'); 1093 : const CheckedModeHelper(const SourceString('intTypeCheck'));
929 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { 1094 } else if (Elements.isNumberOrStringSupertype(element, compiler)) {
930 if (nativeCheck) { 1095 if (nativeCheck) {
931 return typeCast 1096 return typeCast
932 ? const SourceString("numberOrStringSuperNativeTypeCast") 1097 ? const PropertyCheckedModeHelper(const SourceString("numberOrString SuperNativeTypeCast"))
karlklose 2013/06/19 14:37:05 A lot of long lines from here on...
Johnni Winther 2013/06/21 12:19:15 Done.
933 : const SourceString('numberOrStringSuperNativeTypeCheck'); 1098 : const PropertyCheckedModeHelper(const SourceString('numberOrString SuperNativeTypeCheck'));
934 } else { 1099 } else {
935 return typeCast 1100 return typeCast
936 ? const SourceString("numberOrStringSuperTypeCast") 1101 ? const PropertyCheckedModeHelper(const SourceString("numberOrStringSu perTypeCast"))
937 : const SourceString('numberOrStringSuperTypeCheck'); 1102 : const PropertyCheckedModeHelper(const SourceString('numberOrStringSu perTypeCheck'));
938 } 1103 }
939 } else if (Elements.isStringOnlySupertype(element, compiler)) { 1104 } else if (Elements.isStringOnlySupertype(element, compiler)) {
940 if (nativeCheck) { 1105 if (nativeCheck) {
941 return typeCast 1106 return typeCast
942 ? const SourceString("stringSuperNativeTypeCast") 1107 ? const PropertyCheckedModeHelper(const SourceString("stringSuperNat iveTypeCast"))
943 : const SourceString('stringSuperNativeTypeCheck'); 1108 : const PropertyCheckedModeHelper(const SourceString('stringSuperNat iveTypeCheck'));
944 } else { 1109 } else {
945 return typeCast 1110 return typeCast
946 ? const SourceString("stringSuperTypeCast") 1111 ? const PropertyCheckedModeHelper(const SourceString("stringSuperTyp eCast"))
947 : const SourceString('stringSuperTypeCheck'); 1112 : const PropertyCheckedModeHelper(const SourceString('stringSuperTyp eCheck'));
948 } 1113 }
949 } else if ((element == compiler.listClass || element == jsArrayClass) && 1114 } else if ((element == compiler.listClass || element == jsArrayClass) &&
950 type.isRaw) { 1115 type.isRaw) {
951 if (nativeCheckOnly) return null; 1116 if (nativeCheckOnly) return null;
952 return typeCast 1117 return typeCast
953 ? const SourceString("listTypeCast") 1118 ? const CheckedModeHelper(const SourceString("listTypeCast"))
954 : const SourceString('listTypeCheck'); 1119 : const CheckedModeHelper(const SourceString('listTypeCheck'));
955 } else { 1120 } else {
956 if (Elements.isListSupertype(element, compiler)) { 1121 if (Elements.isListSupertype(element, compiler)) {
957 if (nativeCheck) { 1122 if (nativeCheck) {
958 return typeCast 1123 return typeCast
959 ? const SourceString("listSuperNativeTypeCast") 1124 ? const PropertyCheckedModeHelper(const SourceString("listSuperNat iveTypeCast"))
960 : const SourceString('listSuperNativeTypeCheck'); 1125 : const PropertyCheckedModeHelper(const SourceString('listSuperNat iveTypeCheck'));
961 } else { 1126 } else {
962 return typeCast 1127 return typeCast
963 ? const SourceString("listSuperTypeCast") 1128 ? const PropertyCheckedModeHelper(const SourceString("listSuperTyp eCast"))
964 : const SourceString('listSuperTypeCheck'); 1129 : const PropertyCheckedModeHelper(const SourceString('listSuperTyp eCheck'));
965 } 1130 }
966 } else { 1131 } else {
967 if (nativeCheck) { 1132 if (nativeCheck) {
968 // TODO(karlklose): can we get rid of this branch when we use 1133 // TODO(karlklose): can we get rid of this branch when we use
969 // interceptors? 1134 // interceptors?
970 return typeCast 1135 return typeCast
971 ? const SourceString("interceptedTypeCast") 1136 ? const PropertyCheckedModeHelper(const SourceString("interceptedT ypeCast"))
972 : const SourceString('interceptedTypeCheck'); 1137 : const PropertyCheckedModeHelper(const SourceString('interceptedT ypeCheck'));
973 } else { 1138 } else {
974 if (type.kind == TypeKind.INTERFACE && !type.isRaw) { 1139 if (type.kind == TypeKind.INTERFACE && !type.isRaw) {
975 return typeCast 1140 return typeCast
976 ? const SourceString('subtypeCast') 1141 ? const SubtypeCheckedModeHelper(const SourceString('subtypeCast '))
977 : const SourceString('assertSubtype'); 1142 : const SubtypeCheckedModeHelper(const SourceString('assertSubty pe'));
978 } else if (type.kind == TypeKind.TYPE_VARIABLE) { 1143 } else if (type.kind == TypeKind.TYPE_VARIABLE) {
979 return typeCast 1144 return typeCast
980 ? const SourceString('subtypeOfRuntimeTypeCast') 1145 ? const TypeVariableCheckedModeHelper(const SourceString('subtyp eOfRuntimeTypeCast'))
981 : const SourceString('assertSubtypeOfRuntimeType'); 1146 : const TypeVariableCheckedModeHelper(const SourceString('assert SubtypeOfRuntimeType'));
1147 } else if (type.kind == TypeKind.FUNCTION) {
1148 return typeCast
1149 ? const FunctionTypeCheckedModeHelper(const SourceString('functi onSubtypeCast'))
1150 : const FunctionTypeCheckedModeHelper(const SourceString('assert FunctionSubtype'));
982 } else { 1151 } else {
983 return typeCast 1152 return typeCast
984 ? const SourceString('propertyTypeCast') 1153 ? const PropertyCheckedModeHelper(const SourceString('propertyTy peCast'))
985 : const SourceString('propertyTypeCheck'); 1154 : const PropertyCheckedModeHelper(const SourceString('propertyTy peCheck'));
986 } 1155 }
987 } 1156 }
988 } 1157 }
989 } 1158 }
990 } 1159 }
991 1160
992 Element getExceptionUnwrapper() { 1161 Element getExceptionUnwrapper() {
993 return compiler.findHelper(const SourceString('unwrapException')); 1162 return compiler.findHelper(const SourceString('unwrapException'));
994 } 1163 }
995 1164
996 Element getThrowRuntimeError() { 1165 Element getThrowRuntimeError() {
997 return compiler.findHelper(const SourceString('throwRuntimeError')); 1166 return compiler.findHelper(const SourceString('throwRuntimeError'));
998 } 1167 }
999 1168
1169 Element getMalformedTypeCheck() {
1170 return compiler.findHelper(const SourceString('malformedTypeCheck'));
1171 }
1172
1000 Element getThrowMalformedSubtypeError() { 1173 Element getThrowMalformedSubtypeError() {
1001 return compiler.findHelper( 1174 return compiler.findHelper(
1002 const SourceString('throwMalformedSubtypeError')); 1175 const SourceString('throwMalformedSubtypeError'));
1003 } 1176 }
1004 1177
1005 Element getThrowAbstractClassInstantiationError() { 1178 Element getThrowAbstractClassInstantiationError() {
1006 return compiler.findHelper( 1179 return compiler.findHelper(
1007 const SourceString('throwAbstractClassInstantiationError')); 1180 const SourceString('throwAbstractClassInstantiationError'));
1008 } 1181 }
1009 1182
(...skipping 22 matching lines...)
1032 } 1205 }
1033 1206
1034 Element getSetRuntimeTypeInfo() { 1207 Element getSetRuntimeTypeInfo() {
1035 return compiler.findHelper(const SourceString('setRuntimeTypeInfo')); 1208 return compiler.findHelper(const SourceString('setRuntimeTypeInfo'));
1036 } 1209 }
1037 1210
1038 Element getGetRuntimeTypeInfo() { 1211 Element getGetRuntimeTypeInfo() {
1039 return compiler.findHelper(const SourceString('getRuntimeTypeInfo')); 1212 return compiler.findHelper(const SourceString('getRuntimeTypeInfo'));
1040 } 1213 }
1041 1214
1215 Element getApplySignature() {
1216 return compiler.findHelper(const SourceString('applySignature'));
1217 }
1218
1219 Element getGetRuntimeTypeArguments() {
1220 return compiler.findHelper(const SourceString('getRuntimeTypeArguments'));
1221 }
1222
1042 Element getGetRuntimeTypeArgument() { 1223 Element getGetRuntimeTypeArgument() {
1043 return compiler.findHelper(const SourceString('getRuntimeTypeArgument')); 1224 return compiler.findHelper(const SourceString('getRuntimeTypeArgument'));
1044 } 1225 }
1045 1226
1046 Element getRuntimeTypeToString() { 1227 Element getRuntimeTypeToString() {
1047 return compiler.findHelper(const SourceString('runtimeTypeToString')); 1228 return compiler.findHelper(const SourceString('runtimeTypeToString'));
1048 } 1229 }
1049 1230
1050 Element getCheckSubtype() { 1231 Element getCheckSubtype() {
1051 return compiler.findHelper(const SourceString('checkSubtype')); 1232 return compiler.findHelper(const SourceString('checkSubtype'));
1052 } 1233 }
1053 1234
1054 Element getAssertSubtype() { 1235 Element getAssertSubtype() {
1055 return compiler.findHelper(const SourceString('assertSubtype')); 1236 return compiler.findHelper(const SourceString('assertSubtype'));
1056 } 1237 }
1057 1238
1058 Element getCheckSubtypeOfRuntimeType() { 1239 Element getCheckSubtypeOfRuntimeType() {
1059 return compiler.findHelper(const SourceString('checkSubtypeOfRuntimeType')); 1240 return compiler.findHelper(const SourceString('checkSubtypeOfRuntimeType'));
1060 } 1241 }
1061 1242
1062 Element getAssertSubtypeOfRuntimeType() { 1243 Element getAssertSubtypeOfRuntimeType() {
1063 return compiler.findHelper( 1244 return compiler.findHelper(
1064 const SourceString('assertSubtypeOfRuntimeType')); 1245 const SourceString('assertSubtypeOfRuntimeType'));
1065 } 1246 }
1066 1247
1248 Element getCheckFunctionSubtype() {
1249 return compiler.findHelper(const SourceString('checkFunctionSubtype'));
1250 }
1251
1067 Element getThrowNoSuchMethod() { 1252 Element getThrowNoSuchMethod() {
1068 return compiler.findHelper(const SourceString('throwNoSuchMethod')); 1253 return compiler.findHelper(const SourceString('throwNoSuchMethod'));
1069 } 1254 }
1070 1255
1071 Element getCreateRuntimeType() { 1256 Element getCreateRuntimeType() {
1072 return compiler.findHelper(const SourceString('createRuntimeType')); 1257 return compiler.findHelper(const SourceString('createRuntimeType'));
1073 } 1258 }
1074 1259
1075 Element getFallThroughError() { 1260 Element getFallThroughError() {
1076 return compiler.findHelper(const SourceString("getFallThroughError")); 1261 return compiler.findHelper(const SourceString("getFallThroughError"));
(...skipping 31 matching lines...)
1108 ClassElement get listImplementation => jsArrayClass; 1293 ClassElement get listImplementation => jsArrayClass;
1109 ClassElement get constListImplementation => jsArrayClass; 1294 ClassElement get constListImplementation => jsArrayClass;
1110 ClassElement get fixedListImplementation => jsFixedArrayClass; 1295 ClassElement get fixedListImplementation => jsFixedArrayClass;
1111 ClassElement get growableListImplementation => jsExtendableArrayClass; 1296 ClassElement get growableListImplementation => jsExtendableArrayClass;
1112 ClassElement get mapImplementation => mapLiteralClass; 1297 ClassElement get mapImplementation => mapLiteralClass;
1113 ClassElement get constMapImplementation => constMapLiteralClass; 1298 ClassElement get constMapImplementation => constMapLiteralClass;
1114 ClassElement get typeImplementation => typeLiteralClass; 1299 ClassElement get typeImplementation => typeLiteralClass;
1115 ClassElement get boolImplementation => jsBoolClass; 1300 ClassElement get boolImplementation => jsBoolClass;
1116 ClassElement get nullImplementation => jsNullClass; 1301 ClassElement get nullImplementation => jsNullClass;
1117 } 1302 }
OLDNEW

Powered by Google App Engine