| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.program_builder; | 5 part of dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
| 9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
| 10 * | 10 * |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 /// Compute all the classes and typedefs that must be emitted. | 171 /// Compute all the classes and typedefs that must be emitted. |
| 172 void computeNeededDeclarations() { | 172 void computeNeededDeclarations() { |
| 173 // Compute needed typedefs. | 173 // Compute needed typedefs. |
| 174 typedefsNeededForReflection = Elements.sortedByPosition(closedWorld | 174 typedefsNeededForReflection = Elements.sortedByPosition(closedWorld |
| 175 .allTypedefs | 175 .allTypedefs |
| 176 .where(backend.isAccessibleByReflection) | 176 .where(backend.isAccessibleByReflection) |
| 177 .toList()); | 177 .toList()); |
| 178 | 178 |
| 179 // Compute needed classes. | 179 // Compute needed classes. |
| 180 Set<ClassElement> instantiatedClasses = compiler | 180 Set<ClassElement> instantiatedClasses = compiler |
| 181 .codegenWorld.directlyInstantiatedClasses | 181 // TODO(johnniwinther): This should be accessed from a codegen closed |
| 182 // world. |
| 183 .codegenWorldBuilder |
| 184 .directlyInstantiatedClasses |
| 182 .where(computeClassFilter()) | 185 .where(computeClassFilter()) |
| 183 .toSet(); | 186 .toSet(); |
| 184 | 187 |
| 185 void addClassWithSuperclasses(ClassElement cls) { | 188 void addClassWithSuperclasses(ClassElement cls) { |
| 186 neededClasses.add(cls); | 189 neededClasses.add(cls); |
| 187 for (ClassElement superclass = cls.superclass; | 190 for (ClassElement superclass = cls.superclass; |
| 188 superclass != null; | 191 superclass != null; |
| 189 superclass = superclass.superclass) { | 192 superclass = superclass.superclass) { |
| 190 neededClasses.add(superclass); | 193 neededClasses.add(superclass); |
| 191 } | 194 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 282 |
| 280 void computeNeededStaticNonFinalFields() { | 283 void computeNeededStaticNonFinalFields() { |
| 281 JavaScriptConstantCompiler handler = backend.constants; | 284 JavaScriptConstantCompiler handler = backend.constants; |
| 282 addToOutputUnit(Element element) { | 285 addToOutputUnit(Element element) { |
| 283 List<VariableElement> list = outputStaticNonFinalFieldLists.putIfAbsent( | 286 List<VariableElement> list = outputStaticNonFinalFieldLists.putIfAbsent( |
| 284 compiler.deferredLoadTask.outputUnitForElement(element), | 287 compiler.deferredLoadTask.outputUnitForElement(element), |
| 285 () => new List<VariableElement>()); | 288 () => new List<VariableElement>()); |
| 286 list.add(element); | 289 list.add(element); |
| 287 } | 290 } |
| 288 | 291 |
| 289 Iterable<Element> fields = compiler.codegenWorld.allReferencedStaticFields | 292 Iterable<Element> fields = compiler |
| 293 // TODO(johnniwinther): This should be accessed from a codegen closed |
| 294 // world. |
| 295 .codegenWorldBuilder |
| 296 .allReferencedStaticFields |
| 290 .where((FieldElement field) { | 297 .where((FieldElement field) { |
| 291 if (!field.isConst) { | 298 if (!field.isConst) { |
| 292 return field.isField && | 299 return field.isField && |
| 293 !field.isInstanceMember && | 300 !field.isInstanceMember && |
| 294 !field.isFinal && | 301 !field.isFinal && |
| 295 field.constant != null; | 302 field.constant != null; |
| 296 } else { | 303 } else { |
| 297 // We also need to emit static const fields if they are available for | 304 // We also need to emit static const fields if they are available for |
| 298 // reflection. | 305 // reflection. |
| 299 return backend.isAccessibleByReflection(field); | 306 return backend.isAccessibleByReflection(field); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 317 } | 324 } |
| 318 | 325 |
| 319 void collect() { | 326 void collect() { |
| 320 computeNeededDeclarations(); | 327 computeNeededDeclarations(); |
| 321 computeNeededConstants(); | 328 computeNeededConstants(); |
| 322 computeNeededStatics(); | 329 computeNeededStatics(); |
| 323 computeNeededStaticNonFinalFields(); | 330 computeNeededStaticNonFinalFields(); |
| 324 computeNeededLibraries(); | 331 computeNeededLibraries(); |
| 325 } | 332 } |
| 326 } | 333 } |
| OLD | NEW |