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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 bool checkFamily(Entity entity); | 111 bool checkFamily(Entity entity); |
112 | 112 |
113 DartTypes get types => _types; | 113 DartTypes get types => _types; |
114 | 114 |
115 @override | 115 @override |
116 ElementEnvironment get elementEnvironment => _elementEnvironment; | 116 ElementEnvironment get elementEnvironment => _elementEnvironment; |
117 | 117 |
118 @override | 118 @override |
119 CommonElements get commonElements => _commonElements; | 119 CommonElements get commonElements => _commonElements; |
120 | 120 |
| 121 /// NativeBasicData is need for computation of the default super class. |
| 122 NativeBasicData get nativeBasicData; |
| 123 |
121 FunctionEntity get _mainFunction { | 124 FunctionEntity get _mainFunction { |
122 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null; | 125 return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null; |
123 } | 126 } |
124 | 127 |
125 LibraryEntity get _mainLibrary { | 128 LibraryEntity get _mainLibrary { |
126 return _env.mainMethod != null | 129 return _env.mainMethod != null |
127 ? _getLibrary(_env.mainMethod.enclosingLibrary) | 130 ? _getLibrary(_env.mainMethod.enclosingLibrary) |
128 : null; | 131 : null; |
129 } | 132 } |
130 | 133 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 data.interfaces = const <InterfaceType>[]; | 303 data.interfaces = const <InterfaceType>[]; |
301 } else { | 304 } else { |
302 InterfaceType processSupertype(ir.Supertype node) { | 305 InterfaceType processSupertype(ir.Supertype node) { |
303 InterfaceType supertype = _typeConverter.visitSupertype(node); | 306 InterfaceType supertype = _typeConverter.visitSupertype(node); |
304 IndexedClass superclass = supertype.element; | 307 IndexedClass superclass = supertype.element; |
305 ClassData superdata = _classData[superclass.classIndex]; | 308 ClassData superdata = _classData[superclass.classIndex]; |
306 _ensureSupertypes(superclass, superdata); | 309 _ensureSupertypes(superclass, superdata); |
307 return supertype; | 310 return supertype; |
308 } | 311 } |
309 | 312 |
310 data.supertype = processSupertype(node.supertype); | 313 InterfaceType supertype = processSupertype(node.supertype); |
| 314 if (supertype == _commonElements.objectType) { |
| 315 ClassEntity defaultSuperclass = |
| 316 _commonElements.getDefaultSuperclass(cls, nativeBasicData); |
| 317 data.supertype = _elementEnvironment.getRawType(defaultSuperclass); |
| 318 } else { |
| 319 data.supertype = supertype; |
| 320 } |
311 LinkBuilder<InterfaceType> linkBuilder = | 321 LinkBuilder<InterfaceType> linkBuilder = |
312 new LinkBuilder<InterfaceType>(); | 322 new LinkBuilder<InterfaceType>(); |
313 if (node.mixedInType != null) { | 323 if (node.mixedInType != null) { |
314 data.isMixinApplication = true; | 324 data.isMixinApplication = true; |
315 linkBuilder | 325 linkBuilder |
316 .addLast(data.mixedInType = processSupertype(node.mixedInType)); | 326 .addLast(data.mixedInType = processSupertype(node.mixedInType)); |
317 } else { | 327 } else { |
318 data.isMixinApplication = false; | 328 data.isMixinApplication = false; |
319 } | 329 } |
320 node.implementedTypes.forEach((ir.Supertype supertype) { | 330 node.implementedTypes.forEach((ir.Supertype supertype) { |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 } | 1031 } |
1022 | 1032 |
1023 /// Implementation of [KernelToElementMapForImpact] that only supports world | 1033 /// Implementation of [KernelToElementMapForImpact] that only supports world |
1024 /// impact computation. | 1034 /// impact computation. |
1025 class KernelToElementMapForImpactImpl extends KernelToElementMapBase | 1035 class KernelToElementMapForImpactImpl extends KernelToElementMapBase |
1026 with | 1036 with |
1027 KernelToElementMapForImpactMixin, | 1037 KernelToElementMapForImpactMixin, |
1028 ElementCreatorMixin, | 1038 ElementCreatorMixin, |
1029 KElementCreatorMixin { | 1039 KElementCreatorMixin { |
1030 native.BehaviorBuilder _nativeBehaviorBuilder; | 1040 native.BehaviorBuilder _nativeBehaviorBuilder; |
| 1041 FrontendStrategy _frontendStrategy; |
1031 | 1042 |
1032 KernelToElementMapForImpactImpl( | 1043 KernelToElementMapForImpactImpl(DiagnosticReporter reporter, |
1033 DiagnosticReporter reporter, Environment environment) | 1044 Environment environment, this._frontendStrategy) |
1034 : super(reporter, environment); | 1045 : super(reporter, environment); |
1035 | 1046 |
1036 @override | 1047 @override |
1037 bool checkFamily(Entity entity) { | 1048 bool checkFamily(Entity entity) { |
1038 assert( | 1049 assert( |
1039 '$entity'.startsWith(kElementPrefix), | 1050 '$entity'.startsWith(kElementPrefix), |
1040 failedAt(entity, | 1051 failedAt(entity, |
1041 "Unexpected entity $entity, expected family $kElementPrefix.")); | 1052 "Unexpected entity $entity, expected family $kElementPrefix.")); |
1042 return true; | 1053 return true; |
1043 } | 1054 } |
1044 | 1055 |
| 1056 @override |
| 1057 NativeBasicData get nativeBasicData => _frontendStrategy.nativeBasicData; |
| 1058 |
1045 /// Adds libraries in [program] to the set of libraries. | 1059 /// Adds libraries in [program] to the set of libraries. |
1046 /// | 1060 /// |
1047 /// The main method of the first program is used as the main method for the | 1061 /// The main method of the first program is used as the main method for the |
1048 /// compilation. | 1062 /// compilation. |
1049 void addProgram(ir.Program program) { | 1063 void addProgram(ir.Program program) { |
1050 _env.addProgram(program); | 1064 _env.addProgram(program); |
1051 } | 1065 } |
1052 | 1066 |
1053 @override | 1067 @override |
1054 native.BehaviorBuilder get nativeBehaviorBuilder => | 1068 native.BehaviorBuilder get nativeBehaviorBuilder => |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 // codegen world should be a strict subset of the resolution world and | 1803 // codegen world should be a strict subset of the resolution world and |
1790 // creating elements for IR nodes should therefore not be needed. | 1804 // creating elements for IR nodes should therefore not be needed. |
1791 // Currently some are created purely for testing (like | 1805 // Currently some are created purely for testing (like |
1792 // `element == commonElements.foo`, where 'foo' might not be live). | 1806 // `element == commonElements.foo`, where 'foo' might not be live). |
1793 // Others are created because we do a | 1807 // Others are created because we do a |
1794 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted | 1808 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted |
1795 // library. | 1809 // library. |
1796 ElementCreatorMixin | 1810 ElementCreatorMixin |
1797 implements | 1811 implements |
1798 KernelToWorldBuilder { | 1812 KernelToWorldBuilder { |
| 1813 NativeBasicData nativeBasicData; |
| 1814 |
1799 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, | 1815 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, |
1800 KernelToElementMapForImpactImpl _elementMap) | 1816 KernelToElementMapForImpactImpl _elementMap) |
1801 : super(reporter, environment) { | 1817 : super(reporter, environment) { |
1802 _env = _elementMap._env; | 1818 _env = _elementMap._env; |
1803 for (int libraryIndex = 0; | 1819 for (int libraryIndex = 0; |
1804 libraryIndex < _elementMap._libraryEnvs.length; | 1820 libraryIndex < _elementMap._libraryEnvs.length; |
1805 libraryIndex++) { | 1821 libraryIndex++) { |
1806 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; | 1822 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; |
1807 LibraryData data = _elementMap._libraryData[libraryIndex]; | 1823 LibraryData data = _elementMap._libraryData[libraryIndex]; |
1808 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; | 1824 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 if (data.constructorBody != null) { | 2010 if (data.constructorBody != null) { |
1995 f(data.constructorBody); | 2011 f(data.constructorBody); |
1996 } | 2012 } |
1997 }); | 2013 }); |
1998 } | 2014 } |
1999 | 2015 |
2000 String getDeferredUri(ir.LibraryDependency node) { | 2016 String getDeferredUri(ir.LibraryDependency node) { |
2001 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2017 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
2002 } | 2018 } |
2003 } | 2019 } |
OLD | NEW |