| 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:math" as math; | 7 import "dart:math" as math; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| (...skipping 10491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10502 /** | 10502 /** |
| 10503 * If it is appropriate to do so, override the current type of the static and
propagated elements | 10503 * If it is appropriate to do so, override the current type of the static and
propagated elements |
| 10504 * associated with the given expression with the given type. Generally speakin
g, it is appropriate | 10504 * associated with the given expression with the given type. Generally speakin
g, it is appropriate |
| 10505 * if the given type is more specific than the current type. | 10505 * if the given type is more specific than the current type. |
| 10506 * | 10506 * |
| 10507 * @param expression the expression used to access the static and propagated e
lements whose types | 10507 * @param expression the expression used to access the static and propagated e
lements whose types |
| 10508 * might be overridden | 10508 * might be overridden |
| 10509 * @param potentialType the potential type of the elements | 10509 * @param potentialType the potential type of the elements |
| 10510 * @param allowPrecisionLoss see @{code overrideVariable} docs | 10510 * @param allowPrecisionLoss see @{code overrideVariable} docs |
| 10511 */ | 10511 */ |
| 10512 void overrideExpression( | 10512 void overrideExpression(Expression expression, DartType potentialType, |
| 10513 Expression expression, DartType potentialType, bool allowPrecisionLoss) { | 10513 bool allowPrecisionLoss, bool setExpressionType) { |
| 10514 VariableElement element = getOverridableStaticElement(expression); | 10514 VariableElement element = getOverridableStaticElement(expression); |
| 10515 if (element != null) { | 10515 if (element != null) { |
| 10516 DartType newBestType = | 10516 DartType newBestType = |
| 10517 overrideVariable(element, potentialType, allowPrecisionLoss); | 10517 overrideVariable(element, potentialType, allowPrecisionLoss); |
| 10518 recordPropagatedTypeIfBetter(expression, newBestType); | 10518 if (setExpressionType) { |
| 10519 recordPropagatedTypeIfBetter(expression, newBestType); |
| 10520 } |
| 10519 } | 10521 } |
| 10520 element = getOverridablePropagatedElement(expression); | 10522 element = getOverridablePropagatedElement(expression); |
| 10521 if (element != null) { | 10523 if (element != null) { |
| 10522 overrideVariable(element, potentialType, allowPrecisionLoss); | 10524 overrideVariable(element, potentialType, allowPrecisionLoss); |
| 10523 } | 10525 } |
| 10524 } | 10526 } |
| 10525 | 10527 |
| 10526 /** | 10528 /** |
| 10527 * If it is appropriate to do so, override the current type of the given eleme
nt with the given | 10529 * If it is appropriate to do so, override the current type of the given eleme
nt with the given |
| 10528 * type. | 10530 * type. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10631 } | 10633 } |
| 10632 return super.visitAnnotation(node); | 10634 return super.visitAnnotation(node); |
| 10633 } | 10635 } |
| 10634 | 10636 |
| 10635 @override | 10637 @override |
| 10636 Object visitAsExpression(AsExpression node) { | 10638 Object visitAsExpression(AsExpression node) { |
| 10637 super.visitAsExpression(node); | 10639 super.visitAsExpression(node); |
| 10638 // Since an as-statement doesn't actually change the type, we don't | 10640 // Since an as-statement doesn't actually change the type, we don't |
| 10639 // let it affect the propagated type when it would result in a loss | 10641 // let it affect the propagated type when it would result in a loss |
| 10640 // of precision. | 10642 // of precision. |
| 10641 overrideExpression(node.expression, node.type.type, false); | 10643 overrideExpression(node.expression, node.type.type, false, false); |
| 10642 return null; | 10644 return null; |
| 10643 } | 10645 } |
| 10644 | 10646 |
| 10645 @override | 10647 @override |
| 10646 Object visitAssertStatement(AssertStatement node) { | 10648 Object visitAssertStatement(AssertStatement node) { |
| 10647 super.visitAssertStatement(node); | 10649 super.visitAssertStatement(node); |
| 10648 _propagateTrueState(node.condition); | 10650 _propagateTrueState(node.condition); |
| 10649 return null; | 10651 return null; |
| 10650 } | 10652 } |
| 10651 | 10653 |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11696 if (binary.operator.type == sc.TokenType.BAR_BAR) { | 11698 if (binary.operator.type == sc.TokenType.BAR_BAR) { |
| 11697 _propagateFalseState(binary.leftOperand); | 11699 _propagateFalseState(binary.leftOperand); |
| 11698 _propagateFalseState(binary.rightOperand); | 11700 _propagateFalseState(binary.rightOperand); |
| 11699 } | 11701 } |
| 11700 } else if (condition is IsExpression) { | 11702 } else if (condition is IsExpression) { |
| 11701 IsExpression is2 = condition; | 11703 IsExpression is2 = condition; |
| 11702 if (is2.notOperator != null) { | 11704 if (is2.notOperator != null) { |
| 11703 // Since an is-statement doesn't actually change the type, we don't | 11705 // Since an is-statement doesn't actually change the type, we don't |
| 11704 // let it affect the propagated type when it would result in a loss | 11706 // let it affect the propagated type when it would result in a loss |
| 11705 // of precision. | 11707 // of precision. |
| 11706 overrideExpression(is2.expression, is2.type.type, false); | 11708 overrideExpression(is2.expression, is2.type.type, false, false); |
| 11707 } | 11709 } |
| 11708 } else if (condition is PrefixExpression) { | 11710 } else if (condition is PrefixExpression) { |
| 11709 PrefixExpression prefix = condition; | 11711 PrefixExpression prefix = condition; |
| 11710 if (prefix.operator.type == sc.TokenType.BANG) { | 11712 if (prefix.operator.type == sc.TokenType.BANG) { |
| 11711 _propagateTrueState(prefix.operand); | 11713 _propagateTrueState(prefix.operand); |
| 11712 } | 11714 } |
| 11713 } else if (condition is ParenthesizedExpression) { | 11715 } else if (condition is ParenthesizedExpression) { |
| 11714 _propagateFalseState(condition.expression); | 11716 _propagateFalseState(condition.expression); |
| 11715 } | 11717 } |
| 11716 } | 11718 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 11737 if (binary.operator.type == sc.TokenType.AMPERSAND_AMPERSAND) { | 11739 if (binary.operator.type == sc.TokenType.AMPERSAND_AMPERSAND) { |
| 11738 _propagateTrueState(binary.leftOperand); | 11740 _propagateTrueState(binary.leftOperand); |
| 11739 _propagateTrueState(binary.rightOperand); | 11741 _propagateTrueState(binary.rightOperand); |
| 11740 } | 11742 } |
| 11741 } else if (condition is IsExpression) { | 11743 } else if (condition is IsExpression) { |
| 11742 IsExpression is2 = condition; | 11744 IsExpression is2 = condition; |
| 11743 if (is2.notOperator == null) { | 11745 if (is2.notOperator == null) { |
| 11744 // Since an is-statement doesn't actually change the type, we don't | 11746 // Since an is-statement doesn't actually change the type, we don't |
| 11745 // let it affect the propagated type when it would result in a loss | 11747 // let it affect the propagated type when it would result in a loss |
| 11746 // of precision. | 11748 // of precision. |
| 11747 overrideExpression(is2.expression, is2.type.type, false); | 11749 overrideExpression(is2.expression, is2.type.type, false, false); |
| 11748 } | 11750 } |
| 11749 } else if (condition is PrefixExpression) { | 11751 } else if (condition is PrefixExpression) { |
| 11750 PrefixExpression prefix = condition; | 11752 PrefixExpression prefix = condition; |
| 11751 if (prefix.operator.type == sc.TokenType.BANG) { | 11753 if (prefix.operator.type == sc.TokenType.BANG) { |
| 11752 _propagateFalseState(prefix.operand); | 11754 _propagateFalseState(prefix.operand); |
| 11753 } | 11755 } |
| 11754 } else if (condition is ParenthesizedExpression) { | 11756 } else if (condition is ParenthesizedExpression) { |
| 11755 _propagateTrueState(condition.expression); | 11757 _propagateTrueState(condition.expression); |
| 11756 } | 11758 } |
| 11757 } | 11759 } |
| (...skipping 3712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15470 nonFields.add(node); | 15472 nonFields.add(node); |
| 15471 return null; | 15473 return null; |
| 15472 } | 15474 } |
| 15473 | 15475 |
| 15474 @override | 15476 @override |
| 15475 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15477 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15476 | 15478 |
| 15477 @override | 15479 @override |
| 15478 Object visitWithClause(WithClause node) => null; | 15480 Object visitWithClause(WithClause node) => null; |
| 15479 } | 15481 } |
| OLD | NEW |