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

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

Issue 2906253004: Avoid using Invalid{Statement,Expression,Initializer}. (Closed)
Patch Set: Created 3 years, 6 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`.
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/base/instrumentation.dart';
21 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart'; 21 import 'package:front_end/src/fasta/type_inference/type_inference_engine.dart';
22 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart' ; 22 import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart' ;
23 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'; 23 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart';
24 import 'package:front_end/src/fasta/type_inference/type_promotion.dart'; 24 import 'package:front_end/src/fasta/type_inference/type_promotion.dart';
25 import 'package:front_end/src/fasta/type_inference/type_schema.dart'; 25 import 'package:front_end/src/fasta/type_inference/type_schema.dart';
26 import 'package:front_end/src/fasta/type_inference/type_schema_elimination.dart' ; 26 import 'package:front_end/src/fasta/type_inference/type_schema_elimination.dart' ;
27 import 'package:kernel/ast.dart'; 27 import 'package:kernel/ast.dart'
28 hide InvalidExpression, InvalidInitializer, InvalidStatement;
28 import 'package:kernel/frontend/accessors.dart'; 29 import 'package:kernel/frontend/accessors.dart';
29 import 'package:kernel/type_algebra.dart'; 30 import 'package:kernel/type_algebra.dart';
30 31
32 import '../errors.dart' show internalError;
33
31 /// Computes the return type of a (possibly factory) constructor. 34 /// Computes the return type of a (possibly factory) constructor.
32 InterfaceType computeConstructorReturnType(Member constructor) { 35 InterfaceType computeConstructorReturnType(Member constructor) {
33 if (constructor is Constructor) { 36 if (constructor is Constructor) {
34 return constructor.enclosingClass.thisType; 37 return constructor.enclosingClass.thisType;
35 } else { 38 } else {
36 return computeFactoryConstructorReturnType(constructor); 39 return computeFactoryConstructorReturnType(constructor);
37 } 40 }
38 } 41 }
39 42
40 /// Computes the return type of a factory constructor. 43 /// Computes the return type of a factory constructor.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 /// Pointer to the last "let" expression in the cascade. 177 /// Pointer to the last "let" expression in the cascade.
175 Let nextCascade; 178 Let nextCascade;
176 179
177 /// Creates a [KernelCascadeExpression] using [variable] as the cascade 180 /// Creates a [KernelCascadeExpression] using [variable] as the cascade
178 /// variable. Caller is responsible for ensuring that [variable]'s 181 /// variable. Caller is responsible for ensuring that [variable]'s
179 /// initializer is the expression preceding the first `..` of the cascade 182 /// initializer is the expression preceding the first `..` of the cascade
180 /// expression. 183 /// expression.
181 KernelCascadeExpression(KernelVariableDeclaration variable) 184 KernelCascadeExpression(KernelVariableDeclaration variable)
182 : super( 185 : super(
183 variable, 186 variable,
184 makeLet(new VariableDeclaration.forValue(new InvalidExpression()), 187 makeLet(new VariableDeclaration.forValue(new _UnfinishedCascade()),
185 new VariableGet(variable))) { 188 new VariableGet(variable))) {
186 nextCascade = body; 189 nextCascade = body;
187 } 190 }
188 191
189 /// Adds a new unfinalized section to the end of the cascade. Should be 192 /// Adds a new unfinalized section to the end of the cascade. Should be
190 /// called after the previous cascade section has been finalized. 193 /// called after the previous cascade section has been finalized.
191 void extend() { 194 void extend() {
192 assert(nextCascade.variable.initializer is! InvalidExpression); 195 assert(nextCascade.variable.initializer is! _UnfinishedCascade);
193 Let newCascade = makeLet( 196 Let newCascade = makeLet(
194 new VariableDeclaration.forValue(new InvalidExpression()), 197 new VariableDeclaration.forValue(new _UnfinishedCascade()),
195 nextCascade.body); 198 nextCascade.body);
196 nextCascade.body = newCascade; 199 nextCascade.body = newCascade;
197 newCascade.parent = nextCascade; 200 newCascade.parent = nextCascade;
198 nextCascade = newCascade; 201 nextCascade = newCascade;
199 } 202 }
200 203
201 /// Finalizes the last cascade section with the given [expression]. 204 /// Finalizes the last cascade section with the given [expression].
202 void finalize(Expression expression) { 205 void finalize(Expression expression) {
203 assert(nextCascade.variable.initializer is InvalidExpression); 206 assert(nextCascade.variable.initializer is _UnfinishedCascade);
204 nextCascade.variable.initializer = expression; 207 nextCascade.variable.initializer = expression;
205 expression.parent = nextCascade.variable; 208 expression.parent = nextCascade.variable;
206 } 209 }
207 210
208 @override 211 @override
209 DartType _inferExpression( 212 DartType _inferExpression(
210 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 213 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
211 typeNeeded = inferrer.listener.cascadeExpressionEnter(this, typeContext) || 214 typeNeeded = inferrer.listener.cascadeExpressionEnter(this, typeContext) ||
212 typeNeeded; 215 typeNeeded;
213 var lhsType = inferrer.inferExpression( 216 var lhsType = inferrer.inferExpression(
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 closureContext.isAsync 1538 closureContext.isAsync
1536 ? inferrer.coreTypes.streamClass 1539 ? inferrer.coreTypes.streamClass
1537 : inferrer.coreTypes.iterableClass); 1540 : inferrer.coreTypes.iterableClass);
1538 } 1541 }
1539 var inferredType = inferrer.inferExpression( 1542 var inferredType = inferrer.inferExpression(
1540 expression, typeContext, closureContext != null); 1543 expression, typeContext, closureContext != null);
1541 closureContext.handleYield(inferrer, isYieldStar, inferredType); 1544 closureContext.handleYield(inferrer, isYieldStar, inferredType);
1542 inferrer.listener.yieldStatementExit(this); 1545 inferrer.listener.yieldStatementExit(this);
1543 } 1546 }
1544 } 1547 }
1548
1549 class _UnfinishedCascade extends Expression {
1550 getStaticType(types) {
1551 return internalError("Internal error: Unsupported operation.");
1552 }
1553
1554 accept(v) {
1555 return internalError("Internal error: Unsupported operation.");
1556 }
1557
1558 accept1(v, arg) {
1559 return internalError("Internal error: Unsupported operation.");
1560 }
1561
1562 visitChildren(v) {
1563 return internalError("Internal error: Unsupported operation.");
1564 }
1565
1566 transformChildren(v) {
1567 return internalError("Internal error: Unsupported operation.");
1568 }
1569 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698