| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // absolute URI. | 267 // absolute URI. |
| 268 return enclosingLibrary.importUri.toString(); | 268 return enclosingLibrary.importUri.toString(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void _setInferredType(DartType inferredType) { | 271 void _setInferredType(DartType inferredType) { |
| 272 _isInferred = true; | 272 _isInferred = true; |
| 273 super.type = inferredType; | 273 super.type = inferredType; |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 /// Concrete shadow object representing a local function declaration in kernel |
| 278 /// form. |
| 279 class KernelFunctionDeclaration extends FunctionDeclaration |
| 280 implements KernelStatement { |
| 281 KernelFunctionDeclaration(VariableDeclaration variable, FunctionNode function) |
| 282 : super(variable, function); |
| 283 |
| 284 @override |
| 285 void _inferStatement(KernelTypeInferrer inferrer) { |
| 286 inferrer.inferFunctionDeclaration(function.body); |
| 287 } |
| 288 } |
| 289 |
| 277 /// Concrete shadow object representing a function expression in kernel form. | 290 /// Concrete shadow object representing a function expression in kernel form. |
| 278 class KernelFunctionExpression extends FunctionExpression | 291 class KernelFunctionExpression extends FunctionExpression |
| 279 implements KernelExpression { | 292 implements KernelExpression { |
| 280 KernelFunctionExpression(FunctionNode function) : super(function); | 293 KernelFunctionExpression(FunctionNode function) : super(function); |
| 281 | 294 |
| 282 @override | 295 @override |
| 283 DartType _inferExpression( | 296 DartType _inferExpression( |
| 284 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 297 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
| 285 var asyncMarker = function.asyncMarker; | 298 var asyncMarker = function.asyncMarker; |
| 286 bool isAsync = asyncMarker == AsyncMarker.Async || | 299 bool isAsync = asyncMarker == AsyncMarker.Async || |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } else { | 860 } else { |
| 848 // Hack to deal with the fact that BodyBuilder still creates raw | 861 // Hack to deal with the fact that BodyBuilder still creates raw |
| 849 // VariableDeclaration objects sometimes. | 862 // VariableDeclaration objects sometimes. |
| 850 // TODO(paulberry): get rid of this once the type parameter is | 863 // TODO(paulberry): get rid of this once the type parameter is |
| 851 // KernelVariableDeclaration. | 864 // KernelVariableDeclaration. |
| 852 return 0; | 865 return 0; |
| 853 } | 866 } |
| 854 } | 867 } |
| 855 | 868 |
| 856 @override | 869 @override |
| 870 bool isPromotionCandidate(VariableDeclaration variable) { |
| 871 if (variable is KernelVariableDeclaration) { |
| 872 return !variable._isLocalFunction; |
| 873 } else { |
| 874 // Hack to deal with the fact that BodyBuilder still creates raw |
| 875 // VariableDeclaration objects sometimes. |
| 876 // TODO(paulberry): get rid of this once the type parameter is |
| 877 // KernelVariableDeclaration. |
| 878 return true; |
| 879 } |
| 880 } |
| 881 |
| 882 @override |
| 857 bool sameExpressions(Expression a, Expression b) { | 883 bool sameExpressions(Expression a, Expression b) { |
| 858 return identical(a, b); | 884 return identical(a, b); |
| 859 } | 885 } |
| 860 | 886 |
| 861 @override | 887 @override |
| 862 void setVariableMutatedAnywhere(VariableDeclaration variable) { | 888 void setVariableMutatedAnywhere(VariableDeclaration variable) { |
| 863 if (variable is KernelVariableDeclaration) { | 889 if (variable is KernelVariableDeclaration) { |
| 864 variable._mutatedAnywhere = true; | 890 variable._mutatedAnywhere = true; |
| 865 } else { | 891 } else { |
| 866 // Hack to deal with the fact that BodyBuilder still creates raw | 892 // Hack to deal with the fact that BodyBuilder still creates raw |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 class KernelVariableDeclaration extends VariableDeclaration | 926 class KernelVariableDeclaration extends VariableDeclaration |
| 901 implements KernelStatement { | 927 implements KernelStatement { |
| 902 final bool _implicitlyTyped; | 928 final bool _implicitlyTyped; |
| 903 | 929 |
| 904 final int _functionNestingLevel; | 930 final int _functionNestingLevel; |
| 905 | 931 |
| 906 bool _mutatedInClosure = false; | 932 bool _mutatedInClosure = false; |
| 907 | 933 |
| 908 bool _mutatedAnywhere = false; | 934 bool _mutatedAnywhere = false; |
| 909 | 935 |
| 936 final bool _isLocalFunction; |
| 937 |
| 910 KernelVariableDeclaration(String name, this._functionNestingLevel, | 938 KernelVariableDeclaration(String name, this._functionNestingLevel, |
| 911 {Expression initializer, | 939 {Expression initializer, |
| 912 DartType type, | 940 DartType type, |
| 913 bool isFinal: false, | 941 bool isFinal: false, |
| 914 bool isConst: false}) | 942 bool isConst: false, |
| 943 bool isLocalFunction: false}) |
| 915 : _implicitlyTyped = type == null, | 944 : _implicitlyTyped = type == null, |
| 945 _isLocalFunction = isLocalFunction, |
| 916 super(name, | 946 super(name, |
| 917 initializer: initializer, | 947 initializer: initializer, |
| 918 type: type ?? const DynamicType(), | 948 type: type ?? const DynamicType(), |
| 919 isFinal: isFinal, | 949 isFinal: isFinal, |
| 920 isConst: isConst); | 950 isConst: isConst); |
| 921 | 951 |
| 922 DartType get _declaredType => _implicitlyTyped ? null : type; | 952 DartType get _declaredType => _implicitlyTyped ? null : type; |
| 923 | 953 |
| 924 @override | 954 @override |
| 925 void _inferStatement(KernelTypeInferrer inferrer) { | 955 void _inferStatement(KernelTypeInferrer inferrer) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 : super(variable, value); | 988 : super(variable, value); |
| 959 | 989 |
| 960 @override | 990 @override |
| 961 DartType _inferExpression( | 991 DartType _inferExpression( |
| 962 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 992 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
| 963 var variable = this.variable as KernelVariableDeclaration; | 993 var variable = this.variable as KernelVariableDeclaration; |
| 964 return inferrer.inferVariableSet( | 994 return inferrer.inferVariableSet( |
| 965 typeContext, typeNeeded, variable._declaredType, value); | 995 typeContext, typeNeeded, variable._declaredType, value); |
| 966 } | 996 } |
| 967 } | 997 } |
| OLD | NEW |