@@ -37,7 +37,7 @@ import 'type_schema_environment.dart';
37
37
/// Concrete class derived from [InferenceNode] to represent type inference of a
38
38
/// field based on its initializer.
39
39
class FieldInitializerInferenceNode extends InferenceNode {
40
- final TypeInferenceEngineImpl _typeInferenceEngine;
40
+ final TypeInferenceEngine _typeInferenceEngine;
41
41
42
42
/// The field whose type should be inferred.
43
43
final ShadowField field;
@@ -200,16 +200,24 @@ abstract class InferenceNode {
200
200
/// (e.g. DietListener). Derived classes should derive from
201
201
/// [TypeInferenceEngineImpl] .
202
202
abstract class TypeInferenceEngine {
203
- ClassHierarchy get classHierarchy;
204
-
205
- void set classHierarchy (ClassHierarchy classHierarchy);
203
+ ClassHierarchy classHierarchy;
206
204
207
- CoreTypes get coreTypes;
205
+ CoreTypes coreTypes;
208
206
209
207
/// Indicates whether the "prepare" phase of type inference is complete.
210
- void set isTypeInferencePrepared (bool value);
208
+ bool isTypeInferencePrepared = false ;
209
+
210
+ TypeSchemaEnvironment typeSchemaEnvironment;
211
+
212
+ final staticInferenceNodes = < FieldInitializerInferenceNode > [];
213
+
214
+ final initializingFormals = < ShadowVariableDeclaration > [];
215
+
216
+ final Instrumentation instrumentation;
217
+
218
+ final bool strongMode;
211
219
212
- TypeSchemaEnvironment get typeSchemaEnvironment ;
220
+ TypeInferenceEngine ( this .instrumentation, this .strongMode) ;
213
221
214
222
/// Creates a disabled type inferrer (intended for debugging and profiling
215
223
/// only).
@@ -225,66 +233,23 @@ abstract class TypeInferenceEngine {
225
233
TypeInferrer createTopLevelTypeInferrer (
226
234
InterfaceType thisType, ShadowField field);
227
235
236
+ /// Retrieve the [TypeInferrer] for the given [field] , which was created by
237
+ /// a previous call to [createTopLevelTypeInferrer] .
238
+ TypeInferrerImpl getFieldTypeInferrer (ShadowField field);
239
+
228
240
/// Performs the second phase of top level initializer inference, which is to
229
241
/// visit all accessors and top level variables that were passed to
230
242
/// [recordAccessor] in topologically-sorted order and assign their types.
231
- void finishTopLevelFields ();
232
-
233
- /// Performs the third phase of top level inference, which is to visit all
234
- /// initializing formals and infer their types (if necessary) from the
235
- /// corresponding fields.
236
- void finishTopLevelInitializingFormals ();
237
-
238
- /// Gets ready to do top level type inference for the component having the
239
- /// given [hierarchy] , using the given [coreTypes] .
240
- void prepareTopLevel (CoreTypes coreTypes, ClassHierarchy hierarchy);
241
-
242
- /// Records that the given initializing [formal] will need top level type
243
- /// inference.
244
- void recordInitializingFormal (ShadowVariableDeclaration formal);
245
-
246
- /// Records that the given static [field] will need top level type inference.
247
- void recordStaticFieldInferenceCandidate (
248
- ShadowField field, LibraryBuilder library);
249
- }
250
-
251
- /// Derived class containing generic implementations of
252
- /// [TypeInferenceEngineImpl] .
253
- ///
254
- /// This class contains as much of the implementation of type inference as
255
- /// possible without knowing the identity of the type parameter. It defers to
256
- /// abstract methods for everything else.
257
- abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
258
- final Instrumentation instrumentation;
259
-
260
- final bool strongMode;
261
-
262
- final staticInferenceNodes = < FieldInitializerInferenceNode > [];
263
-
264
- final initializingFormals = < ShadowVariableDeclaration > [];
265
-
266
- @override
267
- CoreTypes coreTypes;
268
-
269
- @override
270
- ClassHierarchy classHierarchy;
271
-
272
- TypeSchemaEnvironment typeSchemaEnvironment;
273
-
274
- @override
275
- bool isTypeInferencePrepared = false ;
276
-
277
- TypeInferenceEngineImpl (this .instrumentation, this .strongMode);
278
-
279
- @override
280
243
void finishTopLevelFields () {
281
244
for (var node in staticInferenceNodes) {
282
245
node.resolve ();
283
246
}
284
247
staticInferenceNodes.clear ();
285
248
}
286
249
287
- @override
250
+ /// Performs the third phase of top level inference, which is to visit all
251
+ /// initializing formals and infer their types (if necessary) from the
252
+ /// corresponding fields.
288
253
void finishTopLevelInitializingFormals () {
289
254
for (ShadowVariableDeclaration formal in initializingFormals) {
290
255
try {
@@ -300,23 +265,22 @@ abstract class TypeInferenceEngineImpl extends TypeInferenceEngine {
300
265
}
301
266
}
302
267
303
- /// Retrieve the [TypeInferrer] for the given [field] , which was created by
304
- /// a previous call to [createTopLevelTypeInferrer] .
305
- TypeInferrerImpl getFieldTypeInferrer (ShadowField field);
306
-
307
- @override
268
+ /// Gets ready to do top level type inference for the component having the
269
+ /// given [hierarchy] , using the given [coreTypes] .
308
270
void prepareTopLevel (CoreTypes coreTypes, ClassHierarchy hierarchy) {
309
271
this .coreTypes = coreTypes;
310
272
this .classHierarchy = hierarchy;
311
273
this .typeSchemaEnvironment =
312
274
new TypeSchemaEnvironment (coreTypes, hierarchy, strongMode);
313
275
}
314
276
315
- @override
277
+ /// Records that the given initializing [formal] will need top level type
278
+ /// inference.
316
279
void recordInitializingFormal (ShadowVariableDeclaration formal) {
317
280
initializingFormals.add (formal);
318
281
}
319
282
283
+ /// Records that the given static [field] will need top level type inference.
320
284
void recordStaticFieldInferenceCandidate (
321
285
ShadowField field, LibraryBuilder library) {
322
286
var node = new FieldInitializerInferenceNode (this , field, library);
0 commit comments