| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 classElement.ensureResolved(compiler); | 70 classElement.ensureResolved(compiler); |
| 71 if (!Elements.isNativeOrExtendsNative(classElement)) return; | 71 if (!Elements.isNativeOrExtendsNative(classElement)) return; |
| 72 if (classElement.isMixinApplication) return; | 72 if (classElement.isMixinApplication) return; |
| 73 joinFor(enqueuer).instantiatedClasses.add(classElement); | 73 joinFor(enqueuer).instantiatedClasses.add(classElement); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void registerTypeLiteral(Element element, Enqueuer enqueuer) { | 76 void registerTypeLiteral(Element element, Enqueuer enqueuer) { |
| 77 // In codegen we see the TypeConstants instead. | 77 // In codegen we see the TypeConstants instead. |
| 78 if (!enqueuer.isResolutionQueue) return; | 78 if (!enqueuer.isResolutionQueue) return; |
| 79 | 79 |
| 80 if (element.isClass()) { | 80 if (element.isClass) { |
| 81 // TODO(sra): If we had a flow query from the type literal expression to | 81 // TODO(sra): If we had a flow query from the type literal expression to |
| 82 // the Type argument of the metadata lookup, we could tell if this type | 82 // the Type argument of the metadata lookup, we could tell if this type |
| 83 // literal is really a demand for the metadata. | 83 // literal is really a demand for the metadata. |
| 84 resolutionJoin.selectedClasses.add(element); | 84 resolutionJoin.selectedClasses.add(element); |
| 85 } else { | 85 } else { |
| 86 // This is a type parameter of a parameterized class. | 86 // This is a type parameter of a parameterized class. |
| 87 // TODO(sra): Is there a way to determine which types are bound to the | 87 // TODO(sra): Is there a way to determine which types are bound to the |
| 88 // parameter? | 88 // parameter? |
| 89 resolutionJoin.allClassesSelected = true; | 89 resolutionJoin.allClassesSelected = true; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 void registerTypeConstant(Element element, Enqueuer enqueuer) { | 93 void registerTypeConstant(Element element, Enqueuer enqueuer) { |
| 94 assert(element.isClass()); | 94 assert(element.isClass); |
| 95 assert(!enqueuer.isResolutionQueue); | 95 assert(!enqueuer.isResolutionQueue); |
| 96 codegenJoin.selectedClasses.add(element); | 96 codegenJoin.selectedClasses.add(element); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void registerStaticUse(Element element, Enqueuer enqueuer) { | 99 void registerStaticUse(Element element, Enqueuer enqueuer) { |
| 100 assert(element != null); | 100 assert(element != null); |
| 101 if (!fetchedTableAccessorMethod) { | 101 if (!fetchedTableAccessorMethod) { |
| 102 fetchedTableAccessorMethod = true; | 102 fetchedTableAccessorMethod = true; |
| 103 tableAccessorMethod = compiler.findInterceptor( | 103 tableAccessorMethod = compiler.findInterceptor( |
| 104 'findIndexForNativeSubclassType'); | 104 'findIndexForNativeSubclassType'); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 // ClassesOutput: classes requiring metadata. | 142 // ClassesOutput: classes requiring metadata. |
| 143 final activeClasses = new Set<ClassElement>(); | 143 final activeClasses = new Set<ClassElement>(); |
| 144 | 144 |
| 145 CustomElementsAnalysisJoin(this.backend); | 145 CustomElementsAnalysisJoin(this.backend); |
| 146 | 146 |
| 147 void flush(Enqueuer enqueuer) { | 147 void flush(Enqueuer enqueuer) { |
| 148 if (!demanded) return; | 148 if (!demanded) return; |
| 149 var newActiveClasses = new Set<ClassElement>(); | 149 var newActiveClasses = new Set<ClassElement>(); |
| 150 for (ClassElement classElement in instantiatedClasses) { | 150 for (ClassElement classElement in instantiatedClasses) { |
| 151 bool isNative = classElement.isNative(); | 151 bool isNative = classElement.isNative; |
| 152 bool isExtension = | 152 bool isExtension = |
| 153 !isNative && Elements.isNativeOrExtendsNative(classElement); | 153 !isNative && Elements.isNativeOrExtendsNative(classElement); |
| 154 // Generate table entries for native classes that are explicitly named and | 154 // Generate table entries for native classes that are explicitly named and |
| 155 // extensions that fix our criteria. | 155 // extensions that fix our criteria. |
| 156 if ((isNative && selectedClasses.contains(classElement)) || | 156 if ((isNative && selectedClasses.contains(classElement)) || |
| 157 (isExtension && | 157 (isExtension && |
| 158 (allClassesSelected || selectedClasses.contains(classElement)))) { | 158 (allClassesSelected || selectedClasses.contains(classElement)))) { |
| 159 newActiveClasses.add(classElement); | 159 newActiveClasses.add(classElement); |
| 160 escapingConstructors(classElement).forEach(enqueuer.registerStaticUse); | 160 escapingConstructors(classElement).forEach(enqueuer.registerStaticUse); |
| 161 // Force the generaton of the type constant that is the key to an entry | 161 // Force the generaton of the type constant that is the key to an entry |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 DartType elementType = element.rawType; | 174 DartType elementType = element.rawType; |
| 175 DartType constantType = backend.typeImplementation.rawType; | 175 DartType constantType = backend.typeImplementation.rawType; |
| 176 return new TypeConstant(elementType, constantType); | 176 return new TypeConstant(elementType, constantType); |
| 177 } | 177 } |
| 178 | 178 |
| 179 List<Element> escapingConstructors(ClassElement classElement) { | 179 List<Element> escapingConstructors(ClassElement classElement) { |
| 180 List<Element> result = <Element>[]; | 180 List<Element> result = <Element>[]; |
| 181 // Only classes that extend native classes have constructors in the table. | 181 // Only classes that extend native classes have constructors in the table. |
| 182 // We could refine this to classes that extend Element, but that would break | 182 // We could refine this to classes that extend Element, but that would break |
| 183 // the tests and there is no sane reason to subclass other native classes. | 183 // the tests and there is no sane reason to subclass other native classes. |
| 184 if (classElement.isNative()) return result; | 184 if (classElement.isNative) return result; |
| 185 | 185 |
| 186 selectGenerativeConstructors(ClassElement enclosing, Element member) { | 186 selectGenerativeConstructors(ClassElement enclosing, Element member) { |
| 187 if (member.isGenerativeConstructor()) { | 187 if (member.isGenerativeConstructor) { |
| 188 // Ignore constructors that cannot be called with zero arguments. | 188 // Ignore constructors that cannot be called with zero arguments. |
| 189 FunctionElement constructor = member; | 189 FunctionElement constructor = member; |
| 190 FunctionSignature parameters = constructor.functionSignature; | 190 FunctionSignature parameters = constructor.functionSignature; |
| 191 if (parameters.requiredParameterCount == 0) { | 191 if (parameters.requiredParameterCount == 0) { |
| 192 result.add(member); | 192 result.add(member); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 classElement.forEachMember(selectGenerativeConstructors, | 196 classElement.forEachMember(selectGenerativeConstructors, |
| 197 includeBackendMembers: false, | 197 includeBackendMembers: false, |
| 198 includeSuperAndInjectedMembers: false); | 198 includeSuperAndInjectedMembers: false); |
| 199 return result; | 199 return result; |
| 200 } | 200 } |
| 201 } | 201 } |
| OLD | NEW |