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

Unified Diff: lib/src/info.dart

Issue 1038213003: Downward inference (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: Small fixes Created 5 years, 9 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
Index: lib/src/info.dart
diff --git a/lib/src/info.dart b/lib/src/info.dart
index f1cb2d71ea31cd995d9bce053c8620c966d69f96..2923771d50b176eaf8449abb8519287c5e8a6295 100644
--- a/lib/src/info.dart
+++ b/lib/src/info.dart
@@ -361,6 +361,63 @@ class DownCastImplicit extends DownCast {
final Level level = Level.WARNING;
}
+// An inferred type for the wrapped expression, which may need to be
+// reified into the term
+abstract class InferredTypeBase extends Conversion {
+ DartType _type;
+
+ InferredTypeBase._internal(TypeRules rules, Expression expression, this._type)
+ : super(rules, expression);
+
+ DartType get type => _type;
+
+ DartType _getConvertedType() => type;
+
+ String get message => '$expression has inferred type $type';
+
+ Level get level => Level.INFO;
+
+ accept(AstVisitor visitor) {
+ if (visitor is ConversionVisitor) {
+ return visitor.visitInferredTypeBase(this);
+ } else {
+ return expression.accept(visitor);
+ }
+ }
+}
+
+// Standard / unspecialized inferred type
+class InferredType extends InferredTypeBase {
+ InferredType(TypeRules rules, Expression expression, DartType type)
+ : super._internal(rules, expression, type);
+
+ // Factory to create correct InferredType variant.
+ static InferredTypeBase create(
+ TypeRules rules, Expression expression, DartType type) {
+
+ // Specialized inference:
+ if (expression is Literal) {
+ return new InferredTypeLiteral(rules, expression, type);
+ }
+ if (expression is InstanceCreationExpression) {
+ return new InferredTypeExact(rules, expression, type);
+ }
+ return new InferredType(rules, expression, type);
+ }
+}
+
+// An infered type for a literal expression.
+class InferredTypeLiteral extends InferredTypeBase {
+ InferredTypeLiteral(TypeRules rules, Expression expression, DartType type)
+ : super._internal(rules, expression, type);
+}
+
+// An inferred type for a non-literal allocation site.
+class InferredTypeExact extends InferredTypeBase {
vsm 2015/03/27 21:20:59 Perhaps call this InferredTypeAllocation for clari
Leaf 2015/03/30 23:26:00 Done.
+ InferredTypeExact(TypeRules rules, Expression expression, DartType type)
+ : super._internal(rules, expression, type);
+}
+
// TODO(vsm): Remove these.
// A wrapped closure coerces the underlying type to the desired type.
@@ -657,6 +714,7 @@ abstract class ConversionVisitor<R> implements AstVisitor<R> {
R visitClosureWrapBase(ClosureWrapBase node) => visitConversion(node);
R visitClosureWrap(ClosureWrap node) => visitClosureWrapBase(node);
R visitDynamicInvoke(DynamicInvoke node) => visitConversion(node);
+ R visitInferredTypeBase(InferredTypeBase node) => visitConversion(node);
}
/// Automatically infer list of types by scanning this library using mirrors.

Powered by Google App Engine
This is Rietveld 408576698