| 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 class TypeTestRegistry { | 7 class TypeTestRegistry { |
| 8 /** | 8 /** |
| 9 * Raw ClassElement symbols occuring in is-checks and type assertions. If the | 9 * Raw ClassElement symbols occuring in is-checks and type assertions. If the |
| 10 * program contains parameterized checks `x is Set<int>` and | 10 * program contains parameterized checks `x is Set<int>` and |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 for (ClassElement cls in classes) { | 72 for (ClassElement cls in classes) { |
| 73 addClassWithSuperclasses(cls); | 73 addClassWithSuperclasses(cls); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 // 1. Add classes that are referenced by type arguments or substitutions in | 77 // 1. Add classes that are referenced by type arguments or substitutions in |
| 78 // argument checks. | 78 // argument checks. |
| 79 // TODO(karlklose): merge this case with 2 when unifying argument and | 79 // TODO(karlklose): merge this case with 2 when unifying argument and |
| 80 // object checks. | 80 // object checks. |
| 81 RuntimeTypes rti = backend.rti; | 81 RuntimeTypes rti = backend.rti; |
| 82 rti.getRequiredArgumentClasses(backend) | 82 rti.getRequiredArgumentClasses(backend).forEach(addClassWithSuperclasses); |
| 83 .forEach(addClassWithSuperclasses); | |
| 84 | 83 |
| 85 // 2. Add classes that are referenced by substitutions in object checks and | 84 // 2. Add classes that are referenced by substitutions in object checks and |
| 86 // their superclasses. | 85 // their superclasses. |
| 87 TypeChecks requiredChecks = | 86 TypeChecks requiredChecks = |
| 88 rti.computeChecks(rtiNeededClasses, checkedClasses); | 87 rti.computeChecks(rtiNeededClasses, checkedClasses); |
| 89 Set<ClassElement> classesUsedInSubstitutions = | 88 Set<ClassElement> classesUsedInSubstitutions = |
| 90 rti.getClassesUsedInSubstitutions(backend, requiredChecks); | 89 rti.getClassesUsedInSubstitutions(backend, requiredChecks); |
| 91 addClassesWithSuperclasses(classesUsedInSubstitutions); | 90 addClassesWithSuperclasses(classesUsedInSubstitutions); |
| 92 | 91 |
| 93 // 3. Add classes that contain checked generic function types. These are | 92 // 3. Add classes that contain checked generic function types. These are |
| 94 // needed to store the signature encoding. | 93 // needed to store the signature encoding. |
| 95 for (FunctionType type in checkedFunctionTypes) { | 94 for (FunctionType type in checkedFunctionTypes) { |
| 96 ClassElement contextClass = Types.getClassContext(type); | 95 ClassElement contextClass = Types.getClassContext(type); |
| 97 if (contextClass != null) { | 96 if (contextClass != null) { |
| 98 rtiNeededClasses.add(contextClass); | 97 rtiNeededClasses.add(contextClass); |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 | 100 |
| 102 bool canTearOff(Element function) { | 101 bool canTearOff(Element function) { |
| 103 if (!function.isFunction || | 102 if (!function.isFunction || |
| 104 function.isConstructor || | 103 function.isConstructor || |
| 105 function.isAccessor) { | 104 function.isAccessor) { |
| 106 return false; | 105 return false; |
| 107 } else if (function.isInstanceMember) { | 106 } else if (function.isInstanceMember) { |
| 108 if (!function.enclosingClass.isClosure) { | 107 if (!function.enclosingClass.isClosure) { |
| 109 return compiler.codegenWorld.hasInvokedGetter( | 108 return compiler.codegenWorld |
| 110 function, compiler.world); | 109 .hasInvokedGetter(function, compiler.world); |
| 111 } | 110 } |
| 112 } | 111 } |
| 113 return false; | 112 return false; |
| 114 } | 113 } |
| 115 | 114 |
| 116 bool canBeReflectedAsFunction(Element element) { | 115 bool canBeReflectedAsFunction(Element element) { |
| 117 return element.kind == ElementKind.FUNCTION || | 116 return element.kind == ElementKind.FUNCTION || |
| 118 element.kind == ElementKind.GETTER || | 117 element.kind == ElementKind.GETTER || |
| 119 element.kind == ElementKind.SETTER || | 118 element.kind == ElementKind.SETTER || |
| 120 element.kind == ElementKind.GENERATIVE_CONSTRUCTOR; | 119 element.kind == ElementKind.GENERATIVE_CONSTRUCTOR; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 } | 136 } |
| 138 } | 137 } |
| 139 }); | 138 }); |
| 140 | 139 |
| 141 return rtiNeededClasses; | 140 return rtiNeededClasses; |
| 142 } | 141 } |
| 143 | 142 |
| 144 void computeRequiredTypeChecks() { | 143 void computeRequiredTypeChecks() { |
| 145 assert(checkedClasses == null && checkedFunctionTypes == null); | 144 assert(checkedClasses == null && checkedFunctionTypes == null); |
| 146 | 145 |
| 147 backend.rti.addImplicitChecks(compiler.codegenWorld, | 146 backend.rti.addImplicitChecks( |
| 148 classesUsingTypeVariableTests); | 147 compiler.codegenWorld, classesUsingTypeVariableTests); |
| 149 | 148 |
| 150 checkedClasses = new Set<ClassElement>(); | 149 checkedClasses = new Set<ClassElement>(); |
| 151 checkedFunctionTypes = new Set<FunctionType>(); | 150 checkedFunctionTypes = new Set<FunctionType>(); |
| 152 compiler.codegenWorld.isChecks.forEach((DartType t) { | 151 compiler.codegenWorld.isChecks.forEach((DartType t) { |
| 153 if (t is InterfaceType) { | 152 if (t is InterfaceType) { |
| 154 checkedClasses.add(t.element); | 153 checkedClasses.add(t.element); |
| 155 } else if (t is FunctionType) { | 154 } else if (t is FunctionType) { |
| 156 checkedFunctionTypes.add(t); | 155 checkedFunctionTypes.add(t); |
| 157 } | 156 } |
| 158 }); | 157 }); |
| 159 } | 158 } |
| 160 } | 159 } |
| OLD | NEW |