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