Chromium Code Reviews| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 } | 301 } |
| 302 throw new SpannableAssertionFailure( | 302 throw new SpannableAssertionFailure( |
| 303 cls, "No super method member found for ${name} in $cls."); | 303 cls, "No super method member found for ${name} in $cls."); |
| 304 } | 304 } |
| 305 | 305 |
| 306 @override | 306 @override |
| 307 ConstructorEntity getConstructor(ir.Member node) => _getConstructor(node); | 307 ConstructorEntity getConstructor(ir.Member node) => _getConstructor(node); |
| 308 | 308 |
| 309 ConstructorEntity _getConstructor(ir.Member node); | 309 ConstructorEntity _getConstructor(ir.Member node); |
| 310 | 310 |
| 311 FunctionEntity getConstructorBody(ir.Constructor node) { | |
| 312 ConstructorEntity constructor = getConstructor(node); | |
| 313 return _getConstructorBody(node, constructor); | |
| 314 } | |
| 315 | |
| 316 FunctionEntity _getConstructorBody( | |
| 317 ir.Constructor node, ConstructorEntity constructor); | |
| 318 | |
| 311 ConstructorEntity getSuperConstructor( | 319 ConstructorEntity getSuperConstructor( |
| 312 ir.Constructor sourceNode, ir.Member targetNode) { | 320 ir.Constructor sourceNode, ir.Member targetNode) { |
| 313 ConstructorEntity source = getConstructor(sourceNode); | 321 ConstructorEntity source = getConstructor(sourceNode); |
| 314 ClassEntity sourceClass = source.enclosingClass; | 322 ClassEntity sourceClass = source.enclosingClass; |
| 315 ConstructorEntity target = getConstructor(targetNode); | 323 ConstructorEntity target = getConstructor(targetNode); |
| 316 ClassEntity targetClass = target.enclosingClass; | 324 ClassEntity targetClass = target.enclosingClass; |
| 317 IndexedClass superClass = _getSuperType(sourceClass)?.element; | 325 IndexedClass superClass = _getSuperType(sourceClass)?.element; |
| 318 if (superClass == targetClass) { | 326 if (superClass == targetClass) { |
| 319 return target; | 327 return target; |
| 320 } | 328 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 } | 453 } |
| 446 } | 454 } |
| 447 | 455 |
| 448 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { | 456 void _forEachConstructor(IndexedClass cls, void f(ConstructorEntity member)) { |
| 449 ClassEnv env = _classEnvs[cls.classIndex]; | 457 ClassEnv env = _classEnvs[cls.classIndex]; |
| 450 env.forEachConstructor((ir.Member member) { | 458 env.forEachConstructor((ir.Member member) { |
| 451 f(getConstructor(member)); | 459 f(getConstructor(member)); |
| 452 }); | 460 }); |
| 453 } | 461 } |
| 454 | 462 |
| 463 void _forEachConstructorBody( | |
| 464 IndexedClass cls, void f(ConstructorBodyEntity member)) { | |
| 465 ClassEnv env = _classEnvs[cls.classIndex]; | |
| 466 env.forEachConstructor((ir.Member member) { | |
| 467 IndexedConstructor constructor = getConstructor(member); | |
| 468 ConstructorData data = _memberData[constructor.memberIndex]; | |
| 469 if (data.constructorBody != null) { | |
| 470 f(data.constructorBody); | |
| 471 } | |
| 472 }); | |
| 473 } | |
| 474 | |
| 455 void _forEachClassMember( | 475 void _forEachClassMember( |
| 456 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { | 476 IndexedClass cls, void f(ClassEntity cls, MemberEntity member)) { |
| 457 ClassEnv env = _classEnvs[cls.classIndex]; | 477 ClassEnv env = _classEnvs[cls.classIndex]; |
| 458 env.forEachMember((ir.Member member) { | 478 env.forEachMember((ir.Member member) { |
| 459 f(cls, getMember(member)); | 479 f(cls, getMember(member)); |
| 460 }); | 480 }); |
| 461 ClassData data = _classData[cls.classIndex]; | 481 ClassData data = _classData[cls.classIndex]; |
| 462 _ensureSupertypes(cls, data); | 482 _ensureSupertypes(cls, data); |
| 463 if (data.supertype != null) { | 483 if (data.supertype != null) { |
| 464 _forEachClassMember(data.supertype.element, f); | 484 _forEachClassMember(data.supertype.element, f); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. | 661 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. |
| 642 throw new SpannableAssertionFailure( | 662 throw new SpannableAssertionFailure( |
| 643 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); | 663 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); |
| 644 } | 664 } |
| 645 _memberData.add(new ConstructorData(node, functionNode)); | 665 _memberData.add(new ConstructorData(node, functionNode)); |
| 646 _memberList.add(constructor); | 666 _memberList.add(constructor); |
| 647 return constructor; | 667 return constructor; |
| 648 }); | 668 }); |
| 649 } | 669 } |
| 650 | 670 |
| 671 FunctionEntity _getConstructorBody( | |
| 672 ir.Constructor node, covariant IndexedConstructor constructor) { | |
| 673 ConstructorData data = _memberData[constructor.memberIndex]; | |
| 674 if (data.constructorBody == null) { | |
| 675 data.constructorBody = | |
| 676 createConstructorBody(_memberList.length, constructor); | |
| 677 _memberList.add(data.constructorBody); | |
| 678 _memberData.add(new FunctionData(node, node.function)); | |
| 679 } | |
| 680 return data.constructorBody; | |
| 681 } | |
| 682 | |
| 651 FunctionEntity _getMethod(ir.Procedure node) { | 683 FunctionEntity _getMethod(ir.Procedure node) { |
| 652 return _methodMap.putIfAbsent(node, () { | 684 return _methodMap.putIfAbsent(node, () { |
| 653 int memberIndex = _memberData.length; | 685 int memberIndex = _memberData.length; |
| 654 LibraryEntity library; | 686 LibraryEntity library; |
| 655 ClassEntity enclosingClass; | 687 ClassEntity enclosingClass; |
| 656 if (node.enclosingClass != null) { | 688 if (node.enclosingClass != null) { |
| 657 enclosingClass = _getClass(node.enclosingClass); | 689 enclosingClass = _getClass(node.enclosingClass); |
| 658 library = enclosingClass.library; | 690 library = enclosingClass.library; |
| 659 } else { | 691 } else { |
| 660 library = _getLibrary(node.enclosingLibrary); | 692 library = _getLibrary(node.enclosingLibrary); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 | 831 |
| 800 IndexedConstructor createFactoryConstructor( | 832 IndexedConstructor createFactoryConstructor( |
| 801 int memberIndex, | 833 int memberIndex, |
| 802 ClassEntity enclosingClass, | 834 ClassEntity enclosingClass, |
| 803 Name name, | 835 Name name, |
| 804 ParameterStructure parameterStructure, | 836 ParameterStructure parameterStructure, |
| 805 {bool isExternal, | 837 {bool isExternal, |
| 806 bool isConst, | 838 bool isConst, |
| 807 bool isFromEnvironmentConstructor}); | 839 bool isFromEnvironmentConstructor}); |
| 808 | 840 |
| 841 ConstructorBodyEntity createConstructorBody( | |
| 842 int memberIndex, ConstructorEntity constructor); | |
| 843 | |
| 809 IndexedFunction createGetter(int memberIndex, LibraryEntity library, | 844 IndexedFunction createGetter(int memberIndex, LibraryEntity library, |
| 810 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, | 845 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, |
| 811 {bool isStatic, bool isExternal, bool isAbstract}); | 846 {bool isStatic, bool isExternal, bool isAbstract}); |
| 812 | 847 |
| 813 IndexedFunction createMethod( | 848 IndexedFunction createMethod( |
| 814 int memberIndex, | 849 int memberIndex, |
| 815 LibraryEntity library, | 850 LibraryEntity library, |
| 816 ClassEntity enclosingClass, | 851 ClassEntity enclosingClass, |
| 817 Name name, | 852 Name name, |
| 818 ParameterStructure parameterStructure, | 853 ParameterStructure parameterStructure, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 {bool isExternal, | 905 {bool isExternal, |
| 871 bool isConst, | 906 bool isConst, |
| 872 bool isFromEnvironmentConstructor}) { | 907 bool isFromEnvironmentConstructor}) { |
| 873 return new KFactoryConstructor( | 908 return new KFactoryConstructor( |
| 874 memberIndex, enclosingClass, name, parameterStructure, | 909 memberIndex, enclosingClass, name, parameterStructure, |
| 875 isExternal: isExternal, | 910 isExternal: isExternal, |
| 876 isConst: isConst, | 911 isConst: isConst, |
| 877 isFromEnvironmentConstructor: isFromEnvironmentConstructor); | 912 isFromEnvironmentConstructor: isFromEnvironmentConstructor); |
| 878 } | 913 } |
| 879 | 914 |
| 915 @override | |
| 916 ConstructorBodyEntity createConstructorBody( | |
| 917 int memberIndex, ConstructorEntity constructor) { | |
| 918 return new KConstructorBody(memberIndex, constructor); | |
|
Siggi Cherem (dart-lang)
2017/07/07 20:00:25
I thought we didn't need to have one on the K mode
Johnni Winther
2017/07/10 14:11:33
Now, we don't. [getConstructorBody], [_getConstruc
| |
| 919 } | |
| 920 | |
| 880 IndexedFunction createGetter(int memberIndex, LibraryEntity library, | 921 IndexedFunction createGetter(int memberIndex, LibraryEntity library, |
| 881 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, | 922 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker, |
| 882 {bool isStatic, bool isExternal, bool isAbstract}) { | 923 {bool isStatic, bool isExternal, bool isAbstract}) { |
| 883 return new KGetter(memberIndex, library, enclosingClass, name, asyncMarker, | 924 return new KGetter(memberIndex, library, enclosingClass, name, asyncMarker, |
| 884 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); | 925 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract); |
| 885 } | 926 } |
| 886 | 927 |
| 887 IndexedFunction createMethod( | 928 IndexedFunction createMethod( |
| 888 int memberIndex, | 929 int memberIndex, |
| 889 LibraryEntity library, | 930 LibraryEntity library, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 assert(value != null, | 1035 assert(value != null, |
| 995 failedAt(field, "Field $field doesn't have a constant initial value.")); | 1036 failedAt(field, "Field $field doesn't have a constant initial value.")); |
| 996 return value; | 1037 return value; |
| 997 } | 1038 } |
| 998 | 1039 |
| 999 void forEachParameter(covariant IndexedFunction function, | 1040 void forEachParameter(covariant IndexedFunction function, |
| 1000 void f(DartType type, String name, ConstantValue defaultValue)) { | 1041 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 1001 FunctionData data = _memberData[function.memberIndex]; | 1042 FunctionData data = _memberData[function.memberIndex]; |
| 1002 data.forEachParameter(this, f); | 1043 data.forEachParameter(this, f); |
| 1003 } | 1044 } |
| 1045 | |
| 1046 String getDeferredUri(ir.LibraryDependency node) { | |
| 1047 throw new UnimplementedError( | |
| 1048 'KernelToElementMapForBuildingFromBaseMixin.getDeferredUri'); | |
| 1049 } | |
| 1004 } | 1050 } |
| 1005 | 1051 |
| 1006 /// Element builder used for creating elements and types corresponding to Kernel | 1052 /// Element builder used for creating elements and types corresponding to Kernel |
| 1007 /// IR nodes. | 1053 /// IR nodes. |
| 1008 // TODO(johnniwinther): Use this in the JsStrategy | 1054 // TODO(johnniwinther): Use this in the JsStrategy |
| 1009 class KernelToElementMapForBuildingImpl extends KernelToElementMapBase | 1055 class KernelToElementMapForBuildingImpl extends KernelToElementMapBase |
| 1010 with | 1056 with |
| 1011 KernelToElementMapForBuildingMixin, | 1057 KernelToElementMapForBuildingMixin, |
| 1012 KernelToElementMapForBuildingFromBaseMixin, | 1058 KernelToElementMapForBuildingFromBaseMixin, |
| 1013 ElementCreatorMixin, | 1059 ElementCreatorMixin, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 elementMap._forEachClassMember(cls, f); | 1235 elementMap._forEachClassMember(cls, f); |
| 1190 } | 1236 } |
| 1191 | 1237 |
| 1192 @override | 1238 @override |
| 1193 void forEachConstructor( | 1239 void forEachConstructor( |
| 1194 ClassEntity cls, void f(ConstructorEntity constructor)) { | 1240 ClassEntity cls, void f(ConstructorEntity constructor)) { |
| 1195 elementMap._forEachConstructor(cls, f); | 1241 elementMap._forEachConstructor(cls, f); |
| 1196 } | 1242 } |
| 1197 | 1243 |
| 1198 @override | 1244 @override |
| 1245 void forEachConstructorBody( | |
| 1246 ClassEntity cls, void f(ConstructorBodyEntity constructor)) { | |
| 1247 elementMap._forEachConstructorBody(cls, f); | |
| 1248 } | |
| 1249 | |
| 1250 @override | |
| 1199 void forEachLibraryMember( | 1251 void forEachLibraryMember( |
| 1200 LibraryEntity library, void f(MemberEntity member)) { | 1252 LibraryEntity library, void f(MemberEntity member)) { |
| 1201 elementMap._forEachLibraryMember(library, f); | 1253 elementMap._forEachLibraryMember(library, f); |
| 1202 } | 1254 } |
| 1203 | 1255 |
| 1204 @override | 1256 @override |
| 1205 MemberEntity lookupLibraryMember(LibraryEntity library, String name, | 1257 MemberEntity lookupLibraryMember(LibraryEntity library, String name, |
| 1206 {bool setter: false, bool required: false}) { | 1258 {bool setter: false, bool required: false}) { |
| 1207 MemberEntity member = | 1259 MemberEntity member = |
| 1208 elementMap.lookupLibraryMember(library, name, setter: setter); | 1260 elementMap.lookupLibraryMember(library, name, setter: setter); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1821 @override | 1873 @override |
| 1822 ir.Member getMemberNode(MemberEntity member) { | 1874 ir.Member getMemberNode(MemberEntity member) { |
| 1823 return _getMemberNode(member); | 1875 return _getMemberNode(member); |
| 1824 } | 1876 } |
| 1825 | 1877 |
| 1826 @override | 1878 @override |
| 1827 ir.Class getClassNode(ClassEntity cls) { | 1879 ir.Class getClassNode(ClassEntity cls) { |
| 1828 return _getClassNode(cls); | 1880 return _getClassNode(cls); |
| 1829 } | 1881 } |
| 1830 } | 1882 } |
| OLD | NEW |