Index: pkg/front_end/lib/src/fasta/type_inference/local_type_inferrer.dart |
diff --git a/pkg/front_end/lib/src/fasta/type_inference/local_type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/local_type_inferrer.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b8e2a4beff1b1f1956eb87d94a77f0db98d2b334 |
--- /dev/null |
+++ b/pkg/front_end/lib/src/fasta/type_inference/local_type_inferrer.dart |
@@ -0,0 +1,82 @@ |
+import 'package:kernel/ast.dart' show DartType; |
+ |
+import 'package:kernel/core_types.dart'; |
+ |
+import '../builder/shadow_ast.dart'; |
+ |
+class LocalTypeInferrer { |
+ final CoreTypes coreTypes; |
+ |
+ LocalTypeInferrer(this.coreTypes); |
+ |
+ void finishVariableDeclaration( |
+ DartType type, Expression initializer, VariableDeclaration variable) { |
+ // TODO(paulberry): is this needed at all? |
+ // throw new UnimplementedError(); |
+ } |
+ |
+ void recordReturnStatement(OldFunctionContext function, Expression expr) { |
+ function?._returnExpressions?.add(expr); |
+ } |
+ |
+ OldFunctionContext nestFunctionContext(OldFunctionContext outer) { |
+ return new OldFunctionContext(); |
+ } |
+ |
+ void inferBody(Statement statement) { |
+ statement.shadowInfer(this, null); |
+ } |
+ |
+ DartType union(DartType a, DartType b) { |
+ if (a == null) return b; |
+ throw new UnimplementedError(); |
+ } |
+} |
+ |
+class FunctionContext { |
+ final LocalTypeInferrer inferrer; |
+ |
+ final bool returnTypeNeeded; |
+ |
+ final bool isAsync; |
+ |
+ final bool isGenerator; |
+ |
+ DartType _inferredReturnType; |
+ |
+ FunctionContext( |
+ this.inferrer, this.returnTypeNeeded, this.isAsync, this.isGenerator); |
+ |
+ get inferredReturnType { |
+ if (_inferredReturnType == null) { |
+ // No return statement found. |
+ throw new UnimplementedError(); |
+ } |
+ return _inferredReturnType; |
+ } |
+ |
+ void recordReturnType(DartType type) { |
+ _inferredReturnType = inferrer.union(_inferredReturnType, type); |
+ } |
+} |
+ |
+/// TODO(paulberry): is this needed at all? |
+class OldFunctionContext { |
+ var _returnExpressions = <Expression>[]; |
+ |
+ List<VariableDeclaration> _positionalFormals; |
+ |
+ bool _isAsync = false; |
+ |
+ void recordAsyncModifier(bool isAsync) { |
+ _isAsync = isAsync; |
+ } |
+ |
+ void recordFormals( |
+ int requiredParameterCount, |
+ List<VariableDeclaration> positionalFormals, |
+ List<VariableDeclaration> namedFormals) { |
+ // TODO(paulberry): handle requiredParameterCount and namedFormals. |
+ _positionalFormals = positionalFormals; |
+ } |
+} |