| 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 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:convert' show JSON; | 8 import 'dart:convert' show JSON; |
| 9 | 9 |
| 10 import '../../closure.dart' show ClosureConversionTask, ClosureFieldElement; | 10 import '../../closure.dart' show ClosureConversionTask, ClosureFieldElement; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 final RuntimeTypesEncoder _rtiEncoder; | 94 final RuntimeTypesEncoder _rtiEncoder; |
| 95 final RuntimeTypesSubstitutions _rtiSubstitutions; | 95 final RuntimeTypesSubstitutions _rtiSubstitutions; |
| 96 final JsInteropAnalysis _jsInteropAnalysis; | 96 final JsInteropAnalysis _jsInteropAnalysis; |
| 97 final OneShotInterceptorData _oneShotInterceptorData; | 97 final OneShotInterceptorData _oneShotInterceptorData; |
| 98 final CustomElementsCodegenAnalysis _customElementsCodegenAnalysis; | 98 final CustomElementsCodegenAnalysis _customElementsCodegenAnalysis; |
| 99 final Map<MemberEntity, js.Expression> _generatedCode; | 99 final Map<MemberEntity, js.Expression> _generatedCode; |
| 100 final Namer _namer; | 100 final Namer _namer; |
| 101 final CodeEmitterTask _task; | 101 final CodeEmitterTask _task; |
| 102 final ClosedWorld _closedWorld; | 102 final ClosedWorld _closedWorld; |
| 103 | 103 |
| 104 /// The [Sorter] used for ordering elements in the generated JavaScript. |
| 105 final Sorter _sorter; |
| 106 |
| 104 /// Contains the collected information the program builder used to build | 107 /// Contains the collected information the program builder used to build |
| 105 /// the model. | 108 /// the model. |
| 106 // The collector will be filled on the first call to `buildProgram`. | 109 // The collector will be filled on the first call to `buildProgram`. |
| 107 // It is stored and publicly exposed for backwards compatibility. New code | 110 // It is stored and publicly exposed for backwards compatibility. New code |
| 108 // (and in particular new emitters) should not use it. | 111 // (and in particular new emitters) should not use it. |
| 109 final Collector collector; | 112 final Collector collector; |
| 110 | 113 |
| 111 final Registry _registry; | 114 final Registry _registry; |
| 112 | 115 |
| 113 final FunctionEntity _mainFunction; | 116 final FunctionEntity _mainFunction; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 136 this._rtiChecks, | 139 this._rtiChecks, |
| 137 this._rtiEncoder, | 140 this._rtiEncoder, |
| 138 this._rtiSubstitutions, | 141 this._rtiSubstitutions, |
| 139 this._jsInteropAnalysis, | 142 this._jsInteropAnalysis, |
| 140 this._oneShotInterceptorData, | 143 this._oneShotInterceptorData, |
| 141 this._customElementsCodegenAnalysis, | 144 this._customElementsCodegenAnalysis, |
| 142 this._generatedCode, | 145 this._generatedCode, |
| 143 this._namer, | 146 this._namer, |
| 144 this._task, | 147 this._task, |
| 145 this._closedWorld, | 148 this._closedWorld, |
| 149 this._sorter, |
| 146 Set<ClassEntity> rtiNeededClasses, | 150 Set<ClassEntity> rtiNeededClasses, |
| 147 this._mainFunction, | 151 this._mainFunction, |
| 148 {bool isMockCompilation}) | 152 {bool isMockCompilation}) |
| 149 : this._isMockCompilation = isMockCompilation, | 153 : this._isMockCompilation = isMockCompilation, |
| 150 this.collector = new Collector( | 154 this.collector = new Collector( |
| 151 _options, | 155 _options, |
| 152 _commonElements, | 156 _commonElements, |
| 153 _elementEnvironment, | 157 _elementEnvironment, |
| 154 _deferredLoadTask, | 158 _deferredLoadTask, |
| 155 _worldBuilder, | 159 _worldBuilder, |
| 156 _namer, | 160 _namer, |
| 157 _task.emitter, | 161 _task.emitter, |
| 158 _constantHandler, | 162 _constantHandler, |
| 159 _nativeData, | 163 _nativeData, |
| 160 _interceptorData, | 164 _interceptorData, |
| 161 _oneShotInterceptorData, | 165 _oneShotInterceptorData, |
| 162 _mirrorsData, | 166 _mirrorsData, |
| 163 _closedWorld, | 167 _closedWorld, |
| 164 rtiNeededClasses, | 168 rtiNeededClasses, |
| 165 _generatedCode, | 169 _generatedCode, |
| 166 _task.sorter), | 170 _sorter), |
| 167 this._registry = new Registry(_deferredLoadTask, _task.sorter); | 171 this._registry = new Registry(_deferredLoadTask, _sorter); |
| 168 | 172 |
| 169 /// Mapping from [ClassEntity] to constructed [Class]. We need this to | 173 /// Mapping from [ClassEntity] to constructed [Class]. We need this to |
| 170 /// update the superclass in the [Class]. | 174 /// update the superclass in the [Class]. |
| 171 final Map<ClassEntity, Class> _classes = <ClassEntity, Class>{}; | 175 final Map<ClassEntity, Class> _classes = <ClassEntity, Class>{}; |
| 172 | 176 |
| 173 /// Mapping from [OutputUnit] to constructed [Fragment]. We need this to | 177 /// Mapping from [OutputUnit] to constructed [Fragment]. We need this to |
| 174 /// generate the deferredLoadingMap (to know which hunks to load). | 178 /// generate the deferredLoadingMap (to know which hunks to load). |
| 175 final Map<OutputUnit, Fragment> _outputs = <OutputUnit, Fragment>{}; | 179 final Map<OutputUnit, Fragment> _outputs = <OutputUnit, Fragment>{}; |
| 176 | 180 |
| 177 /// Mapping from [ConstantValue] to constructed [Constant]. We need this to | 181 /// Mapping from [ConstantValue] to constructed [Constant]. We need this to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 Set<Class> _unneededNativeClasses; | 192 Set<Class> _unneededNativeClasses; |
| 189 | 193 |
| 190 /// Classes that have been allocated during a profile run. | 194 /// Classes that have been allocated during a profile run. |
| 191 /// | 195 /// |
| 192 /// These classes should not be soft-deferred. | 196 /// These classes should not be soft-deferred. |
| 193 /// | 197 /// |
| 194 /// Also contains classes that are not tracked by the profile run (like | 198 /// Also contains classes that are not tracked by the profile run (like |
| 195 /// interceptors, ...). | 199 /// interceptors, ...). |
| 196 Set<ClassElement> _notSoftDeferred; | 200 Set<ClassElement> _notSoftDeferred; |
| 197 | 201 |
| 198 Sorter get _sorter => _task.sorter; | |
| 199 | |
| 200 Program buildProgram({bool storeFunctionTypesInMetadata: false}) { | 202 Program buildProgram({bool storeFunctionTypesInMetadata: false}) { |
| 201 collector.collect(); | 203 collector.collect(); |
| 202 _initializeSoftDeferredMap(); | 204 _initializeSoftDeferredMap(); |
| 203 | 205 |
| 204 this._storeFunctionTypesInMetadata = storeFunctionTypesInMetadata; | 206 this._storeFunctionTypesInMetadata = storeFunctionTypesInMetadata; |
| 205 // Note: In rare cases (mostly tests) output units can be empty. This | 207 // Note: In rare cases (mostly tests) output units can be empty. This |
| 206 // happens when the deferred code is dead-code eliminated but we still need | 208 // happens when the deferred code is dead-code eliminated but we still need |
| 207 // to check that the library has been loaded. | 209 // to check that the library has been loaded. |
| 208 _deferredLoadTask.allOutputUnits.forEach(_registry.registerOutputUnit); | 210 _deferredLoadTask.allOutputUnits.forEach(_registry.registerOutputUnit); |
| 209 collector.outputClassLists.forEach(_registry.registerClasses); | 211 collector.outputClassLists.forEach(_registry.registerClasses); |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 Constant constant = new Constant(name, holder, constantValue); | 1195 Constant constant = new Constant(name, holder, constantValue); |
| 1194 _constants[constantValue] = constant; | 1196 _constants[constantValue] = constant; |
| 1195 } | 1197 } |
| 1196 } | 1198 } |
| 1197 | 1199 |
| 1198 Holder _registerStaticStateHolder() { | 1200 Holder _registerStaticStateHolder() { |
| 1199 return _registry.registerHolder(_namer.staticStateHolder, | 1201 return _registry.registerHolder(_namer.staticStateHolder, |
| 1200 isStaticStateHolder: true); | 1202 isStaticStateHolder: true); |
| 1201 } | 1203 } |
| 1202 } | 1204 } |
| OLD | NEW |