| 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'; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 /// annotation. | 93 /// annotation. |
| 94 bool isLibraryReferencedFromMirrorSystem(covariant LibraryEntity element); | 94 bool isLibraryReferencedFromMirrorSystem(covariant LibraryEntity element); |
| 95 | 95 |
| 96 /// Returns `true` if the typedef [element] needs reflection information at | 96 /// Returns `true` if the typedef [element] needs reflection information at |
| 97 /// runtime. | 97 /// runtime. |
| 98 /// | 98 /// |
| 99 /// This property is used to tag emitted elements with a marker which is | 99 /// This property is used to tag emitted elements with a marker which is |
| 100 /// checked by the runtime system to throw an exception if an element is | 100 /// checked by the runtime system to throw an exception if an element is |
| 101 /// accessed (invoked, get, set) that is not accessible for the reflective | 101 /// accessed (invoked, get, set) that is not accessible for the reflective |
| 102 /// system. | 102 /// system. |
| 103 bool isTypedefAccessibleByReflection(TypedefElement element); | 103 bool isTypedefAccessibleByReflection(covariant TypedefEntity element); |
| 104 | 104 |
| 105 /// Returns `true` if the class [element] needs reflection information at | 105 /// Returns `true` if the class [element] needs reflection information at |
| 106 /// runtime. | 106 /// runtime. |
| 107 /// | 107 /// |
| 108 /// This property is used to tag emitted elements with a marker which is | 108 /// This property is used to tag emitted elements with a marker which is |
| 109 /// checked by the runtime system to throw an exception if an element is | 109 /// checked by the runtime system to throw an exception if an element is |
| 110 /// accessed (invoked, get, set) that is not accessible for the reflective | 110 /// accessed (invoked, get, set) that is not accessible for the reflective |
| 111 /// system. | 111 /// system. |
| 112 bool isClassAccessibleByReflection(ClassEntity element); | 112 bool isClassAccessibleByReflection(ClassEntity element); |
| 113 | 113 |
| 114 /// Returns `true` if the member [element] needs reflection information at | 114 /// Returns `true` if the member [element] needs reflection information at |
| 115 /// runtime. | 115 /// runtime. |
| 116 /// | 116 /// |
| 117 /// This property is used to tag emitted elements with a marker which is | 117 /// This property is used to tag emitted elements with a marker which is |
| 118 /// checked by the runtime system to throw an exception if an element is | 118 /// checked by the runtime system to throw an exception if an element is |
| 119 /// accessed (invoked, get, set) that is not accessible for the reflective | 119 /// accessed (invoked, get, set) that is not accessible for the reflective |
| 120 /// system. | 120 /// system. |
| 121 bool isMemberAccessibleByReflection(MemberEntity element); | 121 bool isMemberAccessibleByReflection(MemberEntity element); |
| 122 | 122 |
| 123 // TODO(johnniwinther): Remove this. | 123 // TODO(johnniwinther): Remove this. |
| 124 @deprecated | 124 @deprecated |
| 125 bool isAccessibleByReflection(Element element); | 125 bool isAccessibleByReflection(Element element); |
| 126 | 126 |
| 127 bool retainMetadataOfLibrary(covariant LibraryEntity element, | 127 bool retainMetadataOfLibrary(covariant LibraryEntity element, |
| 128 {bool addForEmission: true}); | 128 {bool addForEmission: true}); |
| 129 bool retainMetadataOfTypedef(TypedefElement element); | 129 bool retainMetadataOfTypedef(covariant TypedefEntity element); |
| 130 bool retainMetadataOfClass(covariant ClassEntity element); | 130 bool retainMetadataOfClass(covariant ClassEntity element); |
| 131 bool retainMetadataOfMember(covariant MemberEntity element); | 131 bool retainMetadataOfMember(covariant MemberEntity element); |
| 132 bool retainMetadataOfParameter(ParameterElement element); | 132 bool retainMetadataOfParameter(ParameterElement element); |
| 133 | 133 |
| 134 /// Returns true if this element has to be enqueued due to | 134 /// Returns true if this element has to be enqueued due to |
| 135 /// mirror usage. Might be a subset of [referencedFromMirrorSystem] if | 135 /// mirror usage. Might be a subset of [referencedFromMirrorSystem] if |
| 136 /// normal tree shaking is still active ([isTreeShakingDisabled] is false). | 136 /// normal tree shaking is still active ([isTreeShakingDisabled] is false). |
| 137 bool requiredByMirrorSystem(Element element); | 137 bool requiredByMirrorSystem(Element element); |
| 138 } | 138 } |
| 139 | 139 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 bool mustPreserveUris = false; | 186 bool mustPreserveUris = false; |
| 187 | 187 |
| 188 /// Set of symbols that the user has requested for reflection. | 188 /// Set of symbols that the user has requested for reflection. |
| 189 final Set<String> symbolsUsed = new Set<String>(); | 189 final Set<String> symbolsUsed = new Set<String>(); |
| 190 | 190 |
| 191 /// Set of elements that the user has requested for reflection. | 191 /// Set of elements that the user has requested for reflection. |
| 192 final Set<MemberEntity> membersInMirrorsUsedTargets = new Set<MemberEntity>(); | 192 final Set<MemberEntity> membersInMirrorsUsedTargets = new Set<MemberEntity>(); |
| 193 final Set<ClassEntity> classesInMirrorsUsedTargets = new Set<ClassEntity>(); | 193 final Set<ClassEntity> classesInMirrorsUsedTargets = new Set<ClassEntity>(); |
| 194 final Set<LibraryEntity> librariesInMirrorsUsedTargets = | 194 final Set<LibraryEntity> librariesInMirrorsUsedTargets = |
| 195 new Set<LibraryEntity>(); | 195 new Set<LibraryEntity>(); |
| 196 final Set<TypedefElement> _typedefsInMirrorsUsedTargets = | 196 final Set<TypedefEntity> _typedefsInMirrorsUsedTargets = |
| 197 new Set<TypedefElement>(); | 197 new Set<TypedefEntity>(); |
| 198 | 198 |
| 199 /// List of annotations provided by user that indicate that the annotated | 199 /// List of annotations provided by user that indicate that the annotated |
| 200 /// element must be retained. | 200 /// element must be retained. |
| 201 final Set<ClassEntity> metaTargetsUsed = new Set<ClassEntity>(); | 201 final Set<ClassEntity> metaTargetsUsed = new Set<ClassEntity>(); |
| 202 | 202 |
| 203 // TODO(johnniwinther): Avoid the need for this. | 203 // TODO(johnniwinther): Avoid the need for this. |
| 204 final Compiler _compiler; | 204 final Compiler _compiler; |
| 205 | 205 |
| 206 final CompilerOptions _options; | 206 final CompilerOptions _options; |
| 207 | 207 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 AbstractFieldElement field = target; | 338 AbstractFieldElement field = target; |
| 339 if (field.getter != null) { | 339 if (field.getter != null) { |
| 340 membersInMirrorsUsedTargets.add(field.getter); | 340 membersInMirrorsUsedTargets.add(field.getter); |
| 341 } | 341 } |
| 342 if (field.setter != null) { | 342 if (field.setter != null) { |
| 343 membersInMirrorsUsedTargets.add(field.setter); | 343 membersInMirrorsUsedTargets.add(field.setter); |
| 344 } | 344 } |
| 345 } else if (target.isClass) { | 345 } else if (target.isClass) { |
| 346 classesInMirrorsUsedTargets.add(target as ClassEntity); | 346 classesInMirrorsUsedTargets.add(target as ClassEntity); |
| 347 } else if (target.isTypedef) { | 347 } else if (target.isTypedef) { |
| 348 _typedefsInMirrorsUsedTargets.add(target); | 348 _typedefsInMirrorsUsedTargets.add(target as TypedefEntity); |
| 349 } else if (target.isLibrary) { | 349 } else if (target.isLibrary) { |
| 350 librariesInMirrorsUsedTargets.add(target as LibraryEntity); | 350 librariesInMirrorsUsedTargets.add(target as LibraryEntity); |
| 351 } else if (target != null) { | 351 } else if (target != null) { |
| 352 membersInMirrorsUsedTargets.add(target as MemberEntity); | 352 membersInMirrorsUsedTargets.add(target as MemberEntity); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 if (metaTargets != null) { | 356 if (metaTargets != null) { |
| 357 for (dynamic element in metaTargets) { | 357 for (dynamic element in metaTargets) { |
| 358 if (element is ClassEntity) { | 358 if (element is ClassEntity) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 if (foundClosure) { | 650 if (foundClosure) { |
| 651 ClassElement cls = _commonElements.closureClass; | 651 ClassElement cls = _commonElements.closureClass; |
| 652 _classesNeededForReflection.add(cls); | 652 _classesNeededForReflection.add(cls); |
| 653 } | 653 } |
| 654 Set<FunctionEntity> closurizedMembers = worldBuilder.closurizedMembers; | 654 Set<FunctionEntity> closurizedMembers = worldBuilder.closurizedMembers; |
| 655 if (closurizedMembers.any(_membersNeededForReflection.contains)) { | 655 if (closurizedMembers.any(_membersNeededForReflection.contains)) { |
| 656 ClassElement cls = _commonElements.boundClosureClass; | 656 ClassElement cls = _commonElements.boundClosureClass; |
| 657 _classesNeededForReflection.add(cls); | 657 _classesNeededForReflection.add(cls); |
| 658 } | 658 } |
| 659 // Add typedefs. | 659 // Add typedefs. |
| 660 _typedefsNeededForReflection.addAll( | 660 for (TypedefElement element in closedWorld.allTypedefs) { |
| 661 closedWorld.allTypedefs.where(isTypedefReferencedFromMirrorSystem)); | 661 if (isTypedefReferencedFromMirrorSystem(element)) { |
| 662 _typedefsNeededForReflection.add(element); |
| 663 } |
| 664 } |
| 662 // Register all symbols of reflectable elements | 665 // Register all symbols of reflectable elements |
| 663 for (ClassElement element in _classesNeededForReflection) { | 666 for (ClassElement element in _classesNeededForReflection) { |
| 664 symbolsUsed.add(element.name); | 667 symbolsUsed.add(element.name); |
| 665 } | 668 } |
| 666 for (TypedefElement element in _typedefsNeededForReflection) { | 669 for (TypedefElement element in _typedefsNeededForReflection) { |
| 667 symbolsUsed.add(element.name); | 670 symbolsUsed.add(element.name); |
| 668 } | 671 } |
| 669 for (MemberElement element in _membersNeededForReflection) { | 672 for (MemberElement element in _membersNeededForReflection) { |
| 670 symbolsUsed.add(element.name); | 673 symbolsUsed.add(element.name); |
| 671 } | 674 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 686 } | 689 } |
| 687 | 690 |
| 688 /// Called when `const Symbol(name)` is seen. | 691 /// Called when `const Symbol(name)` is seen. |
| 689 void registerConstSymbol(String name) { | 692 void registerConstSymbol(String name) { |
| 690 symbolsUsed.add(name); | 693 symbolsUsed.add(name); |
| 691 if (name.endsWith('=')) { | 694 if (name.endsWith('=')) { |
| 692 symbolsUsed.add(name.substring(0, name.length - 1)); | 695 symbolsUsed.add(name.substring(0, name.length - 1)); |
| 693 } | 696 } |
| 694 } | 697 } |
| 695 } | 698 } |
| OLD | NEW |