| 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 /// This file declares a "shadow hierarchy" of concrete classes which extend | 5 /// This file declares a "shadow hierarchy" of concrete classes which extend |
| 6 /// the kernel class hierarchy, adding methods and fields needed by the | 6 /// the kernel class hierarchy, adding methods and fields needed by the |
| 7 /// BodyBuilder. | 7 /// BodyBuilder. |
| 8 /// | 8 /// |
| 9 /// Instances of these classes may be created using the factory methods in | 9 /// Instances of these classes may be created using the factory methods in |
| 10 /// `ast_factory.dart`. | 10 /// `ast_factory.dart`. |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 @override | 730 @override |
| 731 DartType _inferExpression( | 731 DartType _inferExpression( |
| 732 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 732 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
| 733 // TODO(scheglov): implement. | 733 // TODO(scheglov): implement. |
| 734 return typeNeeded ? const DynamicType() : null; | 734 return typeNeeded ? const DynamicType() : null; |
| 735 } | 735 } |
| 736 } | 736 } |
| 737 | 737 |
| 738 /// Shadow object for [MapLiteral]. | 738 /// Shadow object for [MapLiteral]. |
| 739 class KernelMapLiteral extends MapLiteral implements KernelExpression { | 739 class KernelMapLiteral extends MapLiteral implements KernelExpression { |
| 740 final DartType _declaredKeyType; |
| 741 final DartType _declaredValueType; |
| 742 |
| 740 KernelMapLiteral(List<MapEntry> entries, | 743 KernelMapLiteral(List<MapEntry> entries, |
| 741 {DartType keyType: const DynamicType(), | 744 {DartType keyType, DartType valueType, bool isConst: false}) |
| 742 DartType valueType: const DynamicType(), | 745 : _declaredKeyType = keyType, |
| 743 bool isConst: false}) | 746 _declaredValueType = valueType, |
| 744 : super(entries, | 747 super(entries, |
| 745 keyType: keyType, valueType: valueType, isConst: isConst); | 748 keyType: keyType ?? const DynamicType(), |
| 749 valueType: valueType ?? const DynamicType(), |
| 750 isConst: isConst); |
| 746 | 751 |
| 747 @override | 752 @override |
| 748 DartType _inferExpression( | 753 DartType _inferExpression( |
| 749 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 754 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
| 750 // TODO(scheglov): implement. | 755 typeNeeded = |
| 751 return typeNeeded ? const DynamicType() : null; | 756 inferrer.listener.mapLiteralEnter(this, typeContext) || typeNeeded; |
| 757 var mapClass = inferrer.coreTypes.mapClass; |
| 758 var mapType = mapClass.thisType; |
| 759 List<DartType> inferredTypes; |
| 760 DartType inferredKeyType; |
| 761 DartType inferredValueType; |
| 762 List<DartType> formalTypes; |
| 763 List<DartType> actualTypes; |
| 764 assert((_declaredKeyType == null) == (_declaredValueType == null)); |
| 765 bool inferenceNeeded = _declaredKeyType == null && inferrer.strongMode; |
| 766 if (inferenceNeeded) { |
| 767 inferredTypes = [const UnknownType(), const UnknownType()]; |
| 768 inferrer.typeSchemaEnvironment.inferGenericFunctionOrType(mapType, |
| 769 mapClass.typeParameters, null, null, typeContext, inferredTypes); |
| 770 inferredKeyType = inferredTypes[0]; |
| 771 inferredValueType = inferredTypes[1]; |
| 772 formalTypes = []; |
| 773 actualTypes = []; |
| 774 } else { |
| 775 inferredKeyType = _declaredKeyType ?? const DynamicType(); |
| 776 inferredValueType = _declaredValueType ?? const DynamicType(); |
| 777 } |
| 778 for (var entry in entries) { |
| 779 var keyType = |
| 780 inferrer.inferExpression(entry.key, inferredKeyType, inferenceNeeded); |
| 781 var valueType = inferrer.inferExpression( |
| 782 entry.value, inferredValueType, inferenceNeeded); |
| 783 if (inferenceNeeded) { |
| 784 formalTypes.addAll(mapType.typeArguments); |
| 785 actualTypes.add(keyType); |
| 786 actualTypes.add(valueType); |
| 787 } |
| 788 } |
| 789 if (inferenceNeeded) { |
| 790 inferrer.typeSchemaEnvironment.inferGenericFunctionOrType( |
| 791 mapType, |
| 792 mapClass.typeParameters, |
| 793 formalTypes, |
| 794 actualTypes, |
| 795 typeContext, |
| 796 inferredTypes); |
| 797 inferredKeyType = inferredTypes[0]; |
| 798 inferredValueType = inferredTypes[1]; |
| 799 inferrer.instrumentation?.record( |
| 800 Uri.parse(inferrer.uri), |
| 801 fileOffset, |
| 802 'typeArgs', |
| 803 new InstrumentationValueForTypeArgs( |
| 804 [inferredKeyType, inferredValueType])); |
| 805 keyType = inferredKeyType; |
| 806 valueType = inferredValueType; |
| 807 } |
| 808 var inferredType = typeNeeded |
| 809 ? new InterfaceType(mapClass, [inferredKeyType, inferredValueType]) |
| 810 : null; |
| 811 inferrer.listener.mapLiteralExit(this, inferredType); |
| 812 return inferredType; |
| 752 } | 813 } |
| 753 } | 814 } |
| 754 | 815 |
| 755 /// Shadow object for [MethodInvocation]. | 816 /// Shadow object for [MethodInvocation]. |
| 756 class KernelMethodInvocation extends MethodInvocation | 817 class KernelMethodInvocation extends MethodInvocation |
| 757 implements KernelExpression { | 818 implements KernelExpression { |
| 758 KernelMethodInvocation(Expression receiver, Name name, Arguments arguments, | 819 KernelMethodInvocation(Expression receiver, Name name, Arguments arguments, |
| 759 [Procedure interfaceTarget]) | 820 [Procedure interfaceTarget]) |
| 760 : super(receiver, name, arguments, interfaceTarget); | 821 : super(receiver, name, arguments, interfaceTarget); |
| 761 | 822 |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 closureContext.isAsync | 1527 closureContext.isAsync |
| 1467 ? inferrer.coreTypes.streamClass | 1528 ? inferrer.coreTypes.streamClass |
| 1468 : inferrer.coreTypes.iterableClass); | 1529 : inferrer.coreTypes.iterableClass); |
| 1469 } | 1530 } |
| 1470 var inferredType = inferrer.inferExpression( | 1531 var inferredType = inferrer.inferExpression( |
| 1471 expression, typeContext, closureContext != null); | 1532 expression, typeContext, closureContext != null); |
| 1472 closureContext.handleYield(inferrer, isYieldStar, inferredType); | 1533 closureContext.handleYield(inferrer, isYieldStar, inferredType); |
| 1473 inferrer.listener.yieldStatementExit(this); | 1534 inferrer.listener.yieldStatementExit(this); |
| 1474 } | 1535 } |
| 1475 } | 1536 } |
| OLD | NEW |