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

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

Issue 2568723007: Create Namer and Emitter on codegen start. (Closed)
Patch Set: Small fix. Created 4 years 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 *
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 ClosedWorld closedWorld;
17 final Set<ClassElement> rtiNeededClasses; 18 final Set<ClassElement> rtiNeededClasses;
18 final Emitter emitter; 19 final Emitter emitter;
19 20
20 final Set<ClassElement> neededClasses = new Set<ClassElement>(); 21 final Set<ClassElement> neededClasses = new Set<ClassElement>();
21 // This field is set in [computeNeededDeclarations]. 22 // This field is set in [computeNeededDeclarations].
22 Set<ClassElement> classesOnlyNeededForRti; 23 Set<ClassElement> classesOnlyNeededForRti;
23 final Map<OutputUnit, List<ClassElement>> outputClassLists = 24 final Map<OutputUnit, List<ClassElement>> outputClassLists =
24 new Map<OutputUnit, List<ClassElement>>(); 25 new Map<OutputUnit, List<ClassElement>>();
25 final Map<OutputUnit, List<ConstantValue>> outputConstantLists = 26 final Map<OutputUnit, List<ConstantValue>> outputConstantLists =
26 new Map<OutputUnit, List<ConstantValue>>(); 27 new Map<OutputUnit, List<ConstantValue>>();
(...skipping 12 matching lines...) Expand all
39 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; 40 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[];
40 41
41 List<TypedefElement> typedefsNeededForReflection; 42 List<TypedefElement> typedefsNeededForReflection;
42 43
43 JavaScriptBackend get backend => compiler.backend; 44 JavaScriptBackend get backend => compiler.backend;
44 45
45 BackendHelpers get helpers => backend.helpers; 46 BackendHelpers get helpers => backend.helpers;
46 47
47 CoreClasses get coreClasses => compiler.coreClasses; 48 CoreClasses get coreClasses => compiler.coreClasses;
48 49
49 Collector(this.compiler, this.namer, this.rtiNeededClasses, this.emitter); 50 Collector(this.compiler, this.namer, this.closedWorld, this.rtiNeededClasses,
51 this.emitter);
50 52
51 Set<ClassElement> computeInterceptorsReferencedFromConstants() { 53 Set<ClassElement> computeInterceptorsReferencedFromConstants() {
52 Set<ClassElement> classes = new Set<ClassElement>(); 54 Set<ClassElement> classes = new Set<ClassElement>();
53 JavaScriptConstantCompiler handler = backend.constants; 55 JavaScriptConstantCompiler handler = backend.constants;
54 List<ConstantValue> constants = handler.getConstantsForEmission(); 56 List<ConstantValue> constants = handler.getConstantsForEmission();
55 for (ConstantValue constant in constants) { 57 for (ConstantValue constant in constants) {
56 if (constant is InterceptorConstantValue) { 58 if (constant is InterceptorConstantValue) {
57 InterceptorConstantValue interceptorConstant = constant; 59 InterceptorConstantValue interceptorConstant = constant;
58 classes.add(interceptorConstant.dispatchedType.element); 60 classes.add(interceptorConstant.dispatchedType.element);
59 } 61 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 FunctionElement function = element; 124 FunctionElement function = element;
123 function.functionSignature 125 function.functionSignature
124 .forEachParameter(backend.retainMetadataOf); 126 .forEachParameter(backend.retainMetadataOf);
125 } 127 }
126 } 128 }
127 } 129 }
128 for (ClassElement cls in neededClasses) { 130 for (ClassElement cls in neededClasses) {
129 final onlyForRti = classesOnlyNeededForRti.contains(cls); 131 final onlyForRti = classesOnlyNeededForRti.contains(cls);
130 if (!onlyForRti) { 132 if (!onlyForRti) {
131 backend.retainMetadataOf(cls); 133 backend.retainMetadataOf(cls);
132 new FieldVisitor(compiler, namer).visitFields(cls, false, 134 new FieldVisitor(compiler, namer, closedWorld).visitFields(cls, false,
133 (Element member, js.Name name, js.Name accessorName, 135 (Element member, js.Name name, js.Name accessorName,
134 bool needsGetter, bool needsSetter, bool needsCheckedSetter) { 136 bool needsGetter, bool needsSetter, bool needsCheckedSetter) {
135 bool needsAccessor = needsGetter || needsSetter; 137 bool needsAccessor = needsGetter || needsSetter;
136 if (needsAccessor && backend.isAccessibleByReflection(member)) { 138 if (needsAccessor && backend.isAccessibleByReflection(member)) {
137 backend.retainMetadataOf(member); 139 backend.retainMetadataOf(member);
138 } 140 }
139 }); 141 });
140 } 142 }
141 } 143 }
142 typedefsNeededForReflection.forEach(backend.retainMetadataOf); 144 typedefsNeededForReflection.forEach(backend.retainMetadataOf);
(...skipping 19 matching lines...) Expand all
162 } 164 }
163 outputConstantLists 165 outputConstantLists
164 .putIfAbsent(constantUnit, () => new List<ConstantValue>()) 166 .putIfAbsent(constantUnit, () => new List<ConstantValue>())
165 .add(constant); 167 .add(constant);
166 } 168 }
167 } 169 }
168 170
169 /// Compute all the classes and typedefs that must be emitted. 171 /// Compute all the classes and typedefs that must be emitted.
170 void computeNeededDeclarations() { 172 void computeNeededDeclarations() {
171 // Compute needed typedefs. 173 // Compute needed typedefs.
172 typedefsNeededForReflection = Elements.sortedByPosition(compiler 174 typedefsNeededForReflection = Elements.sortedByPosition(closedWorld
173 .closedWorld.allTypedefs 175 .allTypedefs
174 .where(backend.isAccessibleByReflection) 176 .where(backend.isAccessibleByReflection)
175 .toList()); 177 .toList());
176 178
177 // Compute needed classes. 179 // Compute needed classes.
178 Set<ClassElement> instantiatedClasses = compiler 180 Set<ClassElement> instantiatedClasses = compiler
179 .codegenWorld.directlyInstantiatedClasses 181 .codegenWorld.directlyInstantiatedClasses
180 .where(computeClassFilter()) 182 .where(computeClassFilter())
181 .toSet(); 183 .toSet();
182 184
183 void addClassWithSuperclasses(ClassElement cls) { 185 void addClassWithSuperclasses(ClassElement cls) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 317 }
316 318
317 void collect() { 319 void collect() {
318 computeNeededDeclarations(); 320 computeNeededDeclarations();
319 computeNeededConstants(); 321 computeNeededConstants();
320 computeNeededStatics(); 322 computeNeededStatics();
321 computeNeededStaticNonFinalFields(); 323 computeNeededStaticNonFinalFields();
322 computeNeededLibraries(); 324 computeNeededLibraries();
323 } 325 }
324 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698