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

Unified Diff: pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart

Issue 2823243002: Introduce initial plumbing for type inference in fasta. (Closed)
Patch Set: Created 3 years, 8 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: pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e5f6a8bee5838edcffa88690ebd4413afc42cf6d
--- /dev/null
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE.md file.
+
+import 'package:kernel/ast.dart';
ahe 2017/04/18 15:49:59 May want to use show on this import to be explicit
Paul Berry 2017/04/18 16:33:17 Done.
+import 'package:kernel/class_hierarchy.dart';
+import 'package:kernel/core_types.dart';
+
+/// Abstract implementation of type inference which is independent of the
+/// underlying AST representation.
ahe 2017/04/18 15:49:59 But still using DartType from kernel?
Paul Berry 2017/04/18 16:33:17 Yes, for now at least. I don't know if this will
+///
+/// Derived classes should set S, E, V, and F to the class they use to represent
+/// statements, expressions, variable declarations, and field declarations,
+/// respectively.
+abstract class TypeInferrer<S, E, V, F> {
+ final CoreTypes coreTypes;
+
+ final ClassHierarchy classHierarchy;
+
+ /// The URI of the code for which type inference is currently being
+ /// performed--this is used for testing.
+ Uri uri;
+
+ TypeInferrer(this.coreTypes, this.classHierarchy);
+
+ /// Performs type inference on a method with the given method [body].
+ ///
+ /// [uri] is the URI of the file the method is contained in--this is used for
+ /// testing.
+ void inferBody(S body, Uri uri) {
+ this.uri = uri;
+ inferStatement(body);
+ }
+
+ /// Performs type inference on the given [expression].
+ ///
+ /// [typeContext] is the expected type of the expression, based on surrounding
+ /// code. [typeNeeded] indicates whether it is necessary to compute the
+ /// actual type of the expression. If [typeNeeded] is `true`, the actual type
+ /// of the expression is returned; otherwise `null` is returned.
+ ///
+ /// Derived classes should override this method with logic that dispatches on
+ /// the expression type and calls the appropriate specialized "infer" method.
+ DartType inferExpression(E expression, DartType typeContext, bool typeNeeded);
+
+ /// Performs type inference on the given [statement].
+ ///
+ /// Derived classes should override this method with logic that dispatches on
+ /// the statement type and calls the appropriate specialized "infer" method.
+ void inferStatement(S statement);
+}

Powered by Google App Engine
This is Rietveld 408576698