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 * |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // multiple times. | 138 // multiple times. |
139 for (MemberElement element in _generatedCode.keys) { | 139 for (MemberElement element in _generatedCode.keys) { |
140 if (_mirrorsData.isMemberAccessibleByReflection(element)) { | 140 if (_mirrorsData.isMemberAccessibleByReflection(element)) { |
141 bool shouldRetainMetadata = | 141 bool shouldRetainMetadata = |
142 _mirrorsData.retainMetadataOfMember(element); | 142 _mirrorsData.retainMetadataOfMember(element); |
143 if (shouldRetainMetadata && | 143 if (shouldRetainMetadata && |
144 (element.isFunction || | 144 (element.isFunction || |
145 element.isConstructor || | 145 element.isConstructor || |
146 element.isSetter)) { | 146 element.isSetter)) { |
147 MethodElement function = element; | 147 MethodElement function = element; |
148 function.functionSignature | 148 function.functionSignature.forEachParameter((parameter) => |
149 .forEachParameter(_mirrorsData.retainMetadataOfParameter); | 149 _mirrorsData.retainMetadataOfParameter(parameter)); |
150 } | 150 } |
151 } | 151 } |
152 } | 152 } |
153 for (ClassElement cls in neededClasses) { | 153 for (ClassElement cls in neededClasses) { |
154 final onlyForRti = classesOnlyNeededForRti.contains(cls); | 154 final onlyForRti = classesOnlyNeededForRti.contains(cls); |
155 if (!onlyForRti) { | 155 if (!onlyForRti) { |
156 _mirrorsData.retainMetadataOfClass(cls); | 156 _mirrorsData.retainMetadataOfClass(cls); |
157 new FieldVisitor(_options, _elementEnvironment, _worldBuilder, | 157 new FieldVisitor(_options, _elementEnvironment, _worldBuilder, |
158 _nativeData, _mirrorsData, _namer, _closedWorld) | 158 _nativeData, _mirrorsData, _namer, _closedWorld) |
159 .visitFields((FieldElement member, | 159 .visitFields((FieldEntity member, |
160 js.Name name, | 160 js.Name name, |
161 js.Name accessorName, | 161 js.Name accessorName, |
162 bool needsGetter, | 162 bool needsGetter, |
163 bool needsSetter, | 163 bool needsSetter, |
164 bool needsCheckedSetter) { | 164 bool needsCheckedSetter) { |
165 bool needsAccessor = needsGetter || needsSetter; | 165 bool needsAccessor = needsGetter || needsSetter; |
166 if (needsAccessor && | 166 if (needsAccessor && |
167 _mirrorsData.isMemberAccessibleByReflection(member)) { | 167 _mirrorsData.isMemberAccessibleByReflection(member)) { |
168 _mirrorsData.retainMetadataOfMember(member); | 168 _mirrorsData.retainMetadataOfMember(member); |
169 } | 169 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 !field.isInstanceMember && | 327 !field.isInstanceMember && |
328 !field.isFinal && | 328 !field.isFinal && |
329 field.constant != null; | 329 field.constant != null; |
330 } else { | 330 } else { |
331 // We also need to emit static const fields if they are available for | 331 // We also need to emit static const fields if they are available for |
332 // reflection. | 332 // reflection. |
333 return _mirrorsData.isMemberAccessibleByReflection(field); | 333 return _mirrorsData.isMemberAccessibleByReflection(field); |
334 } | 334 } |
335 }); | 335 }); |
336 | 336 |
337 _sorter.sortMembers(fields).forEach(addToOutputUnit); | 337 _sorter.sortMembers(fields).forEach((MemberEntity e) => addToOutputUnit(e)); |
338 } | 338 } |
339 | 339 |
340 void computeNeededLibraries() { | 340 void computeNeededLibraries() { |
341 _generatedCode.keys.forEach((MemberEntity element) { | 341 _generatedCode.keys.forEach((MemberEntity element) { |
342 OutputUnit unit = _deferredLoadTask.outputUnitForMember(element); | 342 OutputUnit unit = _deferredLoadTask.outputUnitForMember(element); |
343 LibraryEntity library = element.library; | 343 LibraryEntity library = element.library; |
344 outputLibraryLists | 344 outputLibraryLists |
345 .putIfAbsent(unit, () => new Set<LibraryEntity>()) | 345 .putIfAbsent(unit, () => new Set<LibraryEntity>()) |
346 .add(library); | 346 .add(library); |
347 }); | 347 }); |
348 neededClasses.forEach((ClassEntity element) { | 348 neededClasses.forEach((ClassEntity element) { |
349 OutputUnit unit = _deferredLoadTask.outputUnitForClass(element); | 349 OutputUnit unit = _deferredLoadTask.outputUnitForClass(element); |
350 LibraryEntity library = element.library; | 350 LibraryEntity library = element.library; |
351 outputLibraryLists | 351 outputLibraryLists |
352 .putIfAbsent(unit, () => new Set<LibraryEntity>()) | 352 .putIfAbsent(unit, () => new Set<LibraryEntity>()) |
353 .add(library); | 353 .add(library); |
354 }); | 354 }); |
355 } | 355 } |
356 | 356 |
357 void collect() { | 357 void collect() { |
358 computeNeededDeclarations(); | 358 computeNeededDeclarations(); |
359 computeNeededConstants(); | 359 computeNeededConstants(); |
360 computeNeededStatics(); | 360 computeNeededStatics(); |
361 computeNeededStaticNonFinalFields(); | 361 computeNeededStaticNonFinalFields(); |
362 computeNeededLibraries(); | 362 computeNeededLibraries(); |
363 } | 363 } |
364 } | 364 } |
OLD | NEW |