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

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

Issue 2828693003: Add local type inference logic for integer literals. (Closed)
Patch Set: Minor clean-ups Created 3 years, 8 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_inferrer.dart'; 21 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart';
22 import 'package:kernel/ast.dart'; 22 import 'package:kernel/ast.dart';
23 import 'package:kernel/class_hierarchy.dart'; 23 import 'package:kernel/class_hierarchy.dart';
24 import 'package:kernel/core_types.dart'; 24 import 'package:kernel/core_types.dart';
25 25
26 /// Concrete shadow object representing a statement block in kernel form. 26 /// Concrete shadow object representing a statement block in kernel form.
27 class KernelBlock extends Block implements KernelStatement { 27 class KernelBlock extends Block implements KernelStatement {
28 KernelBlock(List<KernelStatement> statements) : super(statements); 28 KernelBlock(List<Statement> statements) : super(statements);
29 29
30 @override 30 @override
31 void _inferStatement(KernelTypeInferrer inferrer) { 31 void _inferStatement(KernelTypeInferrer inferrer) {
32 // TODO(paulberry): implement. 32 for (var statement in statements) {
33 inferrer.inferStatement(statement);
34 }
33 } 35 }
34 } 36 }
35 37
36 /// Common base class for shadow objects representing expressions in kernel 38 /// Common base class for shadow objects representing expressions in kernel
37 /// form. 39 /// form.
38 abstract class KernelExpression implements Expression { 40 abstract class KernelExpression implements Expression {
39 /// Calls back to [inferrer] to perform type inference for whatever concrete 41 /// Calls back to [inferrer] to perform type inference for whatever concrete
40 /// type of [KernelExpression] this is. 42 /// type of [KernelExpression] this is.
41 DartType _inferExpression( 43 DartType _inferExpression(
42 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded); 44 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded);
(...skipping 12 matching lines...) Expand all
55 } 57 }
56 } 58 }
57 59
58 /// Concrete shadow object representing an integer literal in kernel form. 60 /// Concrete shadow object representing an integer literal in kernel form.
59 class KernelIntLiteral extends IntLiteral implements KernelExpression { 61 class KernelIntLiteral extends IntLiteral implements KernelExpression {
60 KernelIntLiteral(int value) : super(value); 62 KernelIntLiteral(int value) : super(value);
61 63
62 @override 64 @override
63 DartType _inferExpression( 65 DartType _inferExpression(
64 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 66 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
65 // TODO(paulberry): implement. 67 return inferrer.inferIntLiteral(typeContext, typeNeeded);
66 return typeNeeded ? const DynamicType() : null;
67 } 68 }
68 } 69 }
69 70
70 /// Concrete shadow object representing a list literal in kernel form. 71 /// Concrete shadow object representing a list literal in kernel form.
71 class KernelListLiteral extends ListLiteral implements KernelExpression { 72 class KernelListLiteral extends ListLiteral implements KernelExpression {
72 KernelListLiteral(List<KernelExpression> expressions, 73 KernelListLiteral(List<KernelExpression> expressions,
73 {DartType typeArgument, bool isConst: false}) 74 {DartType typeArgument, bool isConst: false})
74 : super(expressions, typeArgument: typeArgument, isConst: isConst); 75 : super(expressions, typeArgument: typeArgument, isConst: isConst);
75 76
76 @override 77 @override
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // implemented, so just skip it for now. 151 // implemented, so just skip it for now.
151 // TODO(paulberry): once the BodyBuilder uses shadow classes for 152 // TODO(paulberry): once the BodyBuilder uses shadow classes for
152 // everything, this case should no longer be needed. 153 // everything, this case should no longer be needed.
153 } 154 }
154 } 155 }
155 } 156 }
156 157
157 /// Concrete shadow object representing a variable declaration in kernel form. 158 /// Concrete shadow object representing a variable declaration in kernel form.
158 class KernelVariableDeclaration extends VariableDeclaration 159 class KernelVariableDeclaration extends VariableDeclaration
159 implements KernelStatement { 160 implements KernelStatement {
161 final bool _implicitlyTyped;
162
160 KernelVariableDeclaration(String name, 163 KernelVariableDeclaration(String name,
161 {KernelExpression initializer, 164 {Expression initializer,
162 DartType type, 165 DartType type,
163 bool isFinal: false, 166 bool isFinal: false,
164 bool isConst: false}) 167 bool isConst: false})
165 : super(name, 168 : _implicitlyTyped = type == null,
169 super(name,
166 initializer: initializer, 170 initializer: initializer,
167 type: type, 171 type: type ?? const DynamicType(),
168 isFinal: isFinal, 172 isFinal: isFinal,
169 isConst: isConst); 173 isConst: isConst);
170 174
171 @override 175 @override
172 void _inferStatement(KernelTypeInferrer inferrer) { 176 void _inferStatement(KernelTypeInferrer inferrer) {
173 // TODO(paulberry): implement. 177 inferrer.inferVariableDeclaration(
178 _implicitlyTyped ? null : type, initializer, fileOffset, (type) {
179 this.type = type;
180 });
174 } 181 }
175 } 182 }
176 183
177 /// Concrete shadow object representing a read from a variable in kernel form. 184 /// Concrete shadow object representing a read from a variable in kernel form.
178 class KernelVariableGet extends VariableGet implements KernelExpression { 185 class KernelVariableGet extends VariableGet implements KernelExpression {
179 KernelVariableGet(VariableDeclaration variable, [DartType promotedType]) 186 KernelVariableGet(VariableDeclaration variable, [DartType promotedType])
180 : super(variable, promotedType); 187 : super(variable, promotedType);
181 188
182 @override 189 @override
183 DartType _inferExpression( 190 DartType _inferExpression(
184 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) { 191 KernelTypeInferrer inferrer, DartType typeContext, bool typeNeeded) {
185 // TODO(paulberry): implement. 192 // TODO(paulberry): implement.
186 return typeNeeded ? const DynamicType() : null; 193 return typeNeeded ? const DynamicType() : null;
187 } 194 }
188 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698