OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import '../closure.dart'; | 5 import '../closure.dart'; |
6 import '../common.dart'; | 6 import '../common.dart'; |
7 import '../common_elements.dart'; | 7 import '../common_elements.dart'; |
8 import '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
11 import '../elements/entities.dart'; | 11 import '../elements/entities.dart'; |
12 import '../elements/types.dart'; | 12 import '../elements/types.dart'; |
13 import '../options.dart'; | 13 import '../options.dart'; |
14 import '../world.dart'; | 14 import '../world.dart'; |
15 import '../universe/world_builder.dart'; | 15 import '../universe/world_builder.dart'; |
16 import '../util/emptyset.dart'; | 16 import '../util/emptyset.dart'; |
17 import 'backend_helpers.dart'; | |
18 import 'constant_handler_javascript.dart'; | 17 import 'constant_handler_javascript.dart'; |
19 | 18 |
20 abstract class MirrorsData { | 19 abstract class MirrorsData { |
21 /// True if a call to preserveMetadataMarker has been seen. This means that | 20 /// True if a call to preserveMetadataMarker has been seen. This means that |
22 /// metadata must be retained for dart:mirrors to work correctly. | 21 /// metadata must be retained for dart:mirrors to work correctly. |
23 // resolution-empty-queue | 22 // resolution-empty-queue |
24 bool get mustRetainMetadata; | 23 bool get mustRetainMetadata; |
25 | 24 |
26 /// True if any metadata has been retained. This is slightly different from | 25 /// True if any metadata has been retained. This is slightly different from |
27 /// [mustRetainMetadata] and tells us if any metadata was retained. For | 26 /// [mustRetainMetadata] and tells us if any metadata was retained. For |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 /// element must be retained. | 200 /// element must be retained. |
202 final Set<ClassEntity> metaTargetsUsed = new Set<ClassEntity>(); | 201 final Set<ClassEntity> metaTargetsUsed = new Set<ClassEntity>(); |
203 | 202 |
204 // TODO(johnniwinther): Avoid the need for this. | 203 // TODO(johnniwinther): Avoid the need for this. |
205 final Compiler _compiler; | 204 final Compiler _compiler; |
206 | 205 |
207 final CompilerOptions _options; | 206 final CompilerOptions _options; |
208 | 207 |
209 final CommonElements _commonElements; | 208 final CommonElements _commonElements; |
210 | 209 |
211 final BackendHelpers _helpers; | |
212 | |
213 final JavaScriptConstantCompiler _constants; | 210 final JavaScriptConstantCompiler _constants; |
214 | 211 |
215 MirrorsDataImpl(this._compiler, this._options, this._commonElements, | 212 MirrorsDataImpl( |
216 this._helpers, this._constants); | 213 this._compiler, this._options, this._commonElements, this._constants); |
217 | 214 |
218 void registerUsedMember(MemberElement member) { | 215 void registerUsedMember(MemberElement member) { |
219 if (member == _helpers.disableTreeShakingMarker) { | 216 if (member == _commonElements.disableTreeShakingMarker) { |
220 isTreeShakingDisabled = true; | 217 isTreeShakingDisabled = true; |
221 } else if (member == _helpers.preserveNamesMarker) { | 218 } else if (member == _commonElements.preserveNamesMarker) { |
222 mustPreserveNames = true; | 219 mustPreserveNames = true; |
223 } else if (member == _helpers.preserveMetadataMarker) { | 220 } else if (member == _commonElements.preserveMetadataMarker) { |
224 mustRetainMetadata = true; | 221 mustRetainMetadata = true; |
225 } else if (member == _helpers.preserveUrisMarker) { | 222 } else if (member == _commonElements.preserveUrisMarker) { |
226 if (_options.preserveUris) mustPreserveUris = true; | 223 if (_options.preserveUris) mustPreserveUris = true; |
227 } else if (member == _helpers.preserveLibraryNamesMarker) { | 224 } else if (member == _commonElements.preserveLibraryNamesMarker) { |
228 mustRetainLibraryNames = true; | 225 mustRetainLibraryNames = true; |
229 } | 226 } |
230 } | 227 } |
231 | 228 |
232 bool shouldRetainGetter(FieldElement element) { | 229 bool shouldRetainGetter(FieldElement element) { |
233 return isTreeShakingDisabled && isMemberAccessibleByReflection(element); | 230 return isTreeShakingDisabled && isMemberAccessibleByReflection(element); |
234 } | 231 } |
235 | 232 |
236 bool shouldRetainSetter(FieldElement element) { | 233 bool shouldRetainSetter(FieldElement element) { |
237 return isTreeShakingDisabled && isMemberAccessibleByReflection(element); | 234 return isTreeShakingDisabled && isMemberAccessibleByReflection(element); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 } else if (element.isClass) { | 391 } else if (element.isClass) { |
395 return isClassAccessibleByReflection(element); | 392 return isClassAccessibleByReflection(element); |
396 } else if (element.isTypedef) { | 393 } else if (element.isTypedef) { |
397 return isTypedefAccessibleByReflection(element); | 394 return isTypedefAccessibleByReflection(element); |
398 } else { | 395 } else { |
399 return isMemberAccessibleByReflection(element); | 396 return isMemberAccessibleByReflection(element); |
400 } | 397 } |
401 } | 398 } |
402 | 399 |
403 ClassElement _getDartClass(ClassElement cls) { | 400 ClassElement _getDartClass(ClassElement cls) { |
404 if (cls == _helpers.jsIntClass) { | 401 if (cls == _commonElements.jsIntClass) { |
405 return _commonElements.intClass; | 402 return _commonElements.intClass; |
406 } else if (cls == _helpers.jsBoolClass) { | 403 } else if (cls == _commonElements.jsBoolClass) { |
407 return _commonElements.boolClass; | 404 return _commonElements.boolClass; |
408 } else if (cls == _helpers.jsNumberClass) { | 405 } else if (cls == _commonElements.jsNumberClass) { |
409 return _commonElements.numClass; | 406 return _commonElements.numClass; |
410 } else if (cls == _helpers.jsDoubleClass) { | 407 } else if (cls == _commonElements.jsDoubleClass) { |
411 return _commonElements.doubleClass; | 408 return _commonElements.doubleClass; |
412 } else if (cls == _helpers.jsStringClass) { | 409 } else if (cls == _commonElements.jsStringClass) { |
413 return _commonElements.stringClass; | 410 return _commonElements.stringClass; |
414 } else if (cls == _helpers.jsArrayClass) { | 411 } else if (cls == _commonElements.jsArrayClass) { |
415 return _commonElements.listClass; | 412 return _commonElements.listClass; |
416 } else if (cls == _helpers.jsNullClass) { | 413 } else if (cls == _commonElements.jsNullClass) { |
417 return _commonElements.nullClass; | 414 return _commonElements.nullClass; |
418 } else { | 415 } else { |
419 return cls; | 416 return cls; |
420 } | 417 } |
421 } | 418 } |
422 | 419 |
423 bool isMemberAccessibleByReflection(MemberElement element) { | 420 bool isMemberAccessibleByReflection(MemberElement element) { |
424 return _membersNeededForReflection.contains(element); | 421 return _membersNeededForReflection.contains(element); |
425 } | 422 } |
426 | 423 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 for (LocalFunctionElement closure in closureMap[null]) { | 645 for (LocalFunctionElement closure in closureMap[null]) { |
649 if (isMemberReferencedFromMirrorSystem(closure.memberContext)) { | 646 if (isMemberReferencedFromMirrorSystem(closure.memberContext)) { |
650 _closuresNeededForReflection.add(closure); | 647 _closuresNeededForReflection.add(closure); |
651 foundClosure = true; | 648 foundClosure = true; |
652 } | 649 } |
653 } | 650 } |
654 } | 651 } |
655 // As we do not think about closures as classes, yet, we have to make sure | 652 // As we do not think about closures as classes, yet, we have to make sure |
656 // their superclasses are available for reflection manually. | 653 // their superclasses are available for reflection manually. |
657 if (foundClosure) { | 654 if (foundClosure) { |
658 ClassElement cls = _helpers.closureClass; | 655 ClassElement cls = _commonElements.closureClass; |
659 _classesNeededForReflection.add(cls); | 656 _classesNeededForReflection.add(cls); |
660 } | 657 } |
661 Set<FunctionEntity> closurizedMembers = worldBuilder.closurizedMembers; | 658 Set<FunctionEntity> closurizedMembers = worldBuilder.closurizedMembers; |
662 if (closurizedMembers.any(_membersNeededForReflection.contains)) { | 659 if (closurizedMembers.any(_membersNeededForReflection.contains)) { |
663 ClassElement cls = _helpers.boundClosureClass; | 660 ClassElement cls = _commonElements.boundClosureClass; |
664 _classesNeededForReflection.add(cls); | 661 _classesNeededForReflection.add(cls); |
665 } | 662 } |
666 // Add typedefs. | 663 // Add typedefs. |
667 _typedefsNeededForReflection.addAll( | 664 _typedefsNeededForReflection.addAll( |
668 closedWorld.allTypedefs.where(isTypedefReferencedFromMirrorSystem)); | 665 closedWorld.allTypedefs.where(isTypedefReferencedFromMirrorSystem)); |
669 // Register all symbols of reflectable elements | 666 // Register all symbols of reflectable elements |
670 for (ClassElement element in _classesNeededForReflection) { | 667 for (ClassElement element in _classesNeededForReflection) { |
671 symbolsUsed.add(element.name); | 668 symbolsUsed.add(element.name); |
672 } | 669 } |
673 for (TypedefElement element in _typedefsNeededForReflection) { | 670 for (TypedefElement element in _typedefsNeededForReflection) { |
(...skipping 19 matching lines...) Expand all Loading... |
693 } | 690 } |
694 | 691 |
695 /// Called when `const Symbol(name)` is seen. | 692 /// Called when `const Symbol(name)` is seen. |
696 void registerConstSymbol(String name) { | 693 void registerConstSymbol(String name) { |
697 symbolsUsed.add(name); | 694 symbolsUsed.add(name); |
698 if (name.endsWith('=')) { | 695 if (name.endsWith('=')) { |
699 symbolsUsed.add(name.substring(0, name.length - 1)); | 696 symbolsUsed.add(name.substring(0, name.length - 1)); |
700 } | 697 } |
701 } | 698 } |
702 } | 699 } |
OLD | NEW |