Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: pkg/analyzer/lib/src/dart/ast/ast.dart

Issue 1720433002: fixes #25477, downward inference of generic methods (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.dart.ast.ast; 5 library analyzer.src.dart.ast.ast;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 5036 matching lines...) Expand 10 before | Expand all | Expand 10 after
5047 5047
5048 /** 5048 /**
5049 * The invocation of a function resulting from evaluating an expression. 5049 * The invocation of a function resulting from evaluating an expression.
5050 * Invocations of methods and other forms of functions are represented by 5050 * Invocations of methods and other forms of functions are represented by
5051 * [MethodInvocation] nodes. Invocations of getters and setters are represented 5051 * [MethodInvocation] nodes. Invocations of getters and setters are represented
5052 * by either [PrefixedIdentifier] or [PropertyAccess] nodes. 5052 * by either [PrefixedIdentifier] or [PropertyAccess] nodes.
5053 * 5053 *
5054 * > functionExpressionInvocation ::= 5054 * > functionExpressionInvocation ::=
5055 * > [Expression] [TypeArgumentList]? [ArgumentList] 5055 * > [Expression] [TypeArgumentList]? [ArgumentList]
5056 */ 5056 */
5057 class FunctionExpressionInvocationImpl extends ExpressionImpl 5057 class FunctionExpressionInvocationImpl extends InvocationExpressionImpl
5058 implements FunctionExpressionInvocation { 5058 implements FunctionExpressionInvocation {
5059 /** 5059 /**
5060 * The expression producing the function being invoked. 5060 * The expression producing the function being invoked.
5061 */ 5061 */
5062 Expression _function; 5062 Expression _function;
5063 5063
5064 /** 5064 /**
5065 * The type arguments to be applied to the method being invoked, or `null` if
5066 * no type arguments were provided.
5067 */
5068 TypeArgumentList _typeArguments;
5069
5070 /**
5071 * The list of arguments to the function.
5072 */
5073 ArgumentList _argumentList;
5074
5075 /**
5076 * The element associated with the function being invoked based on static type 5065 * The element associated with the function being invoked based on static type
5077 * information, or `null` if the AST structure has not been resolved or the 5066 * information, or `null` if the AST structure has not been resolved or the
5078 * function could not be resolved. 5067 * function could not be resolved.
5079 */ 5068 */
5080 ExecutableElement staticElement; 5069 ExecutableElement staticElement;
5081 5070
5082 /** 5071 /**
5083 * The function type of the method invocation, or `null` if the AST
5084 * structure has not been resolved, or if the invoke could not be resolved.
5085 *
5086 * This will usually be a [FunctionType], but it can also be an
5087 * [InterfaceType] with a `call` method, `dynamic`, `Function`, or a `@proxy`
5088 * interface type that implements `Function`.
5089 */
5090 DartType staticInvokeType;
5091
5092 /**
5093 * The element associated with the function being invoked based on propagated 5072 * The element associated with the function being invoked based on propagated
5094 * type information, or `null` if the AST structure has not been resolved or 5073 * type information, or `null` if the AST structure has not been resolved or
5095 * the function could not be resolved. 5074 * the function could not be resolved.
5096 */ 5075 */
5097 ExecutableElement propagatedElement; 5076 ExecutableElement propagatedElement;
5098 5077
5099 /** 5078 /**
5100 * Like [staticInvokeType], but reflects propagated type information.
5101 */
5102 DartType propagatedInvokeType;
5103
5104 /**
5105 * Initialize a newly created function expression invocation. 5079 * Initialize a newly created function expression invocation.
5106 */ 5080 */
5107 FunctionExpressionInvocationImpl(Expression function, 5081 FunctionExpressionInvocationImpl(Expression function,
5108 TypeArgumentList typeArguments, ArgumentList argumentList) { 5082 TypeArgumentList typeArguments, ArgumentList argumentList)
5083 : super(typeArguments, argumentList) {
5109 _function = _becomeParentOf(function); 5084 _function = _becomeParentOf(function);
5110 _typeArguments = _becomeParentOf(typeArguments);
5111 _argumentList = _becomeParentOf(argumentList);
5112 } 5085 }
5113 5086
5114 @override 5087 @override
5115 ArgumentList get argumentList => _argumentList;
5116
5117 @override
5118 void set argumentList(ArgumentList argumentList) {
5119 _argumentList = _becomeParentOf(argumentList);
5120 }
5121
5122 @override
5123 Token get beginToken => _function.beginToken; 5088 Token get beginToken => _function.beginToken;
5124 5089
5125 @override 5090 @override
5126 ExecutableElement get bestElement { 5091 ExecutableElement get bestElement {
5127 ExecutableElement element = propagatedElement; 5092 ExecutableElement element = propagatedElement;
5128 if (element == null) { 5093 if (element == null) {
5129 element = staticElement; 5094 element = staticElement;
5130 } 5095 }
5131 return element; 5096 return element;
5132 } 5097 }
5133 5098
5134 @override 5099 @override
5135 Iterable get childEntities => 5100 Iterable get childEntities =>
5136 new ChildEntities()..add(_function)..add(_argumentList); 5101 new ChildEntities()..add(_function)..add(_argumentList);
5137 5102
5138 @override 5103 @override
5139 Token get endToken => _argumentList.endToken; 5104 Token get endToken => _argumentList.endToken;
5140 5105
5141 @override 5106 @override
5142 Expression get function => _function; 5107 Expression get function => _function;
5143 5108
5144 @override 5109 @override
5145 void set function(Expression expression) { 5110 void set function(Expression expression) {
5146 _function = _becomeParentOf(expression); 5111 _function = _becomeParentOf(expression);
5147 } 5112 }
5148 5113
5149 @override 5114 @override
5115 Expression get invocationTarget => function;
5116
5117 @override
5150 int get precedence => 15; 5118 int get precedence => 15;
5151 5119
5152 @override 5120 @override
5153 TypeArgumentList get typeArguments => _typeArguments;
5154
5155 @override
5156 void set typeArguments(TypeArgumentList typeArguments) {
5157 _typeArguments = _becomeParentOf(typeArguments);
5158 }
5159
5160 @override
5161 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this); 5121 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this);
5162 5122
5163 @override 5123 @override
5164 void visitChildren(AstVisitor visitor) { 5124 void visitChildren(AstVisitor visitor) {
5165 _safelyVisitChild(_function, visitor); 5125 _safelyVisitChild(_function, visitor);
5166 _safelyVisitChild(_typeArguments, visitor); 5126 _safelyVisitChild(_typeArguments, visitor);
5167 _safelyVisitChild(_argumentList, visitor); 5127 _safelyVisitChild(_argumentList, visitor);
5168 } 5128 }
5169 } 5129 }
5170 5130
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
6160 Token get endToken => contents; 6120 Token get endToken => contents;
6161 6121
6162 @override 6122 @override
6163 accept(AstVisitor visitor) => visitor.visitInterpolationString(this); 6123 accept(AstVisitor visitor) => visitor.visitInterpolationString(this);
6164 6124
6165 @override 6125 @override
6166 void visitChildren(AstVisitor visitor) {} 6126 void visitChildren(AstVisitor visitor) {}
6167 } 6127 }
6168 6128
6169 /** 6129 /**
6130 * Common base class for [FunctionExpressionInvocationImpl] and
6131 * [MethodInvocationImpl].
6132 */
6133 abstract class InvocationExpressionImpl extends ExpressionImpl
6134 implements InvocationExpression {
6135 @override
6136 DartType staticInvokeType;
6137
6138 @override
6139 DartType propagatedInvokeType;
Brian Wilkerson 2016/02/22 22:13:26 nit: We generally (always?) place non-AstNode type
Jennifer Messerly 2016/02/22 22:45:55 Sorry about that. I didn't realize that "sort memb
6140
6141 /**
6142 * The type arguments to be applied to the method being invoked, or `null` if
6143 * no type arguments were provided.
6144 */
6145 TypeArgumentList _typeArguments;
6146
6147 /**
6148 * The list of arguments to the function.
6149 */
6150 ArgumentList _argumentList;
6151
6152 /**
6153 * Initialize a newly created invocation.
6154 */
6155 InvocationExpressionImpl(
6156 TypeArgumentList typeArguments, ArgumentList argumentList) {
6157 _typeArguments = _becomeParentOf(typeArguments);
6158 _argumentList = _becomeParentOf(argumentList);
6159 }
6160
6161 @override
6162 ArgumentList get argumentList => _argumentList;
6163
6164 @override
6165 void set argumentList(ArgumentList argumentList) {
6166 _argumentList = _becomeParentOf(argumentList);
6167 }
6168
6169 @override
6170 TypeArgumentList get typeArguments => _typeArguments;
6171
6172 @override
6173 void set typeArguments(TypeArgumentList typeArguments) {
6174 _typeArguments = _becomeParentOf(typeArguments);
6175 }
6176 }
6177
6178 /**
6170 * An is expression. 6179 * An is expression.
6171 * 6180 *
6172 * > isExpression ::= 6181 * > isExpression ::=
6173 * > [Expression] 'is' '!'? [TypeName] 6182 * > [Expression] 'is' '!'? [TypeName]
6174 */ 6183 */
6175 class IsExpressionImpl extends ExpressionImpl implements IsExpression { 6184 class IsExpressionImpl extends ExpressionImpl implements IsExpression {
6176 /** 6185 /**
6177 * The expression used to compute the value whose type is being tested. 6186 * The expression used to compute the value whose type is being tested.
6178 */ 6187 */
6179 Expression _expression; 6188 Expression _expression;
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
6952 6961
6953 /** 6962 /**
6954 * The invocation of either a function or a method. Invocations of functions 6963 * The invocation of either a function or a method. Invocations of functions
6955 * resulting from evaluating an expression are represented by 6964 * resulting from evaluating an expression are represented by
6956 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are 6965 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are
6957 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes. 6966 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes.
6958 * 6967 *
6959 * > methodInvocation ::= 6968 * > methodInvocation ::=
6960 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis t] 6969 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis t]
6961 */ 6970 */
6962 class MethodInvocationImpl extends ExpressionImpl implements MethodInvocation { 6971 class MethodInvocationImpl extends InvocationExpressionImpl
6972 implements MethodInvocation {
6963 /** 6973 /**
6964 * The expression producing the object on which the method is defined, or 6974 * The expression producing the object on which the method is defined, or
6965 * `null` if there is no target (that is, the target is implicitly `this`). 6975 * `null` if there is no target (that is, the target is implicitly `this`).
6966 */ 6976 */
6967 Expression _target; 6977 Expression _target;
6968 6978
6969 /** 6979 /**
6970 * The operator that separates the target from the method name, or `null` 6980 * The operator that separates the target from the method name, or `null`
6971 * if there is no target. In an ordinary method invocation this will be a 6981 * if there is no target. In an ordinary method invocation this will be a
6972 * period ('.'). In a cascade section this will be the cascade operator 6982 * period ('.'). In a cascade section this will be the cascade operator
6973 * ('..'). 6983 * ('..').
6974 */ 6984 */
6975 Token operator; 6985 Token operator;
6976 6986
6977 /** 6987 /**
6978 * The name of the method being invoked. 6988 * The name of the method being invoked.
6979 */ 6989 */
6980 SimpleIdentifier _methodName; 6990 SimpleIdentifier _methodName;
6981 6991
6982 /** 6992 /**
6983 * The type arguments to be applied to the method being invoked, or `null` if
6984 * no type arguments were provided.
6985 */
6986 TypeArgumentList _typeArguments;
6987
6988 /**
6989 * The list of arguments to the method.
6990 */
6991 ArgumentList _argumentList;
6992
6993 /**
6994 * The function type of the method invocation, or `null` if the AST
6995 * structure has not been resolved, or if the invoke could not be resolved.
6996 *
6997 * This will usually be a [FunctionType], but it can also be an
6998 * [InterfaceType] with a `call` method, `dynamic`, `Function`, or a `@proxy`
6999 * interface type that implements `Function`.
7000 */
7001 DartType staticInvokeType;
7002
7003 /**
7004 * Like [staticInvokeType], but reflects propagated type information.
7005 */
7006 DartType propagatedInvokeType;
7007
7008 /**
7009 * Initialize a newly created method invocation. The [target] and [operator] 6993 * Initialize a newly created method invocation. The [target] and [operator]
7010 * can be `null` if there is no target. 6994 * can be `null` if there is no target.
7011 */ 6995 */
7012 MethodInvocationImpl( 6996 MethodInvocationImpl(
7013 Expression target, 6997 Expression target,
7014 this.operator, 6998 this.operator,
7015 SimpleIdentifier methodName, 6999 SimpleIdentifier methodName,
7016 TypeArgumentList typeArguments, 7000 TypeArgumentList typeArguments,
7017 ArgumentList argumentList) { 7001 ArgumentList argumentList)
7002 : super(typeArguments, argumentList) {
7018 _target = _becomeParentOf(target); 7003 _target = _becomeParentOf(target);
7019 _methodName = _becomeParentOf(methodName); 7004 _methodName = _becomeParentOf(methodName);
7020 _typeArguments = _becomeParentOf(typeArguments);
7021 _argumentList = _becomeParentOf(argumentList);
7022 } 7005 }
7023 7006
7024 @override 7007 @override
7025 ArgumentList get argumentList => _argumentList;
7026
7027 @override
7028 void set argumentList(ArgumentList argumentList) {
7029 _argumentList = _becomeParentOf(argumentList);
7030 }
7031
7032 @override
7033 Token get beginToken { 7008 Token get beginToken {
7034 if (_target != null) { 7009 if (_target != null) {
7035 return _target.beginToken; 7010 return _target.beginToken;
7036 } else if (operator != null) { 7011 } else if (operator != null) {
7037 return operator; 7012 return operator;
7038 } 7013 }
7039 return _methodName.beginToken; 7014 return _methodName.beginToken;
7040 } 7015 }
7041 7016
7042 @override 7017 @override
7043 Iterable get childEntities => new ChildEntities() 7018 Iterable get childEntities => new ChildEntities()
7044 ..add(_target) 7019 ..add(_target)
7045 ..add(operator) 7020 ..add(operator)
7046 ..add(_methodName) 7021 ..add(_methodName)
7047 ..add(_argumentList); 7022 ..add(_argumentList);
7048 7023
7049 @override 7024 @override
7050 Token get endToken => _argumentList.endToken; 7025 Token get endToken => _argumentList.endToken;
7051 7026
7052 @override 7027 @override
7028 Expression get invocationTarget => methodName;
7029
7030 @override
7053 bool get isCascaded => 7031 bool get isCascaded =>
7054 operator != null && operator.type == TokenType.PERIOD_PERIOD; 7032 operator != null && operator.type == TokenType.PERIOD_PERIOD;
7055 7033
7056 @override 7034 @override
7057 SimpleIdentifier get methodName => _methodName; 7035 SimpleIdentifier get methodName => _methodName;
7058 7036
7059 @override 7037 @override
7060 void set methodName(SimpleIdentifier identifier) { 7038 void set methodName(SimpleIdentifier identifier) {
7061 _methodName = _becomeParentOf(identifier); 7039 _methodName = _becomeParentOf(identifier);
7062 } 7040 }
(...skipping 18 matching lines...) Expand all
7081 7059
7082 @override 7060 @override
7083 Expression get target => _target; 7061 Expression get target => _target;
7084 7062
7085 @override 7063 @override
7086 void set target(Expression expression) { 7064 void set target(Expression expression) {
7087 _target = _becomeParentOf(expression); 7065 _target = _becomeParentOf(expression);
7088 } 7066 }
7089 7067
7090 @override 7068 @override
7091 TypeArgumentList get typeArguments => _typeArguments;
7092
7093 @override
7094 void set typeArguments(TypeArgumentList typeArguments) {
7095 _typeArguments = _becomeParentOf(typeArguments);
7096 }
7097
7098 @override
7099 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this); 7069 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this);
7100 7070
7101 @override 7071 @override
7102 void visitChildren(AstVisitor visitor) { 7072 void visitChildren(AstVisitor visitor) {
7103 _safelyVisitChild(_target, visitor); 7073 _safelyVisitChild(_target, visitor);
7104 _safelyVisitChild(_methodName, visitor); 7074 _safelyVisitChild(_methodName, visitor);
7105 _safelyVisitChild(_typeArguments, visitor); 7075 _safelyVisitChild(_typeArguments, visitor);
7106 _safelyVisitChild(_argumentList, visitor); 7076 _safelyVisitChild(_argumentList, visitor);
7107 } 7077 }
7108 } 7078 }
(...skipping 3739 matching lines...) Expand 10 before | Expand all | Expand 10 after
10848 } 10818 }
10849 10819
10850 @override 10820 @override
10851 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); 10821 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
10852 10822
10853 @override 10823 @override
10854 void visitChildren(AstVisitor visitor) { 10824 void visitChildren(AstVisitor visitor) {
10855 _safelyVisitChild(_expression, visitor); 10825 _safelyVisitChild(_expression, visitor);
10856 } 10826 }
10857 } 10827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698