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

Unified Diff: pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Issue 1953043002: Extract 'refineBinaryExpressionType' into TypeSystem. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 7eb4a8b67662448779d2aef9da7683a18964a28d..fefd3ebca75ef140371cec76fc2601ee7985cce1 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -341,14 +341,23 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
ExecutableElement staticMethodElement = node.staticElement;
DartType staticType = _computeStaticReturnType(staticMethodElement);
- staticType = _refineBinaryExpressionType(node, staticType, _getStaticType);
+ staticType = _typeSystem.refineBinaryExpressionType(
+ _typeProvider,
+ node.leftOperand.staticType,
+ node.operator.type,
+ node.rightOperand.staticType,
+ staticType);
_recordStaticType(node, staticType);
MethodElement propagatedMethodElement = node.propagatedElement;
if (!identical(propagatedMethodElement, staticMethodElement)) {
DartType propagatedType =
_computeStaticReturnType(propagatedMethodElement);
- propagatedType =
- _refineBinaryExpressionType(node, propagatedType, _getBestType);
+ propagatedType = _typeSystem.refineBinaryExpressionType(
+ _typeProvider,
+ node.leftOperand.bestType,
+ node.operator.type,
+ node.rightOperand.bestType,
+ propagatedType);
_resolver.recordPropagatedTypeIfBetter(node, propagatedType);
}
return null;
@@ -1634,13 +1643,6 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
/**
- * Return the best type of the given [expression].
- */
- DartType _getBestType(Expression expression) {
- return expression.bestType;
- }
-
- /**
* If the given element name can be mapped to the name of a class defined within the given
* library, return the type specified by the argument.
*
@@ -2178,50 +2180,6 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
/**
- * Attempts to make a better guess for the type of the given binary
- * [expression], given that resolution has so far produced the [currentType].
- * The [typeAccessor] is used to access the corresponding type of the left
- * and right operands.
- */
- DartType _refineBinaryExpressionType(
- BinaryExpression expression, DartType currentType,
- [DartType typeAccessor(Expression node)]) {
- TokenType operator = expression.operator.type;
- // bool
- if (operator == TokenType.AMPERSAND_AMPERSAND ||
- operator == TokenType.BAR_BAR ||
- operator == TokenType.EQ_EQ ||
- operator == TokenType.BANG_EQ) {
- return _typeProvider.boolType;
- }
- DartType intType = _typeProvider.intType;
- if (typeAccessor(expression.leftOperand) == intType) {
- // int op double
- if (operator == TokenType.MINUS ||
- operator == TokenType.PERCENT ||
- operator == TokenType.PLUS ||
- operator == TokenType.STAR) {
- DartType doubleType = _typeProvider.doubleType;
- if (typeAccessor(expression.rightOperand) == doubleType) {
- return doubleType;
- }
- }
- // int op int
- if (operator == TokenType.MINUS ||
- operator == TokenType.PERCENT ||
- operator == TokenType.PLUS ||
- operator == TokenType.STAR ||
- operator == TokenType.TILDE_SLASH) {
- if (typeAccessor(expression.rightOperand) == intType) {
- return intType;
- }
- }
- }
- // default
- return currentType;
- }
-
- /**
* Create a table mapping HTML tag names to the names of the classes (in 'dart:html') that
* implement those tags.
*
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698