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

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

Issue 1225083004: dart2js: Emit static const fields if accessible by reflections. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebase Created 5 years, 5 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698