| 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/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 594 |
| 595 Spannable _getSpannable(MemberEntity member, ir.Node node) { | 595 Spannable _getSpannable(MemberEntity member, ir.Node node) { |
| 596 SourceSpan sourceSpan; | 596 SourceSpan sourceSpan; |
| 597 if (node is ir.TreeNode) { | 597 if (node is ir.TreeNode) { |
| 598 sourceSpan = _getSourceSpanFromTreeNode(node); | 598 sourceSpan = _getSourceSpanFromTreeNode(node); |
| 599 } | 599 } |
| 600 sourceSpan ??= getSourceSpan(member, null); | 600 sourceSpan ??= getSourceSpan(member, null); |
| 601 return sourceSpan; | 601 return sourceSpan; |
| 602 } | 602 } |
| 603 | 603 |
| 604 ir.Member _getMemberNode(covariant IndexedMember member) { | 604 MemberDefinition _getMemberDefinition(covariant IndexedMember member) { |
| 605 assert(checkFamily(member)); | 605 assert(checkFamily(member)); |
| 606 return _memberData[member.memberIndex].node; | 606 return _memberData[member.memberIndex].definition; |
| 607 } | 607 } |
| 608 | 608 |
| 609 ir.Class _getClassNode(covariant IndexedClass cls) { | 609 ClassDefinition _getClassDefinition(covariant IndexedClass cls) { |
| 610 assert(checkFamily(cls)); | 610 assert(checkFamily(cls)); |
| 611 return _classEnvs[cls.classIndex].cls; | 611 return _classData[cls.classIndex].definition; |
| 612 } | 612 } |
| 613 } | 613 } |
| 614 | 614 |
| 615 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. | 615 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. |
| 616 abstract class ElementCreatorMixin { | 616 abstract class ElementCreatorMixin { |
| 617 ProgramEnv get _env; | 617 ProgramEnv get _env; |
| 618 List<LibraryEntity> get _libraryList; | 618 List<LibraryEntity> get _libraryList; |
| 619 List<LibraryEnv> get _libraryEnvs; | 619 List<LibraryEnv> get _libraryEnvs; |
| 620 List<LibraryData> get _libraryData; | 620 List<LibraryData> get _libraryData; |
| 621 List<ClassEntity> get _classList; | 621 List<ClassEntity> get _classList; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 name = path.substring(path.lastIndexOf('/') + 1); | 661 name = path.substring(path.lastIndexOf('/') + 1); |
| 662 } | 662 } |
| 663 LibraryEntity library = | 663 LibraryEntity library = |
| 664 createLibrary(_libraryMap.length, name, canonicalUri); | 664 createLibrary(_libraryMap.length, name, canonicalUri); |
| 665 _libraryList.add(library); | 665 _libraryList.add(library); |
| 666 _libraryData.add(new LibraryData(node)); | 666 _libraryData.add(new LibraryData(node)); |
| 667 return library; | 667 return library; |
| 668 }); | 668 }); |
| 669 } | 669 } |
| 670 | 670 |
| 671 // TODO(johnniwinther,efortuna): Create the class index and data together with |
| 672 // the [KernelClosureClass]. |
| 671 void addClosureClass(KernelClosureClass cls, InterfaceType supertype) { | 673 void addClosureClass(KernelClosureClass cls, InterfaceType supertype) { |
| 672 cls.classIndex = _classEnvs.length; | 674 cls.classIndex = _classEnvs.length; |
| 673 _classEnvs.add(new ClassEnv.closureClass()); | 675 _classEnvs.add(new ClassEnv.closureClass()); |
| 674 _classList.add(cls); | 676 _classList.add(cls); |
| 675 | 677 |
| 676 // Create a classData and set up the interfaces and subclass | 678 // Create a classData and set up the interfaces and subclass |
| 677 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing | 679 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing |
| 678 var closureData = new ClassData(null); | 680 var closureData = |
| 681 new ClassData(null, new ClosureClassDefinition(cls, cls.location)); |
| 679 closureData | 682 closureData |
| 680 ..isMixinApplication = false | 683 ..isMixinApplication = false |
| 681 ..thisType = | 684 ..thisType = |
| 682 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ []) | 685 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ []) |
| 683 ..supertype = supertype | 686 ..supertype = supertype |
| 684 ..interfaces = const <InterfaceType>[]; | 687 ..interfaces = const <InterfaceType>[]; |
| 685 var setBuilder = | 688 var setBuilder = |
| 686 new _KernelOrderedTypeSetBuilder((this as KernelToElementMapBase), cls); | 689 new _KernelOrderedTypeSetBuilder((this as KernelToElementMapBase), cls); |
| 687 _classData.add(closureData); | 690 _classData.add(closureData); |
| 688 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( | 691 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( |
| 689 closureData.supertype, const Link<InterfaceType>()); | 692 closureData.supertype, const Link<InterfaceType>()); |
| 690 // TODO(efortuna): Does getMetadata get called in ClassData for this object? | 693 // TODO(efortuna): Does getMetadata get called in ClassData for this object? |
| 691 } | 694 } |
| 692 | 695 |
| 693 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { | 696 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { |
| 694 return _classMap.putIfAbsent(node, () { | 697 return _classMap.putIfAbsent(node, () { |
| 695 KLibrary library = _getLibrary(node.enclosingLibrary); | 698 KLibrary library = _getLibrary(node.enclosingLibrary); |
| 696 if (classEnv == null) { | 699 if (classEnv == null) { |
| 697 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); | 700 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); |
| 698 } | 701 } |
| 699 _classEnvs.add(classEnv); | 702 _classEnvs.add(classEnv); |
| 700 _classData.add(new ClassData(node)); | |
| 701 ClassEntity cls = createClass(library, _classList.length, node.name, | 703 ClassEntity cls = createClass(library, _classList.length, node.name, |
| 702 isAbstract: node.isAbstract); | 704 isAbstract: node.isAbstract); |
| 705 _classData |
| 706 .add(new ClassData(node, new RegularClassDefinition(cls, node))); |
| 703 _classList.add(cls); | 707 _classList.add(cls); |
| 704 return cls; | 708 return cls; |
| 705 }); | 709 }); |
| 706 } | 710 } |
| 707 | 711 |
| 708 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { | 712 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { |
| 709 return _typeVariableMap.putIfAbsent(node, () { | 713 return _typeVariableMap.putIfAbsent(node, () { |
| 710 if (node.parent is ir.Class) { | 714 if (node.parent is ir.Class) { |
| 711 int typeVariableIndex = _typeVariableList.length; | 715 int typeVariableIndex = _typeVariableList.length; |
| 712 ir.Class cls = node.parent; | 716 ir.Class cls = node.parent; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 | 748 |
| 745 ConstructorEntity _getConstructor(ir.Member node) { | 749 ConstructorEntity _getConstructor(ir.Member node) { |
| 746 return _constructorMap.putIfAbsent(node, () { | 750 return _constructorMap.putIfAbsent(node, () { |
| 747 int memberIndex = _memberData.length; | 751 int memberIndex = _memberData.length; |
| 748 ConstructorEntity constructor; | 752 ConstructorEntity constructor; |
| 749 ClassEntity enclosingClass = _getClass(node.enclosingClass); | 753 ClassEntity enclosingClass = _getClass(node.enclosingClass); |
| 750 Name name = getName(node.name); | 754 Name name = getName(node.name); |
| 751 bool isExternal = node.isExternal; | 755 bool isExternal = node.isExternal; |
| 752 | 756 |
| 753 ir.FunctionNode functionNode; | 757 ir.FunctionNode functionNode; |
| 758 MemberDefinition definition; |
| 754 if (node is ir.Constructor) { | 759 if (node is ir.Constructor) { |
| 755 functionNode = node.function; | 760 functionNode = node.function; |
| 756 constructor = createGenerativeConstructor(memberIndex, enclosingClass, | 761 constructor = createGenerativeConstructor(memberIndex, enclosingClass, |
| 757 name, _getParameterStructure(functionNode), | 762 name, _getParameterStructure(functionNode), |
| 758 isExternal: isExternal, isConst: node.isConst); | 763 isExternal: isExternal, isConst: node.isConst); |
| 764 definition = new SpecialMemberDefinition( |
| 765 constructor, node, MemberKind.constructor); |
| 759 } else if (node is ir.Procedure) { | 766 } else if (node is ir.Procedure) { |
| 760 functionNode = node.function; | 767 functionNode = node.function; |
| 761 bool isFromEnvironment = isExternal && | 768 bool isFromEnvironment = isExternal && |
| 762 name.text == 'fromEnvironment' && | 769 name.text == 'fromEnvironment' && |
| 763 const ['int', 'bool', 'String'].contains(enclosingClass.name); | 770 const ['int', 'bool', 'String'].contains(enclosingClass.name); |
| 764 constructor = createFactoryConstructor(memberIndex, enclosingClass, | 771 constructor = createFactoryConstructor(memberIndex, enclosingClass, |
| 765 name, _getParameterStructure(functionNode), | 772 name, _getParameterStructure(functionNode), |
| 766 isExternal: isExternal, | 773 isExternal: isExternal, |
| 767 isConst: node.isConst, | 774 isConst: node.isConst, |
| 768 isFromEnvironmentConstructor: isFromEnvironment); | 775 isFromEnvironmentConstructor: isFromEnvironment); |
| 776 definition = new RegularMemberDefinition(constructor, node); |
| 769 } else { | 777 } else { |
| 770 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. | 778 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. |
| 771 throw failedAt( | 779 throw failedAt( |
| 772 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); | 780 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); |
| 773 } | 781 } |
| 774 _memberData.add(new ConstructorData(node, functionNode)); | 782 _memberData.add(new ConstructorData(node, functionNode, definition)); |
| 775 _memberList.add(constructor); | 783 _memberList.add(constructor); |
| 776 return constructor; | 784 return constructor; |
| 777 }); | 785 }); |
| 778 } | 786 } |
| 779 | 787 |
| 780 FunctionEntity _getMethod(ir.Procedure node) { | 788 FunctionEntity _getMethod(ir.Procedure node) { |
| 781 return _methodMap.putIfAbsent(node, () { | 789 return _methodMap.putIfAbsent(node, () { |
| 782 int memberIndex = _memberData.length; | 790 int memberIndex = _memberData.length; |
| 783 LibraryEntity library; | 791 LibraryEntity library; |
| 784 ClassEntity enclosingClass; | 792 ClassEntity enclosingClass; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 break; | 839 break; |
| 832 case ir.ProcedureKind.Setter: | 840 case ir.ProcedureKind.Setter: |
| 833 assert(asyncMarker == AsyncMarker.SYNC); | 841 assert(asyncMarker == AsyncMarker.SYNC); |
| 834 function = createSetter( | 842 function = createSetter( |
| 835 memberIndex, library, enclosingClass, name.setter, | 843 memberIndex, library, enclosingClass, name.setter, |
| 836 isStatic: isStatic, | 844 isStatic: isStatic, |
| 837 isExternal: isExternal, | 845 isExternal: isExternal, |
| 838 isAbstract: isAbstract); | 846 isAbstract: isAbstract); |
| 839 break; | 847 break; |
| 840 } | 848 } |
| 841 _memberData.add(new FunctionData(node, node.function)); | 849 _memberData.add(new FunctionData( |
| 850 node, node.function, new RegularMemberDefinition(function, node))); |
| 842 _memberList.add(function); | 851 _memberList.add(function); |
| 843 return function; | 852 return function; |
| 844 }); | 853 }); |
| 845 } | 854 } |
| 846 | 855 |
| 847 FieldEntity _getField(ir.Field node) { | 856 FieldEntity _getField(ir.Field node) { |
| 848 return _fieldMap.putIfAbsent(node, () { | 857 return _fieldMap.putIfAbsent(node, () { |
| 849 int memberIndex = _memberData.length; | 858 int memberIndex = _memberData.length; |
| 850 LibraryEntity library; | 859 LibraryEntity library; |
| 851 ClassEntity enclosingClass; | 860 ClassEntity enclosingClass; |
| 852 if (node.enclosingClass != null) { | 861 if (node.enclosingClass != null) { |
| 853 enclosingClass = _getClass(node.enclosingClass); | 862 enclosingClass = _getClass(node.enclosingClass); |
| 854 library = enclosingClass.library; | 863 library = enclosingClass.library; |
| 855 } else { | 864 } else { |
| 856 library = _getLibrary(node.enclosingLibrary); | 865 library = _getLibrary(node.enclosingLibrary); |
| 857 } | 866 } |
| 858 Name name = getName(node.name); | 867 Name name = getName(node.name); |
| 859 bool isStatic = node.isStatic; | 868 bool isStatic = node.isStatic; |
| 860 _memberData.add(new FieldData(node)); | |
| 861 FieldEntity field = createField( | 869 FieldEntity field = createField( |
| 862 memberIndex, library, enclosingClass, name, | 870 memberIndex, library, enclosingClass, name, |
| 863 isStatic: isStatic, | 871 isStatic: isStatic, |
| 864 isAssignable: node.isMutable, | 872 isAssignable: node.isMutable, |
| 865 isConst: node.isConst); | 873 isConst: node.isConst); |
| 874 _memberData |
| 875 .add(new FieldData(node, new RegularMemberDefinition(field, node))); |
| 866 _memberList.add(field); | 876 _memberList.add(field); |
| 867 return field; | 877 return field; |
| 868 }); | 878 }); |
| 869 } | 879 } |
| 870 | 880 |
| 871 ParameterStructure _getParameterStructure(ir.FunctionNode node) { | 881 ParameterStructure _getParameterStructure(ir.FunctionNode node) { |
| 872 // TODO(johnniwinther): Cache the computed function type. | 882 // TODO(johnniwinther): Cache the computed function type. |
| 873 int requiredParameters = node.requiredParameterCount; | 883 int requiredParameters = node.requiredParameterCount; |
| 874 int positionalParameters = node.positionalParameters.length; | 884 int positionalParameters = node.positionalParameters.length; |
| 875 List<String> namedParameters = | 885 List<String> namedParameters = |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 return _getConstructorBody(node, constructor); | 1952 return _getConstructorBody(node, constructor); |
| 1943 } | 1953 } |
| 1944 | 1954 |
| 1945 FunctionEntity _getConstructorBody( | 1955 FunctionEntity _getConstructorBody( |
| 1946 ir.Constructor node, covariant IndexedConstructor constructor) { | 1956 ir.Constructor node, covariant IndexedConstructor constructor) { |
| 1947 ConstructorData data = _memberData[constructor.memberIndex]; | 1957 ConstructorData data = _memberData[constructor.memberIndex]; |
| 1948 if (data.constructorBody == null) { | 1958 if (data.constructorBody == null) { |
| 1949 data.constructorBody = | 1959 data.constructorBody = |
| 1950 createConstructorBody(_memberList.length, constructor); | 1960 createConstructorBody(_memberList.length, constructor); |
| 1951 _memberList.add(data.constructorBody); | 1961 _memberList.add(data.constructorBody); |
| 1952 _memberData.add(new FunctionData(node, node.function)); | 1962 _memberData.add(new FunctionData( |
| 1963 node, |
| 1964 node.function, |
| 1965 new SpecialMemberDefinition( |
| 1966 data.constructorBody, node, MemberKind.constructorBody))); |
| 1953 } | 1967 } |
| 1954 return data.constructorBody; | 1968 return data.constructorBody; |
| 1955 } | 1969 } |
| 1956 | 1970 |
| 1957 ConstructorBodyEntity createConstructorBody( | 1971 ConstructorBodyEntity createConstructorBody( |
| 1958 int memberIndex, ConstructorEntity constructor); | 1972 int memberIndex, ConstructorEntity constructor); |
| 1959 | 1973 |
| 1960 @override | 1974 @override |
| 1961 ir.Member getMemberNode(MemberEntity member) { | 1975 MemberDefinition getMemberDefinition(MemberEntity member) { |
| 1962 return _getMemberNode(member); | 1976 return _getMemberDefinition(member); |
| 1963 } | 1977 } |
| 1964 | 1978 |
| 1965 @override | 1979 @override |
| 1966 ir.Class getClassNode(ClassEntity cls) { | 1980 ClassDefinition getClassDefinition(ClassEntity cls) { |
| 1967 return _getClassNode(cls); | 1981 return _getClassDefinition(cls); |
| 1968 } | 1982 } |
| 1969 | 1983 |
| 1970 @override | 1984 @override |
| 1971 ConstantValue getFieldConstantValue(ir.Field field) { | 1985 ConstantValue getFieldConstantValue(ir.Field field) { |
| 1972 // TODO(johnniwinther): Cache the result in [FieldData]. | 1986 // TODO(johnniwinther): Cache the result in [FieldData]. |
| 1973 return getConstantValue(field.initializer, | 1987 return getConstantValue(field.initializer, |
| 1974 requireConstant: field.isConst, implicitNull: !field.isConst); | 1988 requireConstant: field.isConst, implicitNull: !field.isConst); |
| 1975 } | 1989 } |
| 1976 | 1990 |
| 1977 bool hasConstantFieldInitializer(covariant IndexedField field) { | 1991 bool hasConstantFieldInitializer(covariant IndexedField field) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2006 if (data.constructorBody != null) { | 2020 if (data.constructorBody != null) { |
| 2007 f(data.constructorBody); | 2021 f(data.constructorBody); |
| 2008 } | 2022 } |
| 2009 }); | 2023 }); |
| 2010 } | 2024 } |
| 2011 | 2025 |
| 2012 String getDeferredUri(ir.LibraryDependency node) { | 2026 String getDeferredUri(ir.LibraryDependency node) { |
| 2013 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2027 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
| 2014 } | 2028 } |
| 2015 } | 2029 } |
| OLD | NEW |