| 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 * |
| 11 * The code for the containing (used) methods must exist in the `universe`. | 11 * The code for the containing (used) methods must exist in the `universe`. |
| 12 */ | 12 */ |
| 13 class Collector { | 13 class Collector { |
| 14 // TODO(floitsch): the code-emitter task should not need a namer. | 14 // TODO(floitsch): the code-emitter task should not need a namer. |
| 15 final Namer namer; | 15 final Namer namer; |
| 16 final Compiler compiler; | 16 final Compiler compiler; |
| 17 final Set<ClassElement> rtiNeededClasses; | 17 final Set<ClassElement> rtiNeededClasses; |
| 18 final Emitter emitter; | 18 final Emitter emitter; |
| 19 // TODO(floitsch): remove this field. | |
| 20 // The field is untyped, because we don't want to import the full emitter | |
| 21 // class. | |
| 22 final oldEmitter; | |
| 23 | 19 |
| 24 final Set<ClassElement> neededClasses = new Set<ClassElement>(); | 20 final Set<ClassElement> neededClasses = new Set<ClassElement>(); |
| 21 // This field is set in [computeNeededDeclarations]. |
| 25 Set<ClassElement> classesOnlyNeededForRti; | 22 Set<ClassElement> classesOnlyNeededForRti; |
| 26 final Map<OutputUnit, List<ClassElement>> outputClassLists = | 23 final Map<OutputUnit, List<ClassElement>> outputClassLists = |
| 27 new Map<OutputUnit, List<ClassElement>>(); | 24 new Map<OutputUnit, List<ClassElement>>(); |
| 28 final Map<OutputUnit, List<ConstantValue>> outputConstantLists = | 25 final Map<OutputUnit, List<ConstantValue>> outputConstantLists = |
| 29 new Map<OutputUnit, List<ConstantValue>>(); | 26 new Map<OutputUnit, List<ConstantValue>>(); |
| 30 final Map<OutputUnit, List<Element>> outputStaticLists = | 27 final Map<OutputUnit, List<Element>> outputStaticLists = |
| 31 new Map<OutputUnit, List<Element>>(); | 28 new Map<OutputUnit, List<Element>>(); |
| 32 final Map<OutputUnit, List<VariableElement>> outputStaticNonFinalFieldLists = | 29 final Map<OutputUnit, List<VariableElement>> outputStaticNonFinalFieldLists = |
| 33 new Map<OutputUnit, List<VariableElement>>(); | 30 new Map<OutputUnit, List<VariableElement>>(); |
| 34 final Map<OutputUnit, Set<LibraryElement>> outputLibraryLists = | 31 final Map<OutputUnit, Set<LibraryElement>> outputLibraryLists = |
| 35 new Map<OutputUnit, Set<LibraryElement>>(); | 32 new Map<OutputUnit, Set<LibraryElement>>(); |
| 36 | 33 |
| 37 /// True, if the output contains a constant list. | 34 /// True, if the output contains a constant list. |
| 38 /// | 35 /// |
| 39 /// This flag is updated in [computeNeededConstants]. | 36 /// This flag is updated in [computeNeededConstants]. |
| 40 bool outputContainsConstantList = false; | 37 bool outputContainsConstantList = false; |
| 41 | 38 |
| 42 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; | 39 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; |
| 43 | 40 |
| 44 List<TypedefElement> typedefsNeededForReflection; | 41 List<TypedefElement> typedefsNeededForReflection; |
| 45 | 42 |
| 46 JavaScriptBackend get backend => compiler.backend; | 43 JavaScriptBackend get backend => compiler.backend; |
| 47 | 44 |
| 48 Collector(this.compiler, this.namer, this.rtiNeededClasses, | 45 Collector(this.compiler, this.namer, this.rtiNeededClasses, this.emitter); |
| 49 this.emitter, this.oldEmitter); | |
| 50 | 46 |
| 51 Set<ClassElement> computeInterceptorsReferencedFromConstants() { | 47 Set<ClassElement> computeInterceptorsReferencedFromConstants() { |
| 52 Set<ClassElement> classes = new Set<ClassElement>(); | 48 Set<ClassElement> classes = new Set<ClassElement>(); |
| 53 JavaScriptConstantCompiler handler = backend.constants; | 49 JavaScriptConstantCompiler handler = backend.constants; |
| 54 List<ConstantValue> constants = handler.getConstantsForEmission(); | 50 List<ConstantValue> constants = handler.getConstantsForEmission(); |
| 55 for (ConstantValue constant in constants) { | 51 for (ConstantValue constant in constants) { |
| 56 if (constant is InterceptorConstantValue) { | 52 if (constant is InterceptorConstantValue) { |
| 57 InterceptorConstantValue interceptorConstant = constant; | 53 InterceptorConstantValue interceptorConstant = constant; |
| 58 classes.add(interceptorConstant.dispatchedType.element); | 54 classes.add(interceptorConstant.dispatchedType.element); |
| 59 } | 55 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 FunctionElement function = element; | 118 FunctionElement function = element; |
| 123 function.functionSignature.forEachParameter( | 119 function.functionSignature.forEachParameter( |
| 124 backend.retainMetadataOf); | 120 backend.retainMetadataOf); |
| 125 } | 121 } |
| 126 } | 122 } |
| 127 } | 123 } |
| 128 for (ClassElement cls in neededClasses) { | 124 for (ClassElement cls in neededClasses) { |
| 129 final onlyForRti = classesOnlyNeededForRti.contains(cls); | 125 final onlyForRti = classesOnlyNeededForRti.contains(cls); |
| 130 if (!onlyForRti) { | 126 if (!onlyForRti) { |
| 131 backend.retainMetadataOf(cls); | 127 backend.retainMetadataOf(cls); |
| 132 oldEmitter.classEmitter.visitFields(cls, false, | 128 new FieldVisitor(compiler, namer).visitFields(cls, false, |
| 133 (Element member, | 129 (Element member, |
| 134 js.Name name, | 130 js.Name name, |
| 135 js.Name accessorName, | 131 js.Name accessorName, |
| 136 bool needsGetter, | 132 bool needsGetter, |
| 137 bool needsSetter, | 133 bool needsSetter, |
| 138 bool needsCheckedSetter) { | 134 bool needsCheckedSetter) { |
| 139 bool needsAccessor = needsGetter || needsSetter; | 135 bool needsAccessor = needsGetter || needsSetter; |
| 140 if (needsAccessor && backend.isAccessibleByReflection(member)) { | 136 if (needsAccessor && backend.isAccessibleByReflection(member)) { |
| 141 backend.retainMetadataOf(member); | 137 backend.retainMetadataOf(member); |
| 142 } | 138 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 294 } |
| 299 | 295 |
| 300 void collect() { | 296 void collect() { |
| 301 computeNeededDeclarations(); | 297 computeNeededDeclarations(); |
| 302 computeNeededConstants(); | 298 computeNeededConstants(); |
| 303 computeNeededStatics(); | 299 computeNeededStatics(); |
| 304 computeNeededStaticNonFinalFields(); | 300 computeNeededStaticNonFinalFields(); |
| 305 computeNeededLibraries(); | 301 computeNeededLibraries(); |
| 306 } | 302 } |
| 307 } | 303 } |
| OLD | NEW |