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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart

Issue 2962583002: Add type inference for break and continue statements. (Closed)
Patch Set: Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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`.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 DartType _inferExpression( 164 DartType _inferExpression(
165 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 165 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
166 typeNeeded = 166 typeNeeded =
167 inferrer.listener.boolLiteralEnter(this, typeContext) || typeNeeded; 167 inferrer.listener.boolLiteralEnter(this, typeContext) || typeNeeded;
168 var inferredType = typeNeeded ? inferrer.coreTypes.boolClass.rawType : null; 168 var inferredType = typeNeeded ? inferrer.coreTypes.boolClass.rawType : null;
169 inferrer.listener.boolLiteralExit(this, inferredType); 169 inferrer.listener.boolLiteralExit(this, inferredType);
170 return inferredType; 170 return inferredType;
171 } 171 }
172 } 172 }
173 173
174 /// Concrete shadow object representing a break or continue statement in kernel
175 /// form.
176 class KernelBreakStatement extends BreakStatement implements KernelStatement {
177 KernelBreakStatement(LabeledStatement target) : super(target);
178
179 @override
180 void _inferStatement(KernelTypeInferrer inferrer) {
181 inferrer.listener.breakStatementEnter(this);
182 // No inference needs to be done.
183 inferrer.listener.breakStatementExit(this);
184 }
185 }
186
174 /// Concrete shadow object representing a cascade expression. 187 /// Concrete shadow object representing a cascade expression.
175 /// 188 ///
176 /// A cascade expression of the form `a..b()..c()` is represented as the kernel 189 /// A cascade expression of the form `a..b()..c()` is represented as the kernel
177 /// expression: 190 /// expression:
178 /// 191 ///
179 /// let v = a in 192 /// let v = a in
180 /// let _ = v.b() in 193 /// let _ = v.b() in
181 /// let _ = v.c() in 194 /// let _ = v.c() in
182 /// v 195 /// v
183 /// 196 ///
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 typeNeeded, 506 typeNeeded,
494 fileOffset, 507 fileOffset,
495 _initialTarget.function.functionType, 508 _initialTarget.function.functionType,
496 computeConstructorReturnType(_initialTarget), 509 computeConstructorReturnType(_initialTarget),
497 arguments); 510 arguments);
498 inferrer.listener.constructorInvocationExit(this, inferredType); 511 inferrer.listener.constructorInvocationExit(this, inferredType);
499 return inferredType; 512 return inferredType;
500 } 513 }
501 } 514 }
502 515
516 /// Concrete shadow object representing a continue statement from a switch
517 /// statement, in kernel form.
518 class KernelContinueSwitchStatement extends ContinueSwitchStatement
519 implements KernelStatement {
520 KernelContinueSwitchStatement(SwitchCase target) : super(target);
521
522 @override
523 void _inferStatement(KernelTypeInferrer inferrer) {
524 inferrer.listener.continueSwitchStatementEnter(this);
525 // No inference needs to be done.
526 inferrer.listener.continueSwitchStatementExit(this);
527 }
528 }
529
503 /// Concrete implementation of [DependencyCollector] specialized to work with 530 /// Concrete implementation of [DependencyCollector] specialized to work with
504 /// kernel objects. 531 /// kernel objects.
505 class KernelDependencyCollector extends DependencyCollectorImpl { 532 class KernelDependencyCollector extends DependencyCollectorImpl {
506 @override 533 @override
507 void collectDependencies(Expression expression) { 534 void collectDependencies(Expression expression) {
508 if (expression is KernelExpression) { 535 if (expression is KernelExpression) {
509 // Use polymorphic dispatch on [KernelExpression] to perform whatever kind 536 // Use polymorphic dispatch on [KernelExpression] to perform whatever kind
510 // of type inference is correct for this kind of statement. 537 // of type inference is correct for this kind of statement.
511 // TODO(paulberry): experiment to see if dynamic dispatch would be better, 538 // TODO(paulberry): experiment to see if dynamic dispatch would be better,
512 // so that the type hierarchy will be simpler (which may speed up "is" 539 // so that the type hierarchy will be simpler (which may speed up "is"
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 } 2359 }
2333 2360
2334 transformChildren(v) { 2361 transformChildren(v) {
2335 return internalError("Internal error: Unsupported operation."); 2362 return internalError("Internal error: Unsupported operation.");
2336 } 2363 }
2337 2364
2338 visitChildren(v) { 2365 visitChildren(v) {
2339 return internalError("Internal error: Unsupported operation."); 2366 return internalError("Internal error: Unsupported operation.");
2340 } 2367 }
2341 } 2368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698