| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// This file declares a "shadow hierarchy" of concrete classes which extend | 5 /// This file declares a "shadow hierarchy" of concrete classes which extend |
| 6 /// the kernel class hierarchy, adding methods and fields needed by the | 6 /// the kernel class hierarchy, adding methods and fields needed by the |
| 7 /// BodyBuilder. | 7 /// BodyBuilder. |
| 8 /// | 8 /// |
| 9 /// Instances of these classes may be created using the factory methods in | 9 /// Instances of these classes may be created using the factory methods in |
| 10 /// `ast_factory.dart`. | 10 /// `ast_factory.dart`. |
| 11 /// | 11 /// |
| 12 /// Note that these classes represent the Dart language prior to desugaring. | 12 /// Note that these classes represent the Dart language prior to desugaring. |
| 13 /// When a single Dart construct desugars to a tree containing multiple kernel | 13 /// When a single Dart construct desugars to a tree containing multiple kernel |
| 14 /// AST nodes, the shadow class extends the kernel object at the top of the | 14 /// AST nodes, the shadow class extends the kernel object at the top of the |
| 15 /// desugared tree. | 15 /// desugared tree. |
| 16 /// | 16 /// |
| 17 /// This means that in some cases multiple shadow classes may extend the same | 17 /// This means that in some cases multiple shadow classes may extend the same |
| 18 /// kernel class, because multiple constructs in Dart may desugar to a tree | 18 /// kernel class, because multiple constructs in Dart may desugar to a tree |
| 19 /// with the same kind of root node. | 19 /// with the same kind of root node. |
| 20 import 'package:front_end/src/base/instrumentation.dart'; |
| 20 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'; | 21 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'; |
| 21 import 'package:kernel/ast.dart'; | 22 import 'package:kernel/ast.dart'; |
| 22 import 'package:kernel/class_hierarchy.dart'; | 23 import 'package:kernel/class_hierarchy.dart'; |
| 23 import 'package:kernel/core_types.dart'; | 24 import 'package:kernel/core_types.dart'; |
| 24 | 25 |
| 25 /// Concrete shadow object representing a statement block in kernel form. | 26 /// Concrete shadow object representing a statement block in kernel form. |
| 26 class KernelBlock extends Block implements KernelStatement { | 27 class KernelBlock extends Block implements KernelStatement { |
| 27 KernelBlock(List<KernelStatement> statements) : super(statements); | 28 KernelBlock(List<KernelStatement> statements) : super(statements); |
| 28 | 29 |
| 29 @override | 30 @override |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 abstract class KernelStatement extends Statement { | 106 abstract class KernelStatement extends Statement { |
| 106 /// Calls back to [inferrer] to perform type inference for whatever concrete | 107 /// Calls back to [inferrer] to perform type inference for whatever concrete |
| 107 /// type of [KernelStatement] this is. | 108 /// type of [KernelStatement] this is. |
| 108 void _inferStatement(KernelTypeInferrer inferrer); | 109 void _inferStatement(KernelTypeInferrer inferrer); |
| 109 } | 110 } |
| 110 | 111 |
| 111 /// Concrete implementation of [TypeInferrer] specialized to work with kernel | 112 /// Concrete implementation of [TypeInferrer] specialized to work with kernel |
| 112 /// objects. | 113 /// objects. |
| 113 class KernelTypeInferrer extends TypeInferrer<Statement, Expression, | 114 class KernelTypeInferrer extends TypeInferrer<Statement, Expression, |
| 114 KernelVariableDeclaration, Field> { | 115 KernelVariableDeclaration, Field> { |
| 115 KernelTypeInferrer(CoreTypes coreTypes, ClassHierarchy classHierarchy) | 116 KernelTypeInferrer(CoreTypes coreTypes, ClassHierarchy classHierarchy, |
| 116 : super(coreTypes, classHierarchy); | 117 Instrumentation instrumentation) |
| 118 : super(coreTypes, classHierarchy, instrumentation); |
| 117 | 119 |
| 118 @override | 120 @override |
| 119 DartType inferExpression( | 121 DartType inferExpression( |
| 120 Expression expression, DartType typeContext, bool typeNeeded) { | 122 Expression expression, DartType typeContext, bool typeNeeded) { |
| 121 if (expression is KernelExpression) { | 123 if (expression is KernelExpression) { |
| 122 // Use polymorphic dispatch on [KernelExpression] to perform whatever kind | 124 // Use polymorphic dispatch on [KernelExpression] to perform whatever kind |
| 123 // of type inference is correct for this kind of statement. | 125 // of type inference is correct for this kind of statement. |
| 124 // TODO(paulberry): experiment to see if dynamic dispatch would be better, | 126 // TODO(paulberry): experiment to see if dynamic dispatch would be better, |
| 125 // so that the type hierarchy will be simpler (which may speed up "is" | 127 // so that the type hierarchy will be simpler (which may speed up "is" |
| 126 // checks). | 128 // checks). |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 KernelVariableGet(VariableDeclaration variable, [DartType promotedType]) | 179 KernelVariableGet(VariableDeclaration variable, [DartType promotedType]) |
| 178 : super(variable, promotedType); | 180 : super(variable, promotedType); |
| 179 | 181 |
| 180 @override | 182 @override |
| 181 DartType _inferExpression( | 183 DartType _inferExpression( |
| 182 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { | 184 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { |
| 183 // TODO(paulberry): implement. | 185 // TODO(paulberry): implement. |
| 184 return typeNeeded ? const DynamicType() : null; | 186 return typeNeeded ? const DynamicType() : null; |
| 185 } | 187 } |
| 186 } | 188 } |
| OLD | NEW |