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 24 matching lines...) Expand all Loading... |
35 /// | 35 /// |
36 /// This flag is updated in [computeNeededConstants]. | 36 /// This flag is updated in [computeNeededConstants]. |
37 bool outputContainsConstantList = false; | 37 bool outputContainsConstantList = false; |
38 | 38 |
39 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; | 39 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; |
40 | 40 |
41 List<TypedefElement> typedefsNeededForReflection; | 41 List<TypedefElement> typedefsNeededForReflection; |
42 | 42 |
43 JavaScriptBackend get backend => compiler.backend; | 43 JavaScriptBackend get backend => compiler.backend; |
44 | 44 |
| 45 BackendHelpers get helpers => backend.helpers; |
| 46 |
45 CoreClasses get coreClasses => compiler.coreClasses; | 47 CoreClasses get coreClasses => compiler.coreClasses; |
46 | 48 |
47 Collector(this.compiler, this.namer, this.rtiNeededClasses, this.emitter); | 49 Collector(this.compiler, this.namer, this.rtiNeededClasses, this.emitter); |
48 | 50 |
49 Set<ClassElement> computeInterceptorsReferencedFromConstants() { | 51 Set<ClassElement> computeInterceptorsReferencedFromConstants() { |
50 Set<ClassElement> classes = new Set<ClassElement>(); | 52 Set<ClassElement> classes = new Set<ClassElement>(); |
51 JavaScriptConstantCompiler handler = backend.constants; | 53 JavaScriptConstantCompiler handler = backend.constants; |
52 List<ConstantValue> constants = handler.getConstantsForEmission(); | 54 List<ConstantValue> constants = handler.getConstantsForEmission(); |
53 for (ConstantValue constant in constants) { | 55 for (ConstantValue constant in constants) { |
54 if (constant is InterceptorConstantValue) { | 56 if (constant is InterceptorConstantValue) { |
(...skipping 30 matching lines...) Expand all Loading... |
85 | 87 |
86 // Add unneeded interceptors to the [unneededClasses] set. | 88 // Add unneeded interceptors to the [unneededClasses] set. |
87 for (ClassElement interceptor in backend.interceptedClasses) { | 89 for (ClassElement interceptor in backend.interceptedClasses) { |
88 if (!needed.contains(interceptor) | 90 if (!needed.contains(interceptor) |
89 && interceptor != coreClasses.objectClass) { | 91 && interceptor != coreClasses.objectClass) { |
90 unneededClasses.add(interceptor); | 92 unneededClasses.add(interceptor); |
91 } | 93 } |
92 } | 94 } |
93 | 95 |
94 // These classes are just helpers for the backend's type system. | 96 // These classes are just helpers for the backend's type system. |
95 unneededClasses.add(backend.jsMutableArrayClass); | 97 unneededClasses.add(helpers.jsMutableArrayClass); |
96 unneededClasses.add(backend.jsFixedArrayClass); | 98 unneededClasses.add(helpers.jsFixedArrayClass); |
97 unneededClasses.add(backend.jsExtendableArrayClass); | 99 unneededClasses.add(helpers.jsExtendableArrayClass); |
98 unneededClasses.add(backend.jsUInt32Class); | 100 unneededClasses.add(helpers.jsUInt32Class); |
99 unneededClasses.add(backend.jsUInt31Class); | 101 unneededClasses.add(helpers.jsUInt31Class); |
100 unneededClasses.add(backend.jsPositiveIntClass); | 102 unneededClasses.add(helpers.jsPositiveIntClass); |
101 | 103 |
102 return (ClassElement cls) => !unneededClasses.contains(cls); | 104 return (ClassElement cls) => !unneededClasses.contains(cls); |
103 } | 105 } |
104 | 106 |
105 /** | 107 /** |
106 * Compute all the constants that must be emitted. | 108 * Compute all the constants that must be emitted. |
107 */ | 109 */ |
108 void computeNeededConstants() { | 110 void computeNeededConstants() { |
109 // Make sure we retain all metadata of all elements. This could add new | 111 // Make sure we retain all metadata of all elements. This could add new |
110 // constants to the handler. | 112 // constants to the handler. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // neededClasses must only contain classes that have been resolved and | 210 // neededClasses must only contain classes that have been resolved and |
209 // codegen'd. The rtiNeededClasses may contain additional classes, but | 211 // codegen'd. The rtiNeededClasses may contain additional classes, but |
210 // these are thought to not have been instantiated, so we neeed to be able | 212 // these are thought to not have been instantiated, so we neeed to be able |
211 // to identify them later and make sure we only emit "empty shells" without | 213 // to identify them later and make sure we only emit "empty shells" without |
212 // fields, etc. | 214 // fields, etc. |
213 classesOnlyNeededForRti = rtiNeededClasses.difference(neededClasses); | 215 classesOnlyNeededForRti = rtiNeededClasses.difference(neededClasses); |
214 | 216 |
215 neededClasses.addAll(classesOnlyNeededForRti); | 217 neededClasses.addAll(classesOnlyNeededForRti); |
216 | 218 |
217 // TODO(18175, floitsch): remove once issue 18175 is fixed. | 219 // TODO(18175, floitsch): remove once issue 18175 is fixed. |
218 if (neededClasses.contains(backend.jsIntClass)) { | 220 if (neededClasses.contains(helpers.jsIntClass)) { |
219 neededClasses.add(coreClasses.intClass); | 221 neededClasses.add(coreClasses.intClass); |
220 } | 222 } |
221 if (neededClasses.contains(backend.jsDoubleClass)) { | 223 if (neededClasses.contains(helpers.jsDoubleClass)) { |
222 neededClasses.add(coreClasses.doubleClass); | 224 neededClasses.add(coreClasses.doubleClass); |
223 } | 225 } |
224 if (neededClasses.contains(backend.jsNumberClass)) { | 226 if (neededClasses.contains(helpers.jsNumberClass)) { |
225 neededClasses.add(coreClasses.numClass); | 227 neededClasses.add(coreClasses.numClass); |
226 } | 228 } |
227 if (neededClasses.contains(backend.jsStringClass)) { | 229 if (neededClasses.contains(helpers.jsStringClass)) { |
228 neededClasses.add(coreClasses.stringClass); | 230 neededClasses.add(coreClasses.stringClass); |
229 } | 231 } |
230 if (neededClasses.contains(backend.jsBoolClass)) { | 232 if (neededClasses.contains(helpers.jsBoolClass)) { |
231 neededClasses.add(coreClasses.boolClass); | 233 neededClasses.add(coreClasses.boolClass); |
232 } | 234 } |
233 if (neededClasses.contains(backend.jsArrayClass)) { | 235 if (neededClasses.contains(helpers.jsArrayClass)) { |
234 neededClasses.add(coreClasses.listClass); | 236 neededClasses.add(coreClasses.listClass); |
235 } | 237 } |
236 | 238 |
237 // 4. Finally, sort the classes. | 239 // 4. Finally, sort the classes. |
238 List<ClassElement> sortedClasses = Elements.sortedByPosition(neededClasses); | 240 List<ClassElement> sortedClasses = Elements.sortedByPosition(neededClasses); |
239 | 241 |
240 for (ClassElement element in sortedClasses) { | 242 for (ClassElement element in sortedClasses) { |
241 if (backend.isNativeOrExtendsNative(element) && | 243 if (backend.isNativeOrExtendsNative(element) && |
242 !classesOnlyNeededForRti.contains(element)) { | 244 !classesOnlyNeededForRti.contains(element)) { |
243 // For now, native classes and related classes cannot be deferred. | 245 // For now, native classes and related classes cannot be deferred. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 308 } |
307 | 309 |
308 void collect() { | 310 void collect() { |
309 computeNeededDeclarations(); | 311 computeNeededDeclarations(); |
310 computeNeededConstants(); | 312 computeNeededConstants(); |
311 computeNeededStatics(); | 313 computeNeededStatics(); |
312 computeNeededStaticNonFinalFields(); | 314 computeNeededStaticNonFinalFields(); |
313 computeNeededLibraries(); | 315 computeNeededLibraries(); |
314 } | 316 } |
315 } | 317 } |
OLD | NEW |