| 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.new_js_emitter.model; | 5 library dart2js.new_js_emitter.model; |
| 6 | 6 |
| 7 import '../js/js.dart' as js show Expression; | 7 import '../js/js.dart' as js show Expression; |
| 8 import '../constants/values.dart' show ConstantValue; | 8 import '../constants/values.dart' show ConstantValue; |
| 9 | 9 |
| 10 import '../deferred_load.dart' show OutputUnit; |
| 11 |
| 10 import '../common.dart'; | 12 import '../common.dart'; |
| 11 | 13 |
| 12 class Program { | 14 class Program { |
| 13 final List<Fragment> fragments; | 15 final List<Fragment> fragments; |
| 14 final bool outputContainsConstantList; | 16 final bool outputContainsConstantList; |
| 15 /// A map from load id to the list of fragments that need to be loaded. | 17 /// A map from load id to the list of fragments that need to be loaded. |
| 16 final Map<String, List<Fragment>> loadMap; | 18 final Map<String, List<Fragment>> loadMap; |
| 17 | 19 |
| 18 Program(this.fragments, this.outputContainsConstantList, this.loadMap); | 20 Program(this.fragments, this.outputContainsConstantList, this.loadMap); |
| 19 } | 21 } |
| 20 | 22 |
| 21 /** | 23 /** |
| 22 * This class represents a JavaScript object that contains static state, like | 24 * This class represents a JavaScript object that contains static state, like |
| 23 * classes or functions. | 25 * classes or functions. |
| 24 */ | 26 */ |
| 25 class Holder { | 27 class Holder { |
| 26 final String name; | 28 final String name; |
| 27 final int index; | 29 final int index; |
| 28 Holder(this.name, this.index); | 30 Holder(this.name, this.index); |
| 29 } | 31 } |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * This class represents one output file. | 34 * This class represents one output file. |
| 33 * | 35 * |
| 34 * If no library is deferred, there is only one [Fragment] of type | 36 * If no library is deferred, there is only one [Fragment] of type |
| 35 * [MainFragment]. | 37 * [MainFragment]. |
| 36 */ | 38 */ |
| 37 abstract class Fragment { | 39 abstract class Fragment { |
| 38 bool get isMainFragment => mainFragment == this; | 40 /// The outputUnit should only be used during the transition to the new model. |
| 39 MainFragment get mainFragment; | 41 /// Uses indicate missing information in the model. |
| 42 final OutputUnit outputUnit; |
| 43 |
| 40 final List<Library> libraries; | 44 final List<Library> libraries; |
| 41 final List<Constant> constants; | 45 final List<Constant> constants; |
| 42 // TODO(floitsch): should we move static fields into libraries or classes? | 46 // TODO(floitsch): should we move static fields into libraries or classes? |
| 43 final List<StaticField> staticNonFinalFields; | 47 final List<StaticField> staticNonFinalFields; |
| 44 // TODO(floitsch): lazy fields should be in their library or even class. | 48 // TODO(floitsch): lazy fields should be in their library or even class. |
| 45 final List<StaticField> staticLazilyInitializedFields; | 49 final List<StaticField> staticLazilyInitializedFields; |
| 46 | 50 |
| 47 /// Output file name without extension. | 51 /// Output file name without extension. |
| 48 final String outputFileName; | 52 final String outputFileName; |
| 49 | 53 |
| 50 Fragment(this.outputFileName, | 54 Fragment(this.outputUnit, |
| 55 this.outputFileName, |
| 51 this.libraries, | 56 this.libraries, |
| 52 this.staticNonFinalFields, | 57 this.staticNonFinalFields, |
| 53 this.staticLazilyInitializedFields, | 58 this.staticLazilyInitializedFields, |
| 54 this.constants); | 59 this.constants); |
| 60 |
| 61 bool get isMainFragment => mainFragment == this; |
| 62 MainFragment get mainFragment; |
| 55 } | 63 } |
| 56 | 64 |
| 57 /** | 65 /** |
| 58 * The main output file. | 66 * The main output file. |
| 59 * | 67 * |
| 60 * This code emitted from this [Fragment] must be loaded first. It can then load | 68 * This code emitted from this [Fragment] must be loaded first. It can then load |
| 61 * other [DeferredFragment]s. | 69 * other [DeferredFragment]s. |
| 62 */ | 70 */ |
| 63 class MainFragment extends Fragment { | 71 class MainFragment extends Fragment { |
| 64 final js.Expression main; | 72 final js.Expression main; |
| 65 final List<Holder> holders; | 73 final List<Holder> holders; |
| 66 | 74 |
| 67 MainFragment(String outputFileName, | 75 MainFragment(OutputUnit outputUnit, |
| 76 String outputFileName, |
| 68 this.main, | 77 this.main, |
| 69 List<Library> libraries, | 78 List<Library> libraries, |
| 70 List<StaticField> staticNonFinalFields, | 79 List<StaticField> staticNonFinalFields, |
| 71 List<StaticField> staticLazilyInitializedFields, | 80 List<StaticField> staticLazilyInitializedFields, |
| 72 List<Constant> constants, | 81 List<Constant> constants, |
| 73 this.holders) | 82 this.holders) |
| 74 : super(outputFileName, | 83 : super(outputUnit, |
| 84 outputFileName, |
| 75 libraries, | 85 libraries, |
| 76 staticNonFinalFields, | 86 staticNonFinalFields, |
| 77 staticLazilyInitializedFields, | 87 staticLazilyInitializedFields, |
| 78 constants); | 88 constants); |
| 79 | 89 |
| 80 MainFragment get mainFragment => this; | 90 MainFragment get mainFragment => this; |
| 81 } | 91 } |
| 82 | 92 |
| 83 /** | 93 /** |
| 84 * An output (file) for deferred code. | 94 * An output (file) for deferred code. |
| 85 */ | 95 */ |
| 86 class DeferredFragment extends Fragment { | 96 class DeferredFragment extends Fragment { |
| 87 final MainFragment mainFragment; | 97 final MainFragment mainFragment; |
| 88 final String name; | 98 final String name; |
| 89 | 99 |
| 90 List<Holder> get holders => mainFragment.holders; | 100 List<Holder> get holders => mainFragment.holders; |
| 91 | 101 |
| 92 DeferredFragment(String outputFileName, | 102 DeferredFragment(OutputUnit outputUnit, |
| 103 String outputFileName, |
| 93 this.name, | 104 this.name, |
| 94 this.mainFragment, | 105 this.mainFragment, |
| 95 List<Library> libraries, | 106 List<Library> libraries, |
| 96 List<StaticField> staticNonFinalFields, | 107 List<StaticField> staticNonFinalFields, |
| 97 List<StaticField> staticLazilyInitializedFields, | 108 List<StaticField> staticLazilyInitializedFields, |
| 98 List<Constant> constants) | 109 List<Constant> constants) |
| 99 : super(outputFileName, | 110 : super(outputUnit, |
| 111 outputFileName, |
| 100 libraries, | 112 libraries, |
| 101 staticNonFinalFields, | 113 staticNonFinalFields, |
| 102 staticLazilyInitializedFields, | 114 staticLazilyInitializedFields, |
| 103 constants); | 115 constants); |
| 104 } | 116 } |
| 105 | 117 |
| 106 class Constant { | 118 class Constant { |
| 107 final String name; | 119 final String name; |
| 108 final Holder holder; | 120 final Holder holder; |
| 109 final ConstantValue value; | 121 final ConstantValue value; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 class StaticMethod extends Method { | 255 class StaticMethod extends Method { |
| 244 final Holder holder; | 256 final Holder holder; |
| 245 StaticMethod(Element element, String name, this.holder, js.Expression code) | 257 StaticMethod(Element element, String name, this.holder, js.Expression code) |
| 246 : super(element, name, code); | 258 : super(element, name, code); |
| 247 } | 259 } |
| 248 | 260 |
| 249 class StaticStubMethod extends StaticMethod { | 261 class StaticStubMethod extends StaticMethod { |
| 250 StaticStubMethod(String name, Holder holder, js.Expression code) | 262 StaticStubMethod(String name, Holder holder, js.Expression code) |
| 251 : super(null, name, holder, code); | 263 : super(null, name, holder, code); |
| 252 } | 264 } |
| OLD | NEW |