| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 for (Element element in Elements.sortedByPosition(elements)) { | 267 for (Element element in Elements.sortedByPosition(elements)) { |
| 268 List<Element> list = outputStaticLists.putIfAbsent( | 268 List<Element> list = outputStaticLists.putIfAbsent( |
| 269 compiler.deferredLoadTask.outputUnitForElement(element), | 269 compiler.deferredLoadTask.outputUnitForElement(element), |
| 270 () => new List<Element>()); | 270 () => new List<Element>()); |
| 271 list.add(element); | 271 list.add(element); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 void computeNeededStaticNonFinalFields() { | 275 void computeNeededStaticNonFinalFields() { |
| 276 JavaScriptConstantCompiler handler = backend.constants; | 276 JavaScriptConstantCompiler handler = backend.constants; |
| 277 addToOutputUnit(Element element) { |
| 278 List<VariableElement> list = outputStaticNonFinalFieldLists.putIfAbsent( |
| 279 compiler.deferredLoadTask.outputUnitForElement(element), |
| 280 () => new List<VariableElement>()); |
| 281 list.add(element); |
| 282 } |
| 283 |
| 277 Iterable<VariableElement> staticNonFinalFields = handler | 284 Iterable<VariableElement> staticNonFinalFields = handler |
| 278 .getStaticNonFinalFieldsForEmission() | 285 .getStaticNonFinalFieldsForEmission() |
| 279 .where(compiler.codegenWorld.allReferencedStaticFields.contains); | 286 .where(compiler.codegenWorld.allReferencedStaticFields.contains); |
| 280 for (Element element in Elements.sortedByPosition(staticNonFinalFields)) { | 287 |
| 281 List<VariableElement> list = outputStaticNonFinalFieldLists.putIfAbsent( | 288 Elements.sortedByPosition(staticNonFinalFields).forEach(addToOutputUnit); |
| 282 compiler.deferredLoadTask.outputUnitForElement(element), | 289 |
| 283 () => new List<VariableElement>()); | 290 // We also need to emit static const fields if they are available for |
| 284 list.add(element); | 291 // reflection. |
| 285 } | 292 compiler.codegenWorld.allReferencedStaticFields |
| 293 .where((FieldElement field) => field.isConst) |
| 294 .where(backend.isAccessibleByReflection) |
| 295 .forEach(addToOutputUnit); |
| 286 } | 296 } |
| 287 | 297 |
| 288 void computeNeededLibraries() { | 298 void computeNeededLibraries() { |
| 289 void addSurroundingLibraryToSet(Element element) { | 299 void addSurroundingLibraryToSet(Element element) { |
| 290 OutputUnit unit = compiler.deferredLoadTask.outputUnitForElement(element); | 300 OutputUnit unit = compiler.deferredLoadTask.outputUnitForElement(element); |
| 291 LibraryElement library = element.library; | 301 LibraryElement library = element.library; |
| 292 outputLibraryLists.putIfAbsent(unit, () => new Set<LibraryElement>()) | 302 outputLibraryLists.putIfAbsent(unit, () => new Set<LibraryElement>()) |
| 293 .add(library); | 303 .add(library); |
| 294 } | 304 } |
| 295 | 305 |
| 296 backend.generatedCode.keys.forEach(addSurroundingLibraryToSet); | 306 backend.generatedCode.keys.forEach(addSurroundingLibraryToSet); |
| 297 neededClasses.forEach(addSurroundingLibraryToSet); | 307 neededClasses.forEach(addSurroundingLibraryToSet); |
| 298 } | 308 } |
| 299 | 309 |
| 300 void collect() { | 310 void collect() { |
| 301 computeNeededDeclarations(); | 311 computeNeededDeclarations(); |
| 302 computeNeededConstants(); | 312 computeNeededConstants(); |
| 303 computeNeededStatics(); | 313 computeNeededStatics(); |
| 304 computeNeededStaticNonFinalFields(); | 314 computeNeededStaticNonFinalFields(); |
| 305 computeNeededLibraries(); | 315 computeNeededLibraries(); |
| 306 } | 316 } |
| 307 } | 317 } |
| OLD | NEW |