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

Unified Diff: pkg/analyzer/lib/src/generated/type_system.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 | « pkg/analyzer/lib/src/generated/static_type_analyzer.dart ('k') | pkg/analyzer/lib/src/summary/link.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/type_system.dart
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index 526d067050019423bc75cbd3b3776501636d082f..426bd4c2c1d035b26b45b9d4bd99553d21a86d13 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -7,6 +7,7 @@ library analyzer.src.generated.type_system;
import 'dart:collection';
import 'dart:math' as math;
+import 'package:analyzer/dart/ast/token.dart' show TokenType;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/element.dart';
@@ -942,6 +943,50 @@ abstract class TypeSystem {
}
/**
+ * Attempts to make a better guess for the type of a binary with the given
+ * [operator], given that resolution has so far produced the [currentType].
+ */
+ DartType refineBinaryExpressionType(
+ TypeProvider typeProvider,
+ DartType leftType,
+ TokenType operator,
+ DartType rightType,
+ DartType currentType) {
+ // 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 (leftType == intType) {
+ // int op double
+ if (operator == TokenType.MINUS ||
+ operator == TokenType.PERCENT ||
+ operator == TokenType.PLUS ||
+ operator == TokenType.STAR) {
+ DartType doubleType = typeProvider.doubleType;
+ if (rightType == doubleType) {
+ return doubleType;
+ }
+ }
+ // int op int
+ if (operator == TokenType.MINUS ||
+ operator == TokenType.PERCENT ||
+ operator == TokenType.PLUS ||
+ operator == TokenType.STAR ||
+ operator == TokenType.TILDE_SLASH) {
+ if (rightType == intType) {
+ return intType;
+ }
+ }
+ }
+ // default
+ return currentType;
+ }
+
+ /**
* Given a [DartType] type, return the [TypeParameterElement]s corresponding
* to its formal type parameters (if any).
*
« no previous file with comments | « pkg/analyzer/lib/src/generated/static_type_analyzer.dart ('k') | pkg/analyzer/lib/src/summary/link.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698