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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 for (ClassElement classElement in instantiatedClasses) { | 149 for (ClassElement classElement in instantiatedClasses) { |
150 bool isNative = backend.isNative(classElement); | 150 bool isNative = backend.isNative(classElement); |
151 bool isExtension = | 151 bool isExtension = |
152 !isNative && backend.isNativeOrExtendsNative(classElement); | 152 !isNative && backend.isNativeOrExtendsNative(classElement); |
153 // Generate table entries for native classes that are explicitly named and | 153 // Generate table entries for native classes that are explicitly named and |
154 // extensions that fix our criteria. | 154 // extensions that fix our criteria. |
155 if ((isNative && selectedClasses.contains(classElement)) || | 155 if ((isNative && selectedClasses.contains(classElement)) || |
156 (isExtension && | 156 (isExtension && |
157 (allClassesSelected || selectedClasses.contains(classElement)))) { | 157 (allClassesSelected || selectedClasses.contains(classElement)))) { |
158 newActiveClasses.add(classElement); | 158 newActiveClasses.add(classElement); |
159 Iterable<Element> escapingConstructors = | 159 Iterable<ConstructorElement> escapingConstructors = |
160 computeEscapingConstructors(classElement); | 160 computeEscapingConstructors(classElement); |
161 escapingConstructors.forEach(enqueuer.registerStaticUse); | 161 for (ConstructorElement constructor in escapingConstructors) { |
| 162 enqueuer.registerStaticUse(new StaticUse.foreignUse(constructor)); |
| 163 } |
162 escapingConstructors | 164 escapingConstructors |
163 .forEach(compiler.globalDependencies.registerDependency); | 165 .forEach(compiler.globalDependencies.registerDependency); |
164 // Force the generaton of the type constant that is the key to an entry | 166 // Force the generaton of the type constant that is the key to an entry |
165 // in the generated table. | 167 // in the generated table. |
166 ConstantValue constant = makeTypeConstant(classElement); | 168 ConstantValue constant = makeTypeConstant(classElement); |
167 backend.registerCompileTimeConstant( | 169 backend.registerCompileTimeConstant( |
168 constant, compiler.globalDependencies); | 170 constant, compiler.globalDependencies); |
169 backend.addCompileTimeConstantForEmission(constant); | 171 backend.addCompileTimeConstantForEmission(constant); |
170 } | 172 } |
171 } | 173 } |
172 activeClasses.addAll(newActiveClasses); | 174 activeClasses.addAll(newActiveClasses); |
173 instantiatedClasses.removeAll(newActiveClasses); | 175 instantiatedClasses.removeAll(newActiveClasses); |
174 } | 176 } |
175 | 177 |
176 TypeConstantValue makeTypeConstant(ClassElement element) { | 178 TypeConstantValue makeTypeConstant(ClassElement element) { |
177 DartType elementType = element.rawType; | 179 DartType elementType = element.rawType; |
178 return backend.constantSystem.createType(compiler, elementType); | 180 return backend.constantSystem.createType(compiler, elementType); |
179 } | 181 } |
180 | 182 |
181 List<Element> computeEscapingConstructors(ClassElement classElement) { | 183 List<ConstructorElement> computeEscapingConstructors( |
182 List<Element> result = <Element>[]; | 184 ClassElement classElement) { |
| 185 List<ConstructorElement> result = <ConstructorElement>[]; |
183 // Only classes that extend native classes have constructors in the table. | 186 // Only classes that extend native classes have constructors in the table. |
184 // We could refine this to classes that extend Element, but that would break | 187 // We could refine this to classes that extend Element, but that would break |
185 // the tests and there is no sane reason to subclass other native classes. | 188 // the tests and there is no sane reason to subclass other native classes. |
186 if (backend.isNative(classElement)) return result; | 189 if (backend.isNative(classElement)) return result; |
187 | 190 |
188 selectGenerativeConstructors(ClassElement enclosing, Element member) { | 191 void selectGenerativeConstructors(ClassElement enclosing, Element member) { |
189 if (member.isGenerativeConstructor) { | 192 if (member.isGenerativeConstructor) { |
190 // Ignore constructors that cannot be called with zero arguments. | 193 // Ignore constructors that cannot be called with zero arguments. |
191 FunctionElement constructor = member; | 194 ConstructorElement constructor = member; |
192 constructor.computeType(compiler.resolution); | 195 constructor.computeType(compiler.resolution); |
193 FunctionSignature parameters = constructor.functionSignature; | 196 FunctionSignature parameters = constructor.functionSignature; |
194 if (parameters.requiredParameterCount == 0) { | 197 if (parameters.requiredParameterCount == 0) { |
195 result.add(member); | 198 result.add(member); |
196 } | 199 } |
197 } | 200 } |
198 } | 201 } |
199 classElement.forEachMember(selectGenerativeConstructors, | 202 classElement.forEachMember(selectGenerativeConstructors, |
200 includeBackendMembers: false, | 203 includeBackendMembers: false, |
201 includeSuperAndInjectedMembers: false); | 204 includeSuperAndInjectedMembers: false); |
202 return result; | 205 return result; |
203 } | 206 } |
204 } | 207 } |
OLD | NEW |