| 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 '../closure.dart' show BoxLocal; | 9 import '../closure.dart' show BoxLocal; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 | 982 |
| 983 /// Implementation of [KernelToElementMapForImpact] that only supports world | 983 /// Implementation of [KernelToElementMapForImpact] that only supports world |
| 984 /// impact computation. | 984 /// impact computation. |
| 985 class KernelToElementMapForImpactImpl extends KernelToElementMapBase | 985 class KernelToElementMapForImpactImpl extends KernelToElementMapBase |
| 986 with | 986 with |
| 987 KernelToElementMapForImpactMixin, | 987 KernelToElementMapForImpactMixin, |
| 988 ElementCreatorMixin, | 988 ElementCreatorMixin, |
| 989 KElementCreatorMixin { | 989 KElementCreatorMixin { |
| 990 native.BehaviorBuilder _nativeBehaviorBuilder; | 990 native.BehaviorBuilder _nativeBehaviorBuilder; |
| 991 FrontendStrategy _frontendStrategy; | 991 FrontendStrategy _frontendStrategy; |
| 992 CompilerOptions _options; |
| 992 | 993 |
| 993 KernelToElementMapForImpactImpl(DiagnosticReporter reporter, | 994 KernelToElementMapForImpactImpl(DiagnosticReporter reporter, |
| 994 Environment environment, this._frontendStrategy) | 995 Environment environment, this._frontendStrategy, this._options) |
| 995 : super(reporter, environment); | 996 : super(reporter, environment); |
| 996 | 997 |
| 997 @override | 998 @override |
| 998 bool checkFamily(Entity entity) { | 999 bool checkFamily(Entity entity) { |
| 999 assert( | 1000 assert( |
| 1000 '$entity'.startsWith(kElementPrefix), | 1001 '$entity'.startsWith(kElementPrefix), |
| 1001 failedAt(entity, | 1002 failedAt(entity, |
| 1002 "Unexpected entity $entity, expected family $kElementPrefix.")); | 1003 "Unexpected entity $entity, expected family $kElementPrefix.")); |
| 1003 return true; | 1004 return true; |
| 1004 } | 1005 } |
| 1005 | 1006 |
| 1006 @override | 1007 @override |
| 1007 NativeBasicData get nativeBasicData => _frontendStrategy.nativeBasicData; | 1008 NativeBasicData get nativeBasicData => _frontendStrategy.nativeBasicData; |
| 1008 | 1009 |
| 1009 /// Adds libraries in [program] to the set of libraries. | 1010 /// Adds libraries in [program] to the set of libraries. |
| 1010 /// | 1011 /// |
| 1011 /// The main method of the first program is used as the main method for the | 1012 /// The main method of the first program is used as the main method for the |
| 1012 /// compilation. | 1013 /// compilation. |
| 1013 void addProgram(ir.Program program) { | 1014 void addProgram(ir.Program program) { |
| 1014 _env.addProgram(program); | 1015 _env.addProgram(program); |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 @override | 1018 @override |
| 1018 native.BehaviorBuilder get nativeBehaviorBuilder => | 1019 native.BehaviorBuilder get nativeBehaviorBuilder => |
| 1019 _nativeBehaviorBuilder ??= new KernelBehaviorBuilder(commonElements); | 1020 _nativeBehaviorBuilder ??= new KernelBehaviorBuilder(elementEnvironment, |
| 1021 commonElements, nativeBasicData, reporter, _options); |
| 1020 | 1022 |
| 1021 ResolutionImpact computeWorldImpact(KMember member) { | 1023 ResolutionImpact computeWorldImpact(KMember member) { |
| 1022 return buildKernelImpact( | 1024 return buildKernelImpact( |
| 1023 _memberData[member.memberIndex].definition.node, this); | 1025 _memberData[member.memberIndex].definition.node, this); |
| 1024 } | 1026 } |
| 1025 | 1027 |
| 1026 ClosureModel computeClosureModel(KMember member) { | 1028 ClosureModel computeClosureModel(KMember member) { |
| 1027 ir.Member node = _memberData[member.memberIndex].definition.node; | 1029 ir.Member node = _memberData[member.memberIndex].definition.node; |
| 1028 return KernelClosureAnalysis.computeClosureModel(member, node); | 1030 return KernelClosureAnalysis.computeClosureModel(member, node); |
| 1029 } | 1031 } |
| 1030 | 1032 |
| 1031 /// Returns the kernel [ir.Procedure] node for the [method]. | 1033 /// Returns the kernel [ir.Procedure] node for the [method]. |
| 1032 ir.Procedure _lookupProcedure(KFunction method) { | 1034 ir.Procedure _lookupProcedure(KFunction method) { |
| 1033 return _memberData[method.memberIndex].definition.node; | 1035 return _memberData[method.memberIndex].definition.node; |
| 1034 } | 1036 } |
| 1035 | 1037 |
| 1036 Iterable<ConstantValue> _getClassMetadata(KClass cls) { | |
| 1037 return _classData[cls.classIndex].getMetadata(this); | |
| 1038 } | |
| 1039 | |
| 1040 @override | 1038 @override |
| 1041 Local getLocalFunction(ir.TreeNode node) { | 1039 Local getLocalFunction(ir.TreeNode node) { |
| 1042 assert( | 1040 assert( |
| 1043 node is ir.FunctionDeclaration || node is ir.FunctionExpression, | 1041 node is ir.FunctionDeclaration || node is ir.FunctionExpression, |
| 1044 failedAt( | 1042 failedAt( |
| 1045 CURRENT_ELEMENT_SPANNABLE, 'Invalid local function node: $node')); | 1043 CURRENT_ELEMENT_SPANNABLE, 'Invalid local function node: $node')); |
| 1046 return _localFunctionMap.putIfAbsent(node, () { | 1044 return _localFunctionMap.putIfAbsent(node, () { |
| 1047 MemberEntity memberContext; | 1045 MemberEntity memberContext; |
| 1048 Entity executableContext; | 1046 Entity executableContext; |
| 1049 ir.TreeNode parent = node.parent; | 1047 ir.TreeNode parent = node.parent; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 @override | 1369 @override |
| 1372 DartType visitInvalidType(ir.InvalidType node) { | 1370 DartType visitInvalidType(ir.InvalidType node) { |
| 1373 // Root uses such a `o is Unresolved` and `o as Unresolved` must be special | 1371 // Root uses such a `o is Unresolved` and `o as Unresolved` must be special |
| 1374 // cased in the builder, nested invalid types are treated as `dynamic`. | 1372 // cased in the builder, nested invalid types are treated as `dynamic`. |
| 1375 return const DynamicType(); | 1373 return const DynamicType(); |
| 1376 } | 1374 } |
| 1377 } | 1375 } |
| 1378 | 1376 |
| 1379 /// [native.BehaviorBuilder] for kernel based elements. | 1377 /// [native.BehaviorBuilder] for kernel based elements. |
| 1380 class KernelBehaviorBuilder extends native.BehaviorBuilder { | 1378 class KernelBehaviorBuilder extends native.BehaviorBuilder { |
| 1379 final ElementEnvironment elementEnvironment; |
| 1381 final CommonElements commonElements; | 1380 final CommonElements commonElements; |
| 1381 final DiagnosticReporter reporter; |
| 1382 final NativeBasicData nativeBasicData; |
| 1383 final CompilerOptions _options; |
| 1382 | 1384 |
| 1383 KernelBehaviorBuilder(this.commonElements); | 1385 KernelBehaviorBuilder(this.elementEnvironment, this.commonElements, |
| 1386 this.nativeBasicData, this.reporter, this._options); |
| 1384 | 1387 |
| 1385 @override | 1388 @override |
| 1386 bool get trustJSInteropTypeAnnotations { | 1389 bool get trustJSInteropTypeAnnotations => |
| 1387 throw new UnimplementedError( | 1390 _options.trustJSInteropTypeAnnotations; |
| 1388 "KernelNativeBehaviorComputer.trustJSInteropTypeAnnotations"); | |
| 1389 } | |
| 1390 | |
| 1391 @override | |
| 1392 DiagnosticReporter get reporter { | |
| 1393 throw new UnimplementedError("KernelNativeBehaviorComputer.reporter"); | |
| 1394 } | |
| 1395 | |
| 1396 NativeBasicData get nativeBasicData { | |
| 1397 throw new UnimplementedError( | |
| 1398 "KernelNativeBehaviorComputer.nativeBasicData"); | |
| 1399 } | |
| 1400 } | 1391 } |
| 1401 | 1392 |
| 1402 /// Constant environment mapping [ConstantExpression]s to [ConstantValue]s using | 1393 /// Constant environment mapping [ConstantExpression]s to [ConstantValue]s using |
| 1403 /// [_EvaluationEnvironment] for the evaluation. | 1394 /// [_EvaluationEnvironment] for the evaluation. |
| 1404 class KernelConstantEnvironment implements ConstantEnvironment { | 1395 class KernelConstantEnvironment implements ConstantEnvironment { |
| 1405 final KernelToElementMapBase _elementMap; | 1396 final KernelToElementMapBase _elementMap; |
| 1406 final Environment _environment; | 1397 final Environment _environment; |
| 1407 | 1398 |
| 1408 Map<ConstantExpression, ConstantValue> _valueMap = | 1399 Map<ConstantExpression, ConstantValue> _valueMap = |
| 1409 <ConstantExpression, ConstantValue>{}; | 1400 <ConstantExpression, ConstantValue>{}; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 bool isNativeMethod(covariant KFunction function) { | 1719 bool isNativeMethod(covariant KFunction function) { |
| 1729 if (!native.maybeEnableNative(function.library.canonicalUri)) return false; | 1720 if (!native.maybeEnableNative(function.library.canonicalUri)) return false; |
| 1730 ir.Member node = | 1721 ir.Member node = |
| 1731 elementMap._memberData[function.memberIndex].definition.node; | 1722 elementMap._memberData[function.memberIndex].definition.node; |
| 1732 return node.isExternal && | 1723 return node.isExternal && |
| 1733 !elementMap.isForeignLibrary(node.enclosingLibrary); | 1724 !elementMap.isForeignLibrary(node.enclosingLibrary); |
| 1734 } | 1725 } |
| 1735 | 1726 |
| 1736 @override | 1727 @override |
| 1737 bool isJsInteropMember(MemberEntity element) { | 1728 bool isJsInteropMember(MemberEntity element) { |
| 1738 // TODO(redemption): Compute this. | 1729 return nativeBasicData.isJsInteropMember(element); |
| 1739 return false; | |
| 1740 } | 1730 } |
| 1741 } | 1731 } |
| 1742 | 1732 |
| 1743 class JsToFrontendMapImpl extends JsToFrontendMapBase | 1733 class JsToFrontendMapImpl extends JsToFrontendMapBase |
| 1744 implements JsToFrontendMap { | 1734 implements JsToFrontendMap { |
| 1745 final KernelToElementMapBase _backend; | 1735 final KernelToElementMapBase _backend; |
| 1746 | 1736 |
| 1747 JsToFrontendMapImpl(this._backend); | 1737 JsToFrontendMapImpl(this._backend); |
| 1748 | 1738 |
| 1749 LibraryEntity toBackendLibrary(covariant IndexedLibrary library) { | 1739 LibraryEntity toBackendLibrary(covariant IndexedLibrary library) { |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 /// | 2117 /// |
| 2128 /// These names are not used in generated code, just as element name. | 2118 /// These names are not used in generated code, just as element name. |
| 2129 String _getClosureVariableName(String name, int id) { | 2119 String _getClosureVariableName(String name, int id) { |
| 2130 return "_captured_${name}_$id"; | 2120 return "_captured_${name}_$id"; |
| 2131 } | 2121 } |
| 2132 | 2122 |
| 2133 String getDeferredUri(ir.LibraryDependency node) { | 2123 String getDeferredUri(ir.LibraryDependency node) { |
| 2134 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2124 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
| 2135 } | 2125 } |
| 2136 } | 2126 } |
| OLD | NEW |