Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: pkg/compiler/lib/src/js_emitter/program_builder/collector.dart

Issue 2814453005: Merge CommonElements and BackendHelpers! (Closed)
Patch Set: comments and re-merge, take two Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
36 /// 36 ///
37 /// This flag is updated in [computeNeededConstants]. 37 /// This flag is updated in [computeNeededConstants].
38 bool outputContainsConstantList = false; 38 bool outputContainsConstantList = false;
39 39
40 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; 40 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[];
41 41
42 List<TypedefElement> typedefsNeededForReflection; 42 List<TypedefElement> typedefsNeededForReflection;
43 43
44 JavaScriptBackend get backend => compiler.backend; 44 JavaScriptBackend get backend => compiler.backend;
45 45
46 BackendHelpers get helpers => backend.helpers;
47
48 CommonElements get commonElements => compiler.commonElements; 46 CommonElements get commonElements => compiler.commonElements;
49 47
50 Collector(this.compiler, this.namer, this.closedWorld, this.rtiNeededClasses, 48 Collector(this.compiler, this.namer, this.closedWorld, this.rtiNeededClasses,
51 this.emitter); 49 this.emitter);
52 50
53 Set<ClassElement> computeInterceptorsReferencedFromConstants() { 51 Set<ClassElement> computeInterceptorsReferencedFromConstants() {
54 Set<ClassElement> classes = new Set<ClassElement>(); 52 Set<ClassElement> classes = new Set<ClassElement>();
55 JavaScriptConstantCompiler handler = backend.constants; 53 JavaScriptConstantCompiler handler = backend.constants;
56 List<ConstantValue> constants = handler.getConstantsForEmission(); 54 List<ConstantValue> constants = handler.getConstantsForEmission();
57 for (ConstantValue constant in constants) { 55 for (ConstantValue constant in constants) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // Add unneeded interceptors to the [unneededClasses] set. 90 // Add unneeded interceptors to the [unneededClasses] set.
93 for (ClassEntity interceptor 91 for (ClassEntity interceptor
94 in backend.interceptorData.interceptedClasses) { 92 in backend.interceptorData.interceptedClasses) {
95 if (!needed.contains(interceptor) && 93 if (!needed.contains(interceptor) &&
96 interceptor != commonElements.objectClass) { 94 interceptor != commonElements.objectClass) {
97 unneededClasses.add(interceptor); 95 unneededClasses.add(interceptor);
98 } 96 }
99 } 97 }
100 98
101 // These classes are just helpers for the backend's type system. 99 // These classes are just helpers for the backend's type system.
102 unneededClasses.add(helpers.jsMutableArrayClass); 100 unneededClasses.add(commonElements.jsMutableArrayClass);
103 unneededClasses.add(helpers.jsFixedArrayClass); 101 unneededClasses.add(commonElements.jsFixedArrayClass);
104 unneededClasses.add(helpers.jsExtendableArrayClass); 102 unneededClasses.add(commonElements.jsExtendableArrayClass);
105 unneededClasses.add(helpers.jsUInt32Class); 103 unneededClasses.add(commonElements.jsUInt32Class);
106 unneededClasses.add(helpers.jsUInt31Class); 104 unneededClasses.add(commonElements.jsUInt31Class);
107 unneededClasses.add(helpers.jsPositiveIntClass); 105 unneededClasses.add(commonElements.jsPositiveIntClass);
108 106
109 return (ClassEntity cls) => !unneededClasses.contains(cls); 107 return (ClassEntity cls) => !unneededClasses.contains(cls);
110 } 108 }
111 109
112 /** 110 /**
113 * Compute all the constants that must be emitted. 111 * Compute all the constants that must be emitted.
114 */ 112 */
115 void computeNeededConstants() { 113 void computeNeededConstants() {
116 // Make sure we retain all metadata of all elements. This could add new 114 // Make sure we retain all metadata of all elements. This could add new
117 // constants to the handler. 115 // constants to the handler.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // neededClasses must only contain classes that have been resolved and 218 // neededClasses must only contain classes that have been resolved and
221 // codegen'd. The rtiNeededClasses may contain additional classes, but 219 // codegen'd. The rtiNeededClasses may contain additional classes, but
222 // these are thought to not have been instantiated, so we neeed to be able 220 // these are thought to not have been instantiated, so we neeed to be able
223 // to identify them later and make sure we only emit "empty shells" without 221 // to identify them later and make sure we only emit "empty shells" without
224 // fields, etc. 222 // fields, etc.
225 classesOnlyNeededForRti = rtiNeededClasses.difference(neededClasses); 223 classesOnlyNeededForRti = rtiNeededClasses.difference(neededClasses);
226 224
227 neededClasses.addAll(classesOnlyNeededForRti); 225 neededClasses.addAll(classesOnlyNeededForRti);
228 226
229 // TODO(18175, floitsch): remove once issue 18175 is fixed. 227 // TODO(18175, floitsch): remove once issue 18175 is fixed.
230 if (neededClasses.contains(helpers.jsIntClass)) { 228 if (neededClasses.contains(commonElements.jsIntClass)) {
231 neededClasses.add(commonElements.intClass); 229 neededClasses.add(commonElements.intClass);
232 } 230 }
233 if (neededClasses.contains(helpers.jsDoubleClass)) { 231 if (neededClasses.contains(commonElements.jsDoubleClass)) {
234 neededClasses.add(commonElements.doubleClass); 232 neededClasses.add(commonElements.doubleClass);
235 } 233 }
236 if (neededClasses.contains(helpers.jsNumberClass)) { 234 if (neededClasses.contains(commonElements.jsNumberClass)) {
237 neededClasses.add(commonElements.numClass); 235 neededClasses.add(commonElements.numClass);
238 } 236 }
239 if (neededClasses.contains(helpers.jsStringClass)) { 237 if (neededClasses.contains(commonElements.jsStringClass)) {
240 neededClasses.add(commonElements.stringClass); 238 neededClasses.add(commonElements.stringClass);
241 } 239 }
242 if (neededClasses.contains(helpers.jsBoolClass)) { 240 if (neededClasses.contains(commonElements.jsBoolClass)) {
243 neededClasses.add(commonElements.boolClass); 241 neededClasses.add(commonElements.boolClass);
244 } 242 }
245 if (neededClasses.contains(helpers.jsArrayClass)) { 243 if (neededClasses.contains(commonElements.jsArrayClass)) {
246 neededClasses.add(commonElements.listClass); 244 neededClasses.add(commonElements.listClass);
247 } 245 }
248 246
249 // 4. Finally, sort the classes. 247 // 4. Finally, sort the classes.
250 List<ClassElement> sortedClasses = Elements.sortedByPosition(neededClasses); 248 List<ClassElement> sortedClasses = Elements.sortedByPosition(neededClasses);
251 249
252 for (ClassElement element in sortedClasses) { 250 for (ClassElement element in sortedClasses) {
253 if (backend.nativeData.isNativeOrExtendsNative(element) && 251 if (backend.nativeData.isNativeOrExtendsNative(element) &&
254 !classesOnlyNeededForRti.contains(element)) { 252 !classesOnlyNeededForRti.contains(element)) {
255 // For now, native classes and related classes cannot be deferred. 253 // For now, native classes and related classes cannot be deferred.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 326 }
329 327
330 void collect() { 328 void collect() {
331 computeNeededDeclarations(); 329 computeNeededDeclarations();
332 computeNeededConstants(); 330 computeNeededConstants();
333 computeNeededStatics(); 331 computeNeededStatics();
334 computeNeededStaticNonFinalFields(); 332 computeNeededStaticNonFinalFields();
335 computeNeededLibraries(); 333 computeNeededLibraries();
336 } 334 }
337 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698