| 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 static-state holder was | 
|  262     // earlier). |  262     // already registered earlier, and that we just call the register to get | 
 |  263     // the holder-instance. | 
|  263     return new StaticField(element, |  264     return new StaticField(element, | 
|  264                            name, _registry.registerHolder(r'$'), code, |  265                            name, _registerStaticStateHolder(), code, | 
|  265                            isFinal, isLazy); |  266                            isFinal, isLazy); | 
|  266   } |  267   } | 
|  267  |  268  | 
|  268   List<StaticField> _buildStaticLazilyInitializedFields( |  269   List<StaticField> _buildStaticLazilyInitializedFields( | 
|  269       LibrariesMap librariesMap) { |  270       LibrariesMap librariesMap) { | 
|  270     // TODO(floitsch): lazy fields should just be in their respective |  271     // TODO(floitsch): lazy fields should just be in their respective | 
|  271     // libraries. |  272     // libraries. | 
|  272     if (librariesMap != _registry.mainLibrariesMap) { |  273     if (librariesMap != _registry.mainLibrariesMap) { | 
|  273       return const <StaticField>[]; |  274       return const <StaticField>[]; | 
|  274     } |  275     } | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  286     js.Expression code = backend.generatedCode[element]; |  287     js.Expression code = backend.generatedCode[element]; | 
|  287     // The code is null if we ended up not needing the lazily |  288     // The code is null if we ended up not needing the lazily | 
|  288     // initialized field after all because of constant folding |  289     // initialized field after all because of constant folding | 
|  289     // before code generation. |  290     // before code generation. | 
|  290     if (code == null) return null; |  291     if (code == null) return null; | 
|  291  |  292  | 
|  292     js.Name name = namer.globalPropertyName(element); |  293     js.Name name = namer.globalPropertyName(element); | 
|  293     bool isFinal = element.isFinal; |  294     bool isFinal = element.isFinal; | 
|  294     bool isLazy = true; |  295     bool isLazy = true; | 
|  295     // TODO(floitsch): we shouldn't update the registry in the middle of |  296     // TODO(floitsch): we shouldn't update the registry in the middle of | 
|  296     // building a static field. (Note that the $ holder is already registered |  297     // building a static field. (Note that the static-state holder was | 
|  297     // earlier). |  298     // already registered earlier, and that we just call the register to get | 
 |  299     // the holder-instance. | 
|  298     return new StaticField(element, |  300     return new StaticField(element, | 
|  299                            name, _registry.registerHolder(r'$'), code, |  301                            name, _registerStaticStateHolder(), code, | 
|  300                            isFinal, isLazy); |  302                            isFinal, isLazy); | 
|  301   } |  303   } | 
|  302  |  304  | 
|  303   List<Library> _buildLibraries(LibrariesMap librariesMap) { |  305   List<Library> _buildLibraries(LibrariesMap librariesMap) { | 
|  304     List<Library> libraries = new List<Library>(librariesMap.length); |  306     List<Library> libraries = new List<Library>(librariesMap.length); | 
|  305     int count = 0; |  307     int count = 0; | 
|  306     librariesMap.forEach((LibraryElement library, List<Element> elements) { |  308     librariesMap.forEach((LibraryElement library, List<Element> elements) { | 
|  307       libraries[count++] = _buildLibrary(library, elements); |  309       libraries[count++] = _buildLibrary(library, elements); | 
|  308     }); |  310     }); | 
|  309     return libraries; |  311     return libraries; | 
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  786  |  788  | 
|  787   void _registerConstants(OutputUnit outputUnit, |  789   void _registerConstants(OutputUnit outputUnit, | 
|  788                           Iterable<ConstantValue> constantValues) { |  790                           Iterable<ConstantValue> constantValues) { | 
|  789     // `constantValues` is null if an outputUnit doesn't contain any constants. |  791     // `constantValues` is null if an outputUnit doesn't contain any constants. | 
|  790     if (constantValues == null) return; |  792     if (constantValues == null) return; | 
|  791     for (ConstantValue constantValue in constantValues) { |  793     for (ConstantValue constantValue in constantValues) { | 
|  792       _registry.registerConstant(outputUnit, constantValue); |  794       _registry.registerConstant(outputUnit, constantValue); | 
|  793       assert(!_constants.containsKey(constantValue)); |  795       assert(!_constants.containsKey(constantValue)); | 
|  794       js.Name name = namer.constantName(constantValue); |  796       js.Name name = namer.constantName(constantValue); | 
|  795       String constantObject = namer.globalObjectForConstant(constantValue); |  797       String constantObject = namer.globalObjectForConstant(constantValue); | 
|  796       Holder holder = _registry.registerHolder(constantObject); |  798       Holder holder = | 
 |  799           _registry.registerHolder(constantObject, isConstantsHolder: true); | 
|  797       Constant constant = new Constant(name, holder, constantValue); |  800       Constant constant = new Constant(name, holder, constantValue); | 
|  798       _constants[constantValue] = constant; |  801       _constants[constantValue] = constant; | 
|  799     } |  802     } | 
|  800   } |  803   } | 
 |  804  | 
 |  805   Holder _registerStaticStateHolder() { | 
 |  806     return _registry.registerHolder( | 
 |  807         namer.staticStateHolder, isStaticStateHolder: true); | 
 |  808   } | 
|  801 } |  809 } | 
| OLD | NEW |