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 import 'package:kernel/clone.dart'; | 8 import 'package:kernel/clone.dart'; |
9 import 'package:kernel/type_algebra.dart'; | 9 import 'package:kernel/type_algebra.dart'; |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 import '../elements/entities.dart'; | 22 import '../elements/entities.dart'; |
23 import '../elements/names.dart'; | 23 import '../elements/names.dart'; |
24 import '../elements/types.dart'; | 24 import '../elements/types.dart'; |
25 import '../environment.dart'; | 25 import '../environment.dart'; |
26 import '../frontend_strategy.dart'; | 26 import '../frontend_strategy.dart'; |
27 import '../js_backend/backend_usage.dart'; | 27 import '../js_backend/backend_usage.dart'; |
28 import '../js_backend/constant_system_javascript.dart'; | 28 import '../js_backend/constant_system_javascript.dart'; |
29 import '../js_backend/interceptor_data.dart'; | 29 import '../js_backend/interceptor_data.dart'; |
30 import '../js_backend/native_data.dart'; | 30 import '../js_backend/native_data.dart'; |
31 import '../js_backend/no_such_method_registry.dart'; | 31 import '../js_backend/no_such_method_registry.dart'; |
| 32 import '../js_model/elements.dart'; |
32 import '../native/native.dart' as native; | 33 import '../native/native.dart' as native; |
33 import '../native/resolver.dart'; | 34 import '../native/resolver.dart'; |
34 import '../ordered_typeset.dart'; | 35 import '../ordered_typeset.dart'; |
35 import '../ssa/kernel_impact.dart'; | 36 import '../ssa/kernel_impact.dart'; |
36 import '../universe/class_set.dart'; | 37 import '../universe/class_set.dart'; |
37 import '../universe/function_set.dart'; | 38 import '../universe/function_set.dart'; |
38 import '../universe/selector.dart'; | 39 import '../universe/selector.dart'; |
39 import '../universe/world_builder.dart'; | 40 import '../universe/world_builder.dart'; |
40 import '../world.dart'; | 41 import '../world.dart'; |
41 import '../util/util.dart' show Link, LinkBuilder; | 42 import '../util/util.dart' show Link, LinkBuilder; |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 _getTypeVariable(node.typeParameters[index])); | 488 _getTypeVariable(node.typeParameters[index])); |
488 })); | 489 })); |
489 env.rawType = new InterfaceType( | 490 env.rawType = new InterfaceType( |
490 cls, | 491 cls, |
491 new List/*<DartType>*/ .filled( | 492 new List/*<DartType>*/ .filled( |
492 node.typeParameters.length, const DynamicType())); | 493 node.typeParameters.length, const DynamicType())); |
493 } | 494 } |
494 } | 495 } |
495 } | 496 } |
496 | 497 |
497 InterfaceType getThisType(KClass cls) { | 498 InterfaceType _getThisType(KClass cls) { |
498 _KClassEnv env = _classEnvs[cls.classIndex]; | 499 _KClassEnv env = _classEnvs[cls.classIndex]; |
499 _ensureThisAndRawType(cls, env); | 500 _ensureThisAndRawType(cls, env); |
500 return env.thisType; | 501 return env.thisType; |
501 } | 502 } |
502 | 503 |
503 InterfaceType _getRawType(KClass cls) { | 504 InterfaceType _getRawType(KClass cls) { |
504 _KClassEnv env = _classEnvs[cls.classIndex]; | 505 _KClassEnv env = _classEnvs[cls.classIndex]; |
505 _ensureThisAndRawType(cls, env); | 506 _ensureThisAndRawType(cls, env); |
506 return env.rawType; | 507 return env.rawType; |
507 } | 508 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 } | 570 } |
570 | 571 |
571 ClassEntity _getAppliedMixin(KClass cls) { | 572 ClassEntity _getAppliedMixin(KClass cls) { |
572 _KClassEnv env = _classEnvs[cls.classIndex]; | 573 _KClassEnv env = _classEnvs[cls.classIndex]; |
573 _ensureSupertypes(cls, env); | 574 _ensureSupertypes(cls, env); |
574 return env.mixedInType?.element; | 575 return env.mixedInType?.element; |
575 } | 576 } |
576 | 577 |
577 DartType _substByContext(DartType type, InterfaceType context) { | 578 DartType _substByContext(DartType type, InterfaceType context) { |
578 return type.subst( | 579 return type.subst( |
579 context.typeArguments, getThisType(context.element).typeArguments); | 580 context.typeArguments, _getThisType(context.element).typeArguments); |
580 } | 581 } |
581 | 582 |
582 InterfaceType _getSuperType(KClass cls) { | 583 InterfaceType _getSuperType(KClass cls) { |
583 _KClassEnv env = _classEnvs[cls.classIndex]; | 584 _KClassEnv env = _classEnvs[cls.classIndex]; |
584 _ensureSupertypes(cls, env); | 585 _ensureSupertypes(cls, env); |
585 return env.supertype; | 586 return env.supertype; |
586 } | 587 } |
587 | 588 |
588 bool _isMixinApplication(KClass cls) { | 589 bool _isMixinApplication(KClass cls) { |
589 _KClassEnv env = _classEnvs[cls.classIndex]; | 590 _KClassEnv env = _classEnvs[cls.classIndex]; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 | 736 |
736 ResolutionImpact computeWorldImpact(KMember member) { | 737 ResolutionImpact computeWorldImpact(KMember member) { |
737 return _memberList[member.memberIndex].getWorldImpact(this); | 738 return _memberList[member.memberIndex].getWorldImpact(this); |
738 } | 739 } |
739 | 740 |
740 @override | 741 @override |
741 Spannable getSpannable(MemberEntity member, ir.Node node) { | 742 Spannable getSpannable(MemberEntity member, ir.Node node) { |
742 return member; | 743 return member; |
743 } | 744 } |
744 | 745 |
745 /// Returns the kernel IR node that defines the [member]. | 746 @override |
746 ir.Member getMemberNode(KMember member) { | 747 ir.Member getMemberNode(KMember member) { |
747 return _memberList[member.memberIndex].node; | 748 return _memberList[member.memberIndex].node; |
748 } | 749 } |
749 | 750 |
750 /// Returns the kernel IR node that defines the [cls]. | 751 /// Returns the kernel IR node that defines the [cls]. |
751 ir.Class getClassNode(KClass cls) { | 752 ir.Class getClassNode(KClass cls) { |
752 return _classEnvs[cls.classIndex].cls; | 753 return _classEnvs[cls.classIndex].cls; |
753 } | 754 } |
754 } | 755 } |
755 | 756 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 @override | 1132 @override |
1132 Iterable<LibraryEntity> get libraries => elementMap._libraries; | 1133 Iterable<LibraryEntity> get libraries => elementMap._libraries; |
1133 | 1134 |
1134 @override | 1135 @override |
1135 String getLibraryName(LibraryEntity library) { | 1136 String getLibraryName(LibraryEntity library) { |
1136 return elementMap._getLibraryName(library); | 1137 return elementMap._getLibraryName(library); |
1137 } | 1138 } |
1138 | 1139 |
1139 @override | 1140 @override |
1140 InterfaceType getThisType(ClassEntity cls) { | 1141 InterfaceType getThisType(ClassEntity cls) { |
1141 return elementMap.getThisType(cls); | 1142 return elementMap._getThisType(cls); |
1142 } | 1143 } |
1143 | 1144 |
1144 @override | 1145 @override |
1145 InterfaceType getRawType(ClassEntity cls) { | 1146 InterfaceType getRawType(ClassEntity cls) { |
1146 return elementMap._getRawType(cls); | 1147 return elementMap._getRawType(cls); |
1147 } | 1148 } |
1148 | 1149 |
1149 @override | 1150 @override |
1150 bool isGenericClass(ClassEntity cls) { | 1151 bool isGenericClass(ClassEntity cls) { |
1151 return getThisType(cls).typeArguments.isNotEmpty; | 1152 return getThisType(cls).typeArguments.isNotEmpty; |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 return node.isExternal && | 1699 return node.isExternal && |
1699 !elementMap.isForeignLibrary(node.enclosingLibrary); | 1700 !elementMap.isForeignLibrary(node.enclosingLibrary); |
1700 } | 1701 } |
1701 | 1702 |
1702 @override | 1703 @override |
1703 bool isJsInteropMember(MemberEntity element) { | 1704 bool isJsInteropMember(MemberEntity element) { |
1704 // TODO(johnniwinther): Compute this. | 1705 // TODO(johnniwinther): Compute this. |
1705 return false; | 1706 return false; |
1706 } | 1707 } |
1707 } | 1708 } |
| 1709 |
| 1710 class JsKernelToElementMap extends KernelToElementMapMixin { |
| 1711 final JsToFrontendMap _map; |
| 1712 final ElementEnvironment _elementEnvironment; |
| 1713 final CommonElements _commonElements; |
| 1714 final KernelToElementMapImpl _elementMap; |
| 1715 |
| 1716 JsKernelToElementMap(this._map, this._elementEnvironment, |
| 1717 this._commonElements, this._elementMap); |
| 1718 |
| 1719 @override |
| 1720 Spannable getSpannable(MemberEntity member, ir.Node node) { |
| 1721 return _elementMap.getSpannable(_map.toFrontendMember(member), node); |
| 1722 } |
| 1723 |
| 1724 @override |
| 1725 LibraryEntity getLibrary(ir.Library node) { |
| 1726 return _map.toBackendLibrary(_elementMap.getLibrary(node)); |
| 1727 } |
| 1728 |
| 1729 @override |
| 1730 Local getLocalFunction(ir.TreeNode node) { |
| 1731 throw new UnsupportedError("JsKernelToElementMap.getLocalFunction"); |
| 1732 } |
| 1733 |
| 1734 @override |
| 1735 ClassEntity getClass(ir.Class node) { |
| 1736 return _map.toBackendClass(_elementMap.getClass(node)); |
| 1737 } |
| 1738 |
| 1739 @override |
| 1740 FieldEntity getField(ir.Field node) { |
| 1741 return _map.toBackendMember(_elementMap.getField(node)); |
| 1742 } |
| 1743 |
| 1744 @override |
| 1745 MemberEntity getSuperMember(ir.Member context, ir.Name name, ir.Member target, |
| 1746 {bool setter: false}) { |
| 1747 return _map.toBackendMember( |
| 1748 _elementMap.getSuperMember(context, name, target, setter: setter)); |
| 1749 } |
| 1750 |
| 1751 @override |
| 1752 FunctionEntity getMethod(ir.Procedure node) { |
| 1753 return _map.toBackendMember(_elementMap.getMethod(node)); |
| 1754 } |
| 1755 |
| 1756 @override |
| 1757 ir.Member getMemberNode(MemberEntity member) { |
| 1758 return _elementMap.getMemberNode(_map.toFrontendMember(member)); |
| 1759 } |
| 1760 |
| 1761 @override |
| 1762 MemberEntity getMember(ir.Member node) { |
| 1763 return _map.toBackendMember(_elementMap.getMember(node)); |
| 1764 } |
| 1765 |
| 1766 @override |
| 1767 ConstructorEntity getSuperConstructor( |
| 1768 ir.Constructor constructor, ir.Member target) { |
| 1769 return _map |
| 1770 .toBackendMember(_elementMap.getSuperConstructor(constructor, target)); |
| 1771 } |
| 1772 |
| 1773 @override |
| 1774 ConstructorEntity getConstructor(ir.Member node) { |
| 1775 return _map.toBackendMember(_elementMap.getConstructor(node)); |
| 1776 } |
| 1777 |
| 1778 @override |
| 1779 InterfaceType createInterfaceType( |
| 1780 ir.Class cls, List<ir.DartType> typeArguments) { |
| 1781 return _map |
| 1782 .toBackendType(_elementMap.createInterfaceType(cls, typeArguments)); |
| 1783 } |
| 1784 |
| 1785 @override |
| 1786 InterfaceType getInterfaceType(ir.InterfaceType type) { |
| 1787 return _map.toBackendType(_elementMap.getInterfaceType(type)); |
| 1788 } |
| 1789 |
| 1790 @override |
| 1791 List<DartType> getDartTypes(List<ir.DartType> types) { |
| 1792 return _elementMap.getDartTypes(types).map(_map.toBackendType).toList(); |
| 1793 } |
| 1794 |
| 1795 @override |
| 1796 FunctionType getFunctionType(ir.FunctionNode node) { |
| 1797 return _map.toBackendType(_elementMap.getFunctionType(node)); |
| 1798 } |
| 1799 |
| 1800 @override |
| 1801 DartType getDartType(ir.DartType type) { |
| 1802 return _map.toBackendType(_elementMap.getDartType(type)); |
| 1803 } |
| 1804 |
| 1805 @override |
| 1806 ElementEnvironment get elementEnvironment { |
| 1807 return _elementEnvironment; |
| 1808 } |
| 1809 |
| 1810 @override |
| 1811 CommonElements get commonElements { |
| 1812 return _commonElements; |
| 1813 } |
| 1814 |
| 1815 @override |
| 1816 ConstantValue computeConstantValue(ConstantExpression constant, |
| 1817 {bool requireConstant: true}) { |
| 1818 throw new UnsupportedError("JsKernelToElementMap.computeConstantValue"); |
| 1819 } |
| 1820 |
| 1821 @override |
| 1822 native.BehaviorBuilder get nativeBehaviorBuilder { |
| 1823 throw new UnsupportedError("JsKernelToElementMap.nativeBehaviorBuilder"); |
| 1824 } |
| 1825 |
| 1826 @override |
| 1827 DiagnosticReporter get reporter { |
| 1828 return _elementMap.reporter; |
| 1829 } |
| 1830 |
| 1831 @override |
| 1832 ConstantValue getFieldConstantValue(ir.Field field) { |
| 1833 throw new UnsupportedError("JsKernelToElementMap.getFieldConstantValue"); |
| 1834 } |
| 1835 } |
OLD | NEW |