OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
6 | 6 |
7 import '../js_emitter.dart' show computeMixinClass, Emitter; | 7 import '../js_emitter.dart' show computeMixinClass, Emitter; |
8 import '../model.dart'; | 8 import '../model.dart'; |
9 | 9 |
10 import '../../common.dart'; | 10 import '../../common.dart'; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 // to check that the library has been loaded. | 93 // to check that the library has been loaded. |
94 _compiler.deferredLoadTask.allOutputUnits.forEach( | 94 _compiler.deferredLoadTask.allOutputUnits.forEach( |
95 _registry.registerOutputUnit); | 95 _registry.registerOutputUnit); |
96 collector.outputClassLists.forEach(_registry.registerElements); | 96 collector.outputClassLists.forEach(_registry.registerElements); |
97 collector.outputStaticLists.forEach(_registry.registerElements); | 97 collector.outputStaticLists.forEach(_registry.registerElements); |
98 collector.outputConstantLists.forEach(_registerConstants); | 98 collector.outputConstantLists.forEach(_registerConstants); |
99 collector.outputStaticNonFinalFieldLists.forEach( | 99 collector.outputStaticNonFinalFieldLists.forEach( |
100 _registry.registerElements); | 100 _registry.registerElements); |
101 | 101 |
102 // We always add the current isolate holder. | 102 // We always add the current isolate holder. |
103 _registry.registerHolder( | 103 _registerStaticStateHolder(); |
104 namer.staticStateHolder, isStaticStateHolder: true); | |
105 | 104 |
106 // We need to run the native-preparation before we build the output. The | 105 // We need to run the native-preparation before we build the output. The |
107 // preparation code, in turn needs the classes to be set up. | 106 // preparation code, in turn needs the classes to be set up. |
108 // We thus build the classes before building their containers. | 107 // We thus build the classes before building their containers. |
109 collector.outputClassLists.forEach((OutputUnit _, List<ClassElement> classes ) { | 108 collector.outputClassLists.forEach((OutputUnit _, List<ClassElement> classes ) { |
110 classes.forEach(_buildClass); | 109 classes.forEach(_buildClass); |
111 }); | 110 }); |
112 | 111 |
113 // Resolve the superclass references after we've processed all the classes. | 112 // Resolve the superclass references after we've processed all the classes. |
114 _classes.forEach((ClassElement element, Class c) { | 113 _classes.forEach((ClassElement element, Class c) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 return staticNonFinalFields | 243 return staticNonFinalFields |
245 .map(_buildStaticField) | 244 .map(_buildStaticField) |
246 .toList(growable: false); | 245 .toList(growable: false); |
247 } | 246 } |
248 | 247 |
249 StaticField _buildStaticField(Element element) { | 248 StaticField _buildStaticField(Element element) { |
250 JavaScriptConstantCompiler handler = backend.constants; | 249 JavaScriptConstantCompiler handler = backend.constants; |
251 ConstantValue initialValue = handler.getInitialValueFor(element); | 250 ConstantValue initialValue = handler.getInitialValueFor(element); |
252 // TODO(zarah): The holder should not be registered during building of | 251 // TODO(zarah): The holder should not be registered during building of |
253 // a static field. | 252 // a static field. |
254 _registry.registerHolder(namer.globalObjectForConstant(initialValue)); | 253 _registry.registerHolder( |
254 namer.globalObjectForConstant(initialValue), isConstantsHolder: true); | |
255 js.Expression code = _task.emitter.constantReference(initialValue); | 255 js.Expression code = _task.emitter.constantReference(initialValue); |
256 js.Name name = namer.globalPropertyName(element); | 256 js.Name name = namer.globalPropertyName(element); |
257 bool isFinal = false; | 257 bool isFinal = false; |
258 bool isLazy = false; | 258 bool isLazy = false; |
259 | 259 |
260 // TODO(floitsch): we shouldn't update the registry in the middle of | 260 // TODO(floitsch): we shouldn't update the registry in the middle of |
261 // building a static field. (Note that the $ holder is already registered | 261 // building a static field. (Note that the $ holder is already registered |
Siggi Cherem (dart-lang)
2015/07/17 16:04:04
maybe update wording in comment (the reference to
floitsch
2015/07/17 17:27:18
Done.
| |
262 // earlier). | 262 // earlier). |
263 return new StaticField(element, | 263 return new StaticField(element, |
264 name, _registry.registerHolder(r'$'), code, | 264 name, _registerStaticStateHolder(), code, |
265 isFinal, isLazy); | 265 isFinal, isLazy); |
266 } | 266 } |
267 | 267 |
268 List<StaticField> _buildStaticLazilyInitializedFields( | 268 List<StaticField> _buildStaticLazilyInitializedFields( |
269 LibrariesMap librariesMap) { | 269 LibrariesMap librariesMap) { |
270 // TODO(floitsch): lazy fields should just be in their respective | 270 // TODO(floitsch): lazy fields should just be in their respective |
271 // libraries. | 271 // libraries. |
272 if (librariesMap != _registry.mainLibrariesMap) { | 272 if (librariesMap != _registry.mainLibrariesMap) { |
273 return const <StaticField>[]; | 273 return const <StaticField>[]; |
274 } | 274 } |
(...skipping 11 matching lines...) Expand all Loading... | |
286 js.Expression code = backend.generatedCode[element]; | 286 js.Expression code = backend.generatedCode[element]; |
287 // The code is null if we ended up not needing the lazily | 287 // The code is null if we ended up not needing the lazily |
288 // initialized field after all because of constant folding | 288 // initialized field after all because of constant folding |
289 // before code generation. | 289 // before code generation. |
290 if (code == null) return null; | 290 if (code == null) return null; |
291 | 291 |
292 js.Name name = namer.globalPropertyName(element); | 292 js.Name name = namer.globalPropertyName(element); |
293 bool isFinal = element.isFinal; | 293 bool isFinal = element.isFinal; |
294 bool isLazy = true; | 294 bool isLazy = true; |
295 // TODO(floitsch): we shouldn't update the registry in the middle of | 295 // TODO(floitsch): we shouldn't update the registry in the middle of |
296 // building a static field. (Note that the $ holder is already registered | 296 // building a static field. (Note that the $ holder is already registered |
Siggi Cherem (dart-lang)
2015/07/17 16:04:04
ditto
floitsch
2015/07/17 17:27:18
Done.
| |
297 // earlier). | 297 // earlier). |
298 return new StaticField(element, | 298 return new StaticField(element, |
299 name, _registry.registerHolder(r'$'), code, | 299 name, _registerStaticStateHolder(), code, |
300 isFinal, isLazy); | 300 isFinal, isLazy); |
301 } | 301 } |
302 | 302 |
303 List<Library> _buildLibraries(LibrariesMap librariesMap) { | 303 List<Library> _buildLibraries(LibrariesMap librariesMap) { |
304 List<Library> libraries = new List<Library>(librariesMap.length); | 304 List<Library> libraries = new List<Library>(librariesMap.length); |
305 int count = 0; | 305 int count = 0; |
306 librariesMap.forEach((LibraryElement library, List<Element> elements) { | 306 librariesMap.forEach((LibraryElement library, List<Element> elements) { |
307 libraries[count++] = _buildLibrary(library, elements); | 307 libraries[count++] = _buildLibrary(library, elements); |
308 }); | 308 }); |
309 return libraries; | 309 return libraries; |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 | 786 |
787 void _registerConstants(OutputUnit outputUnit, | 787 void _registerConstants(OutputUnit outputUnit, |
788 Iterable<ConstantValue> constantValues) { | 788 Iterable<ConstantValue> constantValues) { |
789 // `constantValues` is null if an outputUnit doesn't contain any constants. | 789 // `constantValues` is null if an outputUnit doesn't contain any constants. |
790 if (constantValues == null) return; | 790 if (constantValues == null) return; |
791 for (ConstantValue constantValue in constantValues) { | 791 for (ConstantValue constantValue in constantValues) { |
792 _registry.registerConstant(outputUnit, constantValue); | 792 _registry.registerConstant(outputUnit, constantValue); |
793 assert(!_constants.containsKey(constantValue)); | 793 assert(!_constants.containsKey(constantValue)); |
794 js.Name name = namer.constantName(constantValue); | 794 js.Name name = namer.constantName(constantValue); |
795 String constantObject = namer.globalObjectForConstant(constantValue); | 795 String constantObject = namer.globalObjectForConstant(constantValue); |
796 Holder holder = _registry.registerHolder(constantObject); | 796 Holder holder = |
797 _registry.registerHolder(constantObject, isConstantsHolder: true); | |
797 Constant constant = new Constant(name, holder, constantValue); | 798 Constant constant = new Constant(name, holder, constantValue); |
798 _constants[constantValue] = constant; | 799 _constants[constantValue] = constant; |
799 } | 800 } |
800 } | 801 } |
802 | |
803 Holder _registerStaticStateHolder() { | |
804 return _registry.registerHolder( | |
805 namer.staticStateHolder, isStaticStateHolder: true); | |
806 } | |
801 } | 807 } |
OLD | NEW |