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

Unified Diff: lib/src/codegen/reify_coercions.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/codegen/reify_coercions.dart
diff --git a/lib/src/codegen/reify_coercions.dart b/lib/src/codegen/reify_coercions.dart
index fbedd451b83c84aeddc04820fb19284ee34ce818..3ee5335a6f9a194b300b487ccc5c7063a6956667 100644
--- a/lib/src/codegen/reify_coercions.dart
+++ b/lib/src/codegen/reify_coercions.dart
@@ -33,6 +33,38 @@ class _LocatedWrapper {
_LocatedWrapper(this.wrapper, this.loc);
}
+class _Inference extends DownwardsInference {
+ TypeManager _tm;
+
+ _Inference(TypeRules rules, this._tm) : super(rules);
+
+ @override
+ void annotateListLiteral(ListLiteral e, List<DartType> targs) {
+ var tNames = targs.map(_tm.typeNameFromDartType).toList();
+ e.typeArguments = AstBuilder.typeArgumentList(tNames);
+ var listT = rules.provider.listType.substitute4(targs);
+ e.staticType = listT;
+ }
+
+ @override
+ void annotateMapLiteral(MapLiteral e, List<DartType> targs) {
+ var tNames = targs.map(_tm.typeNameFromDartType).toList();
+ e.typeArguments = AstBuilder.typeArgumentList(tNames);
+ var mapT = rules.provider.mapType.substitute4(targs);
+ e.staticType = mapT;
+ }
+
+ @override
+ void annotateInstanceCreationExpression(
+ InstanceCreationExpression e, List<DartType> targs) {
+ var tNames = targs.map(_tm.typeNameFromDartType).toList();
+ var cName = e.constructorName;
+ var id = cName.type.name;
+ var typeName = AstBuilder.typeName(id, tNames);
+ cName.type = typeName;
vsm 2015/03/27 21:20:59 Does e.staticType require updating?
Leaf 2015/03/30 23:26:00 Done.
+ }
+}
+
// This class implements a pass which modifies (in place) the ast replacing
// abstract coercion nodes with their dart implementations.
class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
@@ -43,9 +75,11 @@ class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
SourceFile _file;
bool _skipCoercions = false;
final TypeRules _rules;
+ _Inference _inferrer;
UnitCoercionReifier(this._tm, this._vm, this._rules) {
_cm = new CoercionManager(_vm, _tm, _rules);
+ _inferrer = new _Inference(_rules, _tm);
}
// This should be the entry point for this class. Entering via the
@@ -101,6 +135,22 @@ class UnitCoercionReifier extends analyzer.GeneralizingAstVisitor<Object>
}
@override
+ Object visitInferredTypeBase(InferredTypeBase node) {
+ var expr = node.node;
+ var b = _inferrer.inferExpression(expr, node.type);
+ if (!b) {
+ print("Expression is $expr : ${node.type}");
+ _inferrer.inferExpression(expr, node.type);
+ }
+ assert(b);
+ if (!NodeReplacer.replace(node, expr)) {
+ _log.severe("Failed to replace node for InferredType");
+ }
+ expr.accept(this);
+ return null;
+ }
+
+ @override
Object visitDownCast(DownCast node) {
if (_skipCoercions) {
_log.severe("Skipping runtime downcast in constant context");

Powered by Google App Engine
This is Rietveld 408576698