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 library dart2js.kernel.element_map; | 5 library dart2js.kernel.element_map; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/resolution.dart'; | 10 import '../common/resolution.dart'; |
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 _memberMap.values.forEach(f); | 793 _memberMap.values.forEach(f); |
794 for (ir.Member member in _setterMap.values) { | 794 for (ir.Member member in _setterMap.values) { |
795 if (member is ir.Procedure) { | 795 if (member is ir.Procedure) { |
796 f(member); | 796 f(member); |
797 } else { | 797 } else { |
798 // Skip fields; these are also in _memberMap. | 798 // Skip fields; these are also in _memberMap. |
799 } | 799 } |
800 } | 800 } |
801 } | 801 } |
802 | 802 |
803 Iterable<ConstantExpression> getMetadata(KernelToElementMap worldBuilder) { | 803 Iterable<ConstantExpression> getMetadata(KernelToElementMap elementMap) { |
804 if (_metadata == null) { | 804 if (_metadata == null) { |
805 _metadata = worldBuilder.getMetadata(cls.annotations); | 805 _metadata = elementMap.getMetadata(cls.annotations); |
806 } | 806 } |
807 return _metadata; | 807 return _metadata; |
808 } | 808 } |
809 } | 809 } |
810 | 810 |
811 class _MemberData { | 811 class _MemberData { |
812 final ir.Member node; | 812 final ir.Member node; |
| 813 Iterable<ConstantExpression> _metadata; |
813 | 814 |
814 _MemberData(this.node); | 815 _MemberData(this.node); |
815 | 816 |
816 ResolutionImpact getWorldImpact(KernelToElementMap elementMap) { | 817 ResolutionImpact getWorldImpact(KernelToElementMap elementMap) { |
817 return buildKernelImpact(node, elementMap); | 818 return buildKernelImpact(node, elementMap); |
818 } | 819 } |
| 820 |
| 821 Iterable<ConstantExpression> getMetadata(KernelToElementMap elementMap) { |
| 822 return _metadata ??= elementMap.getMetadata(node.annotations); |
| 823 } |
819 } | 824 } |
820 | 825 |
821 class _FunctionData extends _MemberData { | 826 class _FunctionData extends _MemberData { |
822 final ir.FunctionNode functionNode; | 827 final ir.FunctionNode functionNode; |
823 FunctionType _type; | 828 FunctionType _type; |
824 CallStructure _callStructure; | 829 CallStructure _callStructure; |
825 | 830 |
826 _FunctionData(ir.Member node, this.functionNode) : super(node); | 831 _FunctionData(ir.Member node, this.functionNode) : super(node); |
827 | 832 |
828 FunctionType getFunctionType(KernelToElementMap elementMap) { | 833 FunctionType getFunctionType(KernelToElementMap elementMap) { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 CallStructure getCallStructure(KFunction function) { | 1038 CallStructure getCallStructure(KFunction function) { |
1034 _FunctionData data = elementMap._memberList[function.memberIndex]; | 1039 _FunctionData data = elementMap._memberList[function.memberIndex]; |
1035 return data.callStructure; | 1040 return data.callStructure; |
1036 } | 1041 } |
1037 | 1042 |
1038 @override | 1043 @override |
1039 bool isDeferredLoadLibraryGetter(KMember member) { | 1044 bool isDeferredLoadLibraryGetter(KMember member) { |
1040 // TODO(johnniwinther): Support these. | 1045 // TODO(johnniwinther): Support these. |
1041 return false; | 1046 return false; |
1042 } | 1047 } |
| 1048 |
| 1049 @override |
| 1050 Iterable<ConstantValue> getMemberMetadata(KMember member) { |
| 1051 List<ConstantValue> values = <ConstantValue>[]; |
| 1052 _MemberData memberData = elementMap._memberList[member.memberIndex]; |
| 1053 for (ConstantExpression constant in memberData.getMetadata(elementMap)) { |
| 1054 values.add(elementMap.constantEnvironment.getConstantValue(constant)); |
| 1055 } |
| 1056 return values; |
| 1057 } |
1043 } | 1058 } |
1044 | 1059 |
1045 /// Visitor that converts kernel dart types into [DartType]. | 1060 /// Visitor that converts kernel dart types into [DartType]. |
1046 class DartTypeConverter extends ir.DartTypeVisitor<DartType> { | 1061 class DartTypeConverter extends ir.DartTypeVisitor<DartType> { |
1047 final KernelToElementMap elementAdapter; | 1062 final KernelToElementMap elementAdapter; |
1048 bool topLevel = true; | 1063 bool topLevel = true; |
1049 | 1064 |
1050 DartTypeConverter(this.elementAdapter); | 1065 DartTypeConverter(this.elementAdapter); |
1051 | 1066 |
1052 DartType convert(ir.DartType type) { | 1067 DartType convert(ir.DartType type) { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 } | 1293 } |
1279 | 1294 |
1280 InterfaceType getMixinTypeForClass(KClass cls) { | 1295 InterfaceType getMixinTypeForClass(KClass cls) { |
1281 _KClassEnv env = builder._classEnvs[cls.classIndex]; | 1296 _KClassEnv env = builder._classEnvs[cls.classIndex]; |
1282 ir.Supertype mixedInType = env.cls.mixedInType; | 1297 ir.Supertype mixedInType = env.cls.mixedInType; |
1283 if (mixedInType == null) return null; | 1298 if (mixedInType == null) return null; |
1284 return builder.createInterfaceType( | 1299 return builder.createInterfaceType( |
1285 mixedInType.classNode, mixedInType.typeArguments); | 1300 mixedInType.classNode, mixedInType.typeArguments); |
1286 } | 1301 } |
1287 } | 1302 } |
OLD | NEW |