| OLD | NEW |
| 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 3912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3923 bool _enclosingBlockContainsBreak = false; | 3923 bool _enclosingBlockContainsBreak = false; |
| 3924 | 3924 |
| 3925 @override | 3925 @override |
| 3926 bool visitArgumentList(ArgumentList node) => | 3926 bool visitArgumentList(ArgumentList node) => |
| 3927 _visitExpressions(node.arguments); | 3927 _visitExpressions(node.arguments); |
| 3928 | 3928 |
| 3929 @override | 3929 @override |
| 3930 bool visitAsExpression(AsExpression node) => _nodeExits(node.expression); | 3930 bool visitAsExpression(AsExpression node) => _nodeExits(node.expression); |
| 3931 | 3931 |
| 3932 @override | 3932 @override |
| 3933 bool visitAssertStatement(AssertStatement node) => _nodeExits(node.condition); | 3933 bool visitAssertStatement(AssertStatement node) => false; |
| 3934 | 3934 |
| 3935 @override | 3935 @override |
| 3936 bool visitAssignmentExpression(AssignmentExpression node) => | 3936 bool visitAssignmentExpression(AssignmentExpression node) { |
| 3937 _nodeExits(node.leftHandSide) || _nodeExits(node.rightHandSide); | 3937 Expression leftHandSide = node.leftHandSide; |
| 3938 if (_nodeExits(leftHandSide)) { |
| 3939 return true; |
| 3940 } |
| 3941 if (node.operator.type == sc.TokenType.QUESTION_QUESTION_EQ) { |
| 3942 return false; |
| 3943 } |
| 3944 if (leftHandSide is PropertyAccess && |
| 3945 leftHandSide.operator.type == sc.TokenType.QUESTION_PERIOD) { |
| 3946 return false; |
| 3947 } |
| 3948 return _nodeExits(node.rightHandSide); |
| 3949 } |
| 3938 | 3950 |
| 3939 @override | 3951 @override |
| 3940 bool visitAwaitExpression(AwaitExpression node) => | 3952 bool visitAwaitExpression(AwaitExpression node) => |
| 3941 _nodeExits(node.expression); | 3953 _nodeExits(node.expression); |
| 3942 | 3954 |
| 3943 @override | 3955 @override |
| 3944 bool visitBinaryExpression(BinaryExpression node) { | 3956 bool visitBinaryExpression(BinaryExpression node) { |
| 3945 Expression lhsExpression = node.leftOperand; | 3957 Expression lhsExpression = node.leftOperand; |
| 3958 Expression rhsExpression = node.rightOperand; |
| 3946 sc.TokenType operatorType = node.operator.type; | 3959 sc.TokenType operatorType = node.operator.type; |
| 3947 // If the operator is || and the left hand side is false literal, don't | 3960 // If the operator is ||, then only consider the RHS of the binary |
| 3948 // consider the RHS of the binary expression. | 3961 // expression if the left hand side is the false literal. |
| 3949 // TODO(jwren) Do we want to take constant expressions into account, | 3962 // TODO(jwren) Do we want to take constant expressions into account, |
| 3950 // evaluate if(false) {} differently than if(<condition>), when <condition> | 3963 // evaluate if(false) {} differently than if(<condition>), when <condition> |
| 3951 // evaluates to a constant false value? | 3964 // evaluates to a constant false value? |
| 3952 if (operatorType == sc.TokenType.BAR_BAR) { | 3965 if (operatorType == sc.TokenType.BAR_BAR) { |
| 3953 if (lhsExpression is BooleanLiteral) { | 3966 if (lhsExpression is BooleanLiteral) { |
| 3954 BooleanLiteral booleanLiteral = lhsExpression; | 3967 BooleanLiteral booleanLiteral = lhsExpression; |
| 3955 if (!booleanLiteral.value) { | 3968 if (!booleanLiteral.value) { |
| 3956 return false; | 3969 return _nodeExits(rhsExpression); |
| 3957 } | 3970 } |
| 3958 } | 3971 } |
| 3972 return _nodeExits(lhsExpression); |
| 3959 } | 3973 } |
| 3960 // If the operator is && and the left hand side is true literal, don't | 3974 // If the operator is &&, then only consider the RHS of the binary |
| 3961 // consider the RHS of the binary expression. | 3975 // expression if the left hand side is the true literal. |
| 3962 if (operatorType == sc.TokenType.AMPERSAND_AMPERSAND) { | 3976 if (operatorType == sc.TokenType.AMPERSAND_AMPERSAND) { |
| 3963 if (lhsExpression is BooleanLiteral) { | 3977 if (lhsExpression is BooleanLiteral) { |
| 3964 BooleanLiteral booleanLiteral = lhsExpression; | 3978 BooleanLiteral booleanLiteral = lhsExpression; |
| 3965 if (booleanLiteral.value) { | 3979 if (booleanLiteral.value) { |
| 3966 return false; | 3980 return _nodeExits(rhsExpression); |
| 3967 } | 3981 } |
| 3968 } | 3982 } |
| 3983 return _nodeExits(lhsExpression); |
| 3969 } | 3984 } |
| 3970 Expression rhsExpression = node.rightOperand; | 3985 // If the operator is ??, then don't consider the RHS of the binary |
| 3986 // expression. |
| 3987 if (operatorType == sc.TokenType.QUESTION_QUESTION) { |
| 3988 return _nodeExits(lhsExpression); |
| 3989 } |
| 3971 return _nodeExits(lhsExpression) || _nodeExits(rhsExpression); | 3990 return _nodeExits(lhsExpression) || _nodeExits(rhsExpression); |
| 3972 } | 3991 } |
| 3973 | 3992 |
| 3974 @override | 3993 @override |
| 3975 bool visitBlock(Block node) => _visitStatements(node.statements); | 3994 bool visitBlock(Block node) => _visitStatements(node.statements); |
| 3976 | 3995 |
| 3977 @override | 3996 @override |
| 3978 bool visitBlockFunctionBody(BlockFunctionBody node) => _nodeExits(node.block); | 3997 bool visitBlockFunctionBody(BlockFunctionBody node) => _nodeExits(node.block); |
| 3979 | 3998 |
| 3980 @override | 3999 @override |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4155 @override | 4174 @override |
| 4156 bool visitLabeledStatement(LabeledStatement node) => | 4175 bool visitLabeledStatement(LabeledStatement node) => |
| 4157 node.statement.accept(this); | 4176 node.statement.accept(this); |
| 4158 | 4177 |
| 4159 @override | 4178 @override |
| 4160 bool visitLiteral(Literal node) => false; | 4179 bool visitLiteral(Literal node) => false; |
| 4161 | 4180 |
| 4162 @override | 4181 @override |
| 4163 bool visitMethodInvocation(MethodInvocation node) { | 4182 bool visitMethodInvocation(MethodInvocation node) { |
| 4164 Expression target = node.realTarget; | 4183 Expression target = node.realTarget; |
| 4165 if (target != null && target.accept(this)) { | 4184 if (target != null) { |
| 4166 return true; | 4185 if (target.accept(this)) { |
| 4186 return true; |
| 4187 } |
| 4188 if (node.operator.type == sc.TokenType.QUESTION_PERIOD) { |
| 4189 return false; |
| 4190 } |
| 4167 } | 4191 } |
| 4168 return _nodeExits(node.argumentList); | 4192 return _nodeExits(node.argumentList); |
| 4169 } | 4193 } |
| 4170 | 4194 |
| 4171 @override | 4195 @override |
| 4172 bool visitNamedExpression(NamedExpression node) => | 4196 bool visitNamedExpression(NamedExpression node) => |
| 4173 node.expression.accept(this); | 4197 node.expression.accept(this); |
| 4174 | 4198 |
| 4175 @override | 4199 @override |
| 4176 bool visitParenthesizedExpression(ParenthesizedExpression node) => | 4200 bool visitParenthesizedExpression(ParenthesizedExpression node) => |
| (...skipping 11212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15389 nonFields.add(node); | 15413 nonFields.add(node); |
| 15390 return null; | 15414 return null; |
| 15391 } | 15415 } |
| 15392 | 15416 |
| 15393 @override | 15417 @override |
| 15394 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15418 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15395 | 15419 |
| 15396 @override | 15420 @override |
| 15397 Object visitWithClause(WithClause node) => null; | 15421 Object visitWithClause(WithClause node) => null; |
| 15398 } | 15422 } |
| OLD | NEW |