| 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'package:front_end/src/base/instrumentation.dart'; | 5 import 'package:front_end/src/base/instrumentation.dart'; |
| 6 import 'package:front_end/src/fasta/errors.dart' show internalError; | 6 import 'package:front_end/src/fasta/errors.dart' show internalError; |
| 7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; | 7 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; |
| 8 import 'package:front_end/src/fasta/names.dart' show callName; | 8 import 'package:front_end/src/fasta/names.dart' show callName; |
| 9 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart'; | 9 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart'; |
| 10 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart'
; | 10 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart'
; |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 return inferredType; | 620 return inferredType; |
| 621 } | 621 } |
| 622 | 622 |
| 623 @override | 623 @override |
| 624 void inferParameterInitializer( | 624 void inferParameterInitializer( |
| 625 Expression initializer, DartType declaredType) { | 625 Expression initializer, DartType declaredType) { |
| 626 assert(closureContext == null); | 626 assert(closureContext == null); |
| 627 inferExpression(initializer, declaredType, false); | 627 inferExpression(initializer, declaredType, false); |
| 628 } | 628 } |
| 629 | 629 |
| 630 /// Performs the core type inference algorithm for property gets (this handles |
| 631 /// both null-aware and non-null-aware property gets). |
| 632 DartType inferPropertyGet( |
| 633 Expression expression, |
| 634 Expression receiver, |
| 635 int fileOffset, |
| 636 PropertyGet desugaredGet, |
| 637 DartType typeContext, |
| 638 bool typeNeeded) { |
| 639 typeNeeded = |
| 640 listener.propertyGetEnter(expression, typeContext) || typeNeeded; |
| 641 // First infer the receiver so we can look up the getter that was invoked. |
| 642 var receiverType = inferExpression(receiver, null, true); |
| 643 Member interfaceMember = |
| 644 findInterfaceMember(receiverType, desugaredGet.name, fileOffset); |
| 645 if (isTopLevel && |
| 646 ((interfaceMember is Procedure && |
| 647 interfaceMember.kind == ProcedureKind.Getter) || |
| 648 interfaceMember is Field)) { |
| 649 if (TypeInferenceEngineImpl.fullTopLevelInference) { |
| 650 if (interfaceMember is KernelField) { |
| 651 var fieldNode = KernelMember.getFieldNode(interfaceMember); |
| 652 if (fieldNode != null) { |
| 653 engine.inferFieldFused(fieldNode, this.fieldNode); |
| 654 } |
| 655 } |
| 656 } else { |
| 657 // References to fields and getters can't be relied upon for top level |
| 658 // inference. |
| 659 recordNotImmediatelyEvident(fileOffset); |
| 660 } |
| 661 } |
| 662 desugaredGet.interfaceTarget = interfaceMember; |
| 663 var inferredType = |
| 664 getCalleeType(interfaceMember, receiverType, desugaredGet.name); |
| 665 // TODO(paulberry): Infer tear-off type arguments if appropriate. |
| 666 listener.propertyGetExit(expression, inferredType); |
| 667 return typeNeeded ? inferredType : null; |
| 668 } |
| 669 |
| 630 /// Modifies a type as appropriate when inferring a closure return type. | 670 /// Modifies a type as appropriate when inferring a closure return type. |
| 631 DartType inferReturnType(DartType returnType, bool isExpressionFunction) { | 671 DartType inferReturnType(DartType returnType, bool isExpressionFunction) { |
| 632 if (returnType == null) { | 672 if (returnType == null) { |
| 633 // Analyzer infers `Null` if there is no `return` expression; the spec | 673 // Analyzer infers `Null` if there is no `return` expression; the spec |
| 634 // says to return `void`. TODO(paulberry): resolve this difference. | 674 // says to return `void`. TODO(paulberry): resolve this difference. |
| 635 return coreTypes.nullClass.rawType; | 675 return coreTypes.nullClass.rawType; |
| 636 } | 676 } |
| 637 if (isExpressionFunction && | 677 if (isExpressionFunction && |
| 638 returnType is InterfaceType && | 678 returnType is InterfaceType && |
| 639 identical(returnType.classNode, coreTypes.nullClass)) { | 679 identical(returnType.classNode, coreTypes.nullClass)) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 void _forEachArgument( | 740 void _forEachArgument( |
| 701 Arguments arguments, void callback(String name, Expression expression)) { | 741 Arguments arguments, void callback(String name, Expression expression)) { |
| 702 for (var expression in arguments.positional) { | 742 for (var expression in arguments.positional) { |
| 703 callback(null, expression); | 743 callback(null, expression); |
| 704 } | 744 } |
| 705 for (var namedExpression in arguments.named) { | 745 for (var namedExpression in arguments.named) { |
| 706 callback(namedExpression.name, namedExpression.value); | 746 callback(namedExpression.name, namedExpression.value); |
| 707 } | 747 } |
| 708 } | 748 } |
| 709 } | 749 } |
| OLD | NEW |