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

Side by Side Diff: pkg/compiler/lib/src/inferrer/builder_kernel.dart

Issue 3009043002: Handle variable declarations in inferrer (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/kernel_inferrer_engine.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../constants/constant_system.dart'; 9 import '../constants/constant_system.dart';
10 import '../elements/entities.dart'; 10 import '../elements/entities.dart';
11 import '../elements/types.dart';
12 import '../kernel/element_map.dart';
11 import '../options.dart'; 13 import '../options.dart';
12 import '../types/constants.dart'; 14 import '../types/constants.dart';
13 import '../world.dart'; 15 import '../world.dart';
14 import 'inferrer_engine.dart'; 16 import 'inferrer_engine.dart';
15 import 'locals_handler.dart'; 17 import 'locals_handler.dart';
16 import 'type_graph_nodes.dart'; 18 import 'type_graph_nodes.dart';
17 import 'type_system.dart'; 19 import 'type_system.dart';
18 20
19 /// [KernelTypeGraphBuilder] constructs a type-inference graph for a particular 21 /// [KernelTypeGraphBuilder] constructs a type-inference graph for a particular
20 /// element. 22 /// element.
21 /// 23 ///
22 /// Calling [run] will start the work of visiting the body of the code to 24 /// Calling [run] will start the work of visiting the body of the code to
23 /// construct a set of inference-nodes that abstractly represent what the code 25 /// construct a set of inference-nodes that abstractly represent what the code
24 /// is doing. 26 /// is doing.
25 class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> { 27 class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
26 final CompilerOptions _options; 28 final CompilerOptions _options;
27 final ClosedWorld _closedWorld; 29 final ClosedWorld _closedWorld;
28 final ClosureDataLookup<ir.Node> _closureDataLookup; 30 final ClosureDataLookup<ir.Node> _closureDataLookup;
29 final InferrerEngine<ir.Node> _inferrer; 31 final InferrerEngine<ir.Node> _inferrer;
30 final TypeSystem<ir.Node> _types; 32 final TypeSystem<ir.Node> _types;
31 final MemberEntity _analyzedMember; 33 final MemberEntity _analyzedMember;
32 final ir.Node _analyzedNode; 34 final ir.Node _analyzedNode;
35 final KernelToElementMapForBuilding _elementMap;
36 final KernelToLocalsMap _localsMap;
33 LocalsHandler _locals; 37 LocalsHandler _locals;
34 38
35 TypeInformation _returnType; 39 TypeInformation _returnType;
36 40
37 KernelTypeGraphBuilder( 41 KernelTypeGraphBuilder(
38 this._options, 42 this._options,
39 this._closedWorld, 43 this._closedWorld,
40 this._closureDataLookup, 44 this._closureDataLookup,
41 this._inferrer, 45 this._inferrer,
42 this._analyzedMember, 46 this._analyzedMember,
43 this._analyzedNode, 47 this._analyzedNode,
48 this._elementMap,
49 this._localsMap,
44 [this._locals]) 50 [this._locals])
45 : this._types = _inferrer.types { 51 : this._types = _inferrer.types {
46 if (_locals != null) return; 52 if (_locals != null) return;
47 53
48 FieldInitializationScope<ir.Node> fieldScope = 54 FieldInitializationScope<ir.Node> fieldScope =
49 _analyzedNode is ir.Constructor 55 _analyzedNode is ir.Constructor
50 ? new FieldInitializationScope(_types) 56 ? new FieldInitializationScope(_types)
51 : null; 57 : null;
52 _locals = new LocalsHandler( 58 _locals = new LocalsHandler(
53 _inferrer, _types, _options, _analyzedNode, fieldScope); 59 _inferrer, _types, _options, _analyzedNode, fieldScope);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 MemberEntity member = _analyzedMember; 94 MemberEntity member = _analyzedMember;
89 if (member is ConstructorEntity && member.isGenerativeConstructor) { 95 if (member is ConstructorEntity && member.isGenerativeConstructor) {
90 _locals.fieldScope.isIndefinite = true; 96 _locals.fieldScope.isIndefinite = true;
91 } 97 }
92 } 98 }
93 99
94 TypeInformation visit(ir.Node node) { 100 TypeInformation visit(ir.Node node) {
95 return node == null ? null : node.accept(this); 101 return node == null ? null : node.accept(this);
96 } 102 }
97 103
104 void visitList(List<ir.Node> nodes) {
105 if (nodes == null) return;
106 nodes.forEach(visit);
107 }
108
98 @override 109 @override
99 TypeInformation visitFunctionNode(ir.FunctionNode node) { 110 TypeInformation visitFunctionNode(ir.FunctionNode node) {
100 // TODO(redemption): Handle constructors. 111 // TODO(redemption): Handle constructors.
101 // TODO(redemption): Handle native methods. 112 // TODO(redemption): Handle native methods.
102 // TODO(redemption): Set up parameters. 113 visitList(node.positionalParameters);
114 visitList(node.namedParameters);
103 visit(node.body); 115 visit(node.body);
104 switch (node.asyncMarker) { 116 switch (node.asyncMarker) {
105 case ir.AsyncMarker.Sync: 117 case ir.AsyncMarker.Sync:
106 if (_returnType == null) { 118 if (_returnType == null) {
107 // No return in the body. 119 // No return in the body.
108 _returnType = _locals.seenReturnOrThrow 120 _returnType = _locals.seenReturnOrThrow
109 ? _types.nonNullEmpty() // Body always throws. 121 ? _types.nonNullEmpty() // Body always throws.
110 : _types.nullType; 122 : _types.nullType;
111 } else if (!_locals.seenReturnOrThrow) { 123 } else if (!_locals.seenReturnOrThrow) {
112 // We haven'TypeInformation seen returns on all branches. So the metho d may 124 // We haven'TypeInformation seen returns on all branches. So the metho d may
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 212 }
201 213
202 @override 214 @override
203 TypeInformation visitDoubleLiteral(ir.DoubleLiteral node) { 215 TypeInformation visitDoubleLiteral(ir.DoubleLiteral node) {
204 ConstantSystem constantSystem = _closedWorld.constantSystem; 216 ConstantSystem constantSystem = _closedWorld.constantSystem;
205 // The JavaScript backend may turn this literal into an integer at 217 // The JavaScript backend may turn this literal into an integer at
206 // runtime. 218 // runtime.
207 return _types.getConcreteTypeFor( 219 return _types.getConcreteTypeFor(
208 computeTypeMask(_closedWorld, constantSystem.createDouble(node.value))); 220 computeTypeMask(_closedWorld, constantSystem.createDouble(node.value)));
209 } 221 }
222
223 @override
224 TypeInformation visitVariableDeclaration(ir.VariableDeclaration node) {
225 Local local = _localsMap.getLocalVariable(node);
226 DartType type = _localsMap.getLocalType(_elementMap, local);
227 if (node.initializer == null) {
228 _locals.update(local, _types.nullType, node, type);
229 } else {
230 _locals.update(local, visit(node.initializer), node, type);
231 }
232 return null;
233 }
234
235 @override
236 TypeInformation visitVariableGet(ir.VariableGet node) {
237 return _locals.use(_localsMap.getLocalVariable(node.variable));
238 }
210 } 239 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/inferrer/kernel_inferrer_engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698