| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of dart2js.js_emitter.program_builder; | 5 part of dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Generates the code for all used classes in the program. Static fields (even | 8 * Generates the code for all used classes in the program. Static fields (even |
| 9 * in classes) are ignored, since they can be treated as non-class elements. | 9 * in classes) are ignored, since they can be treated as non-class elements. |
| 10 * | 10 * |
| 11 * The code for the containing (used) methods must exist in the `universe`. | 11 * The code for the containing (used) methods must exist in the `universe`. |
| 12 */ | 12 */ |
| 13 class Collector { | 13 class Collector { |
| 14 final CompilerOptions _options; | 14 final CompilerOptions _options; |
| 15 final CommonElements _commonElements; | 15 final CommonElements _commonElements; |
| 16 final ElementEnvironment _elementEnvironment; |
| 16 final DeferredLoadTask _deferredLoadTask; | 17 final DeferredLoadTask _deferredLoadTask; |
| 17 final CodegenWorldBuilder _worldBuilder; | 18 final CodegenWorldBuilder _worldBuilder; |
| 18 // TODO(floitsch): the code-emitter task should not need a namer. | 19 // TODO(floitsch): the code-emitter task should not need a namer. |
| 19 final Namer _namer; | 20 final Namer _namer; |
| 20 final Emitter _emitter; | 21 final Emitter _emitter; |
| 21 final JavaScriptConstantCompiler _constantHandler; | 22 final JavaScriptConstantCompiler _constantHandler; |
| 22 final NativeData _nativeData; | 23 final NativeData _nativeData; |
| 23 final InterceptorData _interceptorData; | 24 final InterceptorData _interceptorData; |
| 24 final OneShotInterceptorData _oneShotInterceptorData; | 25 final OneShotInterceptorData _oneShotInterceptorData; |
| 25 final MirrorsData _mirrorsData; | 26 final MirrorsData _mirrorsData; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 /// This flag is updated in [computeNeededConstants]. | 48 /// This flag is updated in [computeNeededConstants]. |
| 48 bool outputContainsConstantList = false; | 49 bool outputContainsConstantList = false; |
| 49 | 50 |
| 50 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; | 51 final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[]; |
| 51 | 52 |
| 52 List<TypedefElement> typedefsNeededForReflection; | 53 List<TypedefElement> typedefsNeededForReflection; |
| 53 | 54 |
| 54 Collector( | 55 Collector( |
| 55 this._options, | 56 this._options, |
| 56 this._commonElements, | 57 this._commonElements, |
| 58 this._elementEnvironment, |
| 57 this._deferredLoadTask, | 59 this._deferredLoadTask, |
| 58 this._worldBuilder, | 60 this._worldBuilder, |
| 59 this._namer, | 61 this._namer, |
| 60 this._emitter, | 62 this._emitter, |
| 61 this._constantHandler, | 63 this._constantHandler, |
| 62 this._nativeData, | 64 this._nativeData, |
| 63 this._interceptorData, | 65 this._interceptorData, |
| 64 this._oneShotInterceptorData, | 66 this._oneShotInterceptorData, |
| 65 this._mirrorsData, | 67 this._mirrorsData, |
| 66 this._closedWorld, | 68 this._closedWorld, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 MethodElement function = element; | 148 MethodElement function = element; |
| 147 function.functionSignature | 149 function.functionSignature |
| 148 .forEachParameter(_mirrorsData.retainMetadataOfParameter); | 150 .forEachParameter(_mirrorsData.retainMetadataOfParameter); |
| 149 } | 151 } |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 for (ClassElement cls in neededClasses) { | 154 for (ClassElement cls in neededClasses) { |
| 153 final onlyForRti = classesOnlyNeededForRti.contains(cls); | 155 final onlyForRti = classesOnlyNeededForRti.contains(cls); |
| 154 if (!onlyForRti) { | 156 if (!onlyForRti) { |
| 155 _mirrorsData.retainMetadataOfClass(cls); | 157 _mirrorsData.retainMetadataOfClass(cls); |
| 156 new FieldVisitor(_options, _worldBuilder, _nativeData, _mirrorsData, | 158 new FieldVisitor(_options, _elementEnvironment, _worldBuilder, |
| 157 _namer, _closedWorld) | 159 _nativeData, _mirrorsData, _namer, _closedWorld) |
| 158 .visitFields(cls, false, (FieldElement member, | 160 .visitFields((FieldElement member, |
| 159 js.Name name, | 161 js.Name name, |
| 160 js.Name accessorName, | 162 js.Name accessorName, |
| 161 bool needsGetter, | 163 bool needsGetter, |
| 162 bool needsSetter, | 164 bool needsSetter, |
| 163 bool needsCheckedSetter) { | 165 bool needsCheckedSetter) { |
| 164 bool needsAccessor = needsGetter || needsSetter; | 166 bool needsAccessor = needsGetter || needsSetter; |
| 165 if (needsAccessor && | 167 if (needsAccessor && |
| 166 _mirrorsData.isMemberAccessibleByReflection(member)) { | 168 _mirrorsData.isMemberAccessibleByReflection(member)) { |
| 167 _mirrorsData.retainMetadataOfMember(member); | 169 _mirrorsData.retainMetadataOfMember(member); |
| 168 } | 170 } |
| 169 }); | 171 }, cls: cls); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 typedefsNeededForReflection.forEach(_mirrorsData.retainMetadataOfTypedef); | 174 typedefsNeededForReflection.forEach(_mirrorsData.retainMetadataOfTypedef); |
| 173 } | 175 } |
| 174 | 176 |
| 175 JavaScriptConstantCompiler handler = _constantHandler; | 177 JavaScriptConstantCompiler handler = _constantHandler; |
| 176 List<ConstantValue> constants = | 178 List<ConstantValue> constants = |
| 177 handler.getConstantsForEmission(_emitter.compareConstants); | 179 handler.getConstantsForEmission(_emitter.compareConstants); |
| 178 for (ConstantValue constant in constants) { | 180 for (ConstantValue constant in constants) { |
| 179 if (_emitter.isConstantInlinedOrAlreadyEmitted(constant)) continue; | 181 if (_emitter.isConstantInlinedOrAlreadyEmitted(constant)) continue; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 357 } |
| 356 | 358 |
| 357 void collect() { | 359 void collect() { |
| 358 computeNeededDeclarations(); | 360 computeNeededDeclarations(); |
| 359 computeNeededConstants(); | 361 computeNeededConstants(); |
| 360 computeNeededStatics(); | 362 computeNeededStatics(); |
| 361 computeNeededStaticNonFinalFields(); | 363 computeNeededStaticNonFinalFields(); |
| 362 computeNeededLibraries(); | 364 computeNeededLibraries(); |
| 363 } | 365 } |
| 364 } | 366 } |
| OLD | NEW |