| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 7 /** |
| 8 * Support for Custom Elements. | 8 * Support for Custom Elements. |
| 9 * | 9 * |
| 10 * The support for custom elements the compiler builds a table that maps the | 10 * The support for custom elements the compiler builds a table that maps the |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // TODO(12607): Match on [ClassMirror.reflectedType] | 61 // TODO(12607): Match on [ClassMirror.reflectedType] |
| 62 resolutionJoin.allClassesSelected = true; | 62 resolutionJoin.allClassesSelected = true; |
| 63 codegenJoin.allClassesSelected = true; | 63 codegenJoin.allClassesSelected = true; |
| 64 } | 64 } |
| 65 | 65 |
| 66 CustomElementsAnalysisJoin joinFor(Enqueuer enqueuer) => | 66 CustomElementsAnalysisJoin joinFor(Enqueuer enqueuer) => |
| 67 enqueuer.isResolutionQueue ? resolutionJoin : codegenJoin; | 67 enqueuer.isResolutionQueue ? resolutionJoin : codegenJoin; |
| 68 | 68 |
| 69 void registerInstantiatedClass(ClassElement classElement, Enqueuer enqueuer) { | 69 void registerInstantiatedClass(ClassElement classElement, Enqueuer enqueuer) { |
| 70 classElement.ensureResolved(compiler.resolution); | 70 classElement.ensureResolved(compiler.resolution); |
| 71 if (!Elements.isNativeOrExtendsNative(classElement)) return; | 71 if (!backend.isNativeOrExtendsNative(classElement)) return; |
| 72 if (classElement.isMixinApplication) return; | 72 if (classElement.isMixinApplication) return; |
| 73 if (classElement.isAbstract) return; | 73 if (classElement.isAbstract) return; |
| 74 // JsInterop classes are opaque interfaces without a concrete | 74 // JsInterop classes are opaque interfaces without a concrete |
| 75 // implementation. | 75 // implementation. |
| 76 if (classElement.isJsInterop) return; | 76 if (backend.isJsInterop(classElement)) return; |
| 77 joinFor(enqueuer).instantiatedClasses.add(classElement); | 77 joinFor(enqueuer).instantiatedClasses.add(classElement); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void registerTypeLiteral(DartType type) { | 80 void registerTypeLiteral(DartType type) { |
| 81 if (type.isInterfaceType) { | 81 if (type.isInterfaceType) { |
| 82 // TODO(sra): If we had a flow query from the type literal expression to | 82 // TODO(sra): If we had a flow query from the type literal expression to |
| 83 // the Type argument of the metadata lookup, we could tell if this type | 83 // the Type argument of the metadata lookup, we could tell if this type |
| 84 // literal is really a demand for the metadata. | 84 // literal is really a demand for the metadata. |
| 85 resolutionJoin.selectedClasses.add(type.element); | 85 resolutionJoin.selectedClasses.add(type.element); |
| 86 } else if (type.isTypeVariable) { | 86 } else if (type.isTypeVariable) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 // ClassesOutput: classes requiring metadata. | 143 // ClassesOutput: classes requiring metadata. |
| 144 final activeClasses = new Set<ClassElement>(); | 144 final activeClasses = new Set<ClassElement>(); |
| 145 | 145 |
| 146 CustomElementsAnalysisJoin(this.backend); | 146 CustomElementsAnalysisJoin(this.backend); |
| 147 | 147 |
| 148 void flush(Enqueuer enqueuer) { | 148 void flush(Enqueuer enqueuer) { |
| 149 if (!demanded) return; | 149 if (!demanded) return; |
| 150 var newActiveClasses = new Set<ClassElement>(); | 150 var newActiveClasses = new Set<ClassElement>(); |
| 151 for (ClassElement classElement in instantiatedClasses) { | 151 for (ClassElement classElement in instantiatedClasses) { |
| 152 bool isNative = classElement.isNative; | 152 bool isNative = backend.isNative(classElement); |
| 153 bool isExtension = | 153 bool isExtension = |
| 154 !isNative && Elements.isNativeOrExtendsNative(classElement); | 154 !isNative && backend.isNativeOrExtendsNative(classElement); |
| 155 // Generate table entries for native classes that are explicitly named and | 155 // Generate table entries for native classes that are explicitly named and |
| 156 // extensions that fix our criteria. | 156 // extensions that fix our criteria. |
| 157 if ((isNative && selectedClasses.contains(classElement)) || | 157 if ((isNative && selectedClasses.contains(classElement)) || |
| 158 (isExtension && | 158 (isExtension && |
| 159 (allClassesSelected || selectedClasses.contains(classElement)))) { | 159 (allClassesSelected || selectedClasses.contains(classElement)))) { |
| 160 newActiveClasses.add(classElement); | 160 newActiveClasses.add(classElement); |
| 161 Iterable<Element> escapingConstructors = | 161 Iterable<Element> escapingConstructors = |
| 162 computeEscapingConstructors(classElement); | 162 computeEscapingConstructors(classElement); |
| 163 escapingConstructors.forEach(enqueuer.registerStaticUse); | 163 escapingConstructors.forEach(enqueuer.registerStaticUse); |
| 164 escapingConstructors | 164 escapingConstructors |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 TypeConstantValue makeTypeConstant(ClassElement element) { | 177 TypeConstantValue makeTypeConstant(ClassElement element) { |
| 178 DartType elementType = element.rawType; | 178 DartType elementType = element.rawType; |
| 179 return backend.constantSystem.createType(compiler, elementType); | 179 return backend.constantSystem.createType(compiler, elementType); |
| 180 } | 180 } |
| 181 | 181 |
| 182 List<Element> computeEscapingConstructors(ClassElement classElement) { | 182 List<Element> computeEscapingConstructors(ClassElement classElement) { |
| 183 List<Element> result = <Element>[]; | 183 List<Element> result = <Element>[]; |
| 184 // Only classes that extend native classes have constructors in the table. | 184 // Only classes that extend native classes have constructors in the table. |
| 185 // We could refine this to classes that extend Element, but that would break | 185 // We could refine this to classes that extend Element, but that would break |
| 186 // the tests and there is no sane reason to subclass other native classes. | 186 // the tests and there is no sane reason to subclass other native classes. |
| 187 if (classElement.isNative) return result; | 187 if (backend.isNative(classElement)) return result; |
| 188 | 188 |
| 189 selectGenerativeConstructors(ClassElement enclosing, Element member) { | 189 selectGenerativeConstructors(ClassElement enclosing, Element member) { |
| 190 if (member.isGenerativeConstructor) { | 190 if (member.isGenerativeConstructor) { |
| 191 // Ignore constructors that cannot be called with zero arguments. | 191 // Ignore constructors that cannot be called with zero arguments. |
| 192 FunctionElement constructor = member; | 192 FunctionElement constructor = member; |
| 193 constructor.computeType(compiler.resolution); | 193 constructor.computeType(compiler.resolution); |
| 194 FunctionSignature parameters = constructor.functionSignature; | 194 FunctionSignature parameters = constructor.functionSignature; |
| 195 if (parameters.requiredParameterCount == 0) { | 195 if (parameters.requiredParameterCount == 0) { |
| 196 result.add(member); | 196 result.add(member); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 classElement.forEachMember(selectGenerativeConstructors, | 200 classElement.forEachMember(selectGenerativeConstructors, |
| 201 includeBackendMembers: false, | 201 includeBackendMembers: false, |
| 202 includeSuperAndInjectedMembers: false); | 202 includeSuperAndInjectedMembers: false); |
| 203 return result; | 203 return result; |
| 204 } | 204 } |
| 205 } | 205 } |
| OLD | NEW |