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