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 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 '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
11 import '../kernel/kernel.dart'; | 11 import '../kernel/kernel.dart'; |
12 import '../ssa/kernel_ast_adapter.dart'; | 12 import '../ssa/kernel_ast_adapter.dart'; |
13 import '../tree/tree.dart' as ast; | 13 import '../tree/tree.dart' as ast; |
14 import '../universe/side_effects.dart' show SideEffects; | 14 import '../universe/side_effects.dart' show SideEffects; |
15 import 'inferrer_engine.dart'; | 15 import 'inferrer_engine.dart'; |
16 import 'locals_handler.dart'; | 16 import 'locals_handler.dart'; |
17 import 'type_graph_nodes.dart'; | 17 import 'type_graph_nodes.dart'; |
18 import 'type_system.dart'; | 18 import 'type_system.dart'; |
19 | 19 |
20 /// [KernelTypeGraphBuilder] constructs a type-inference graph for a particular | 20 /// [KernelTypeGraphBuilder] constructs a type-inference graph for a particular |
21 /// element. | 21 /// element. |
22 /// | 22 /// |
23 /// Calling [run] will start the work of visiting the body of the code to | 23 /// Calling [run] will start the work of visiting the body of the code to |
24 /// construct a set of inference-nodes that abstractly represent what the code | 24 /// construct a set of inference-nodes that abstractly represent what the code |
25 /// is doing. | 25 /// is doing. |
26 class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> { | 26 class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> { |
27 final Compiler compiler; | 27 final Compiler compiler; |
28 final AstElement originalElement; | 28 final MemberElement originalElement; |
29 // TODO(efortuna): Remove this. | 29 // TODO(efortuna): Remove this. |
30 final Element outermostElement; | 30 final MemberElement outermostElement; |
31 final ir.Node analyzedNode; | 31 final ir.Node analyzedNode; |
32 final ResolvedAst resolvedAst; | 32 final ResolvedAst resolvedAst; |
33 final TypeSystem types; | 33 final TypeSystem types; |
34 LocalsHandler locals; | 34 LocalsHandler locals; |
35 final InferrerEngine inferrer; | 35 final InferrerEngine inferrer; |
36 SideEffects sideEffects = new SideEffects.empty(); | 36 SideEffects sideEffects = new SideEffects.empty(); |
37 int loopLevel = 0; | 37 int loopLevel = 0; |
38 bool get inLoop => loopLevel > 0; | 38 bool get inLoop => loopLevel > 0; |
39 | 39 |
40 final Set<Entity> capturedVariables = new Set<Entity>(); | 40 final Set<Entity> capturedVariables = new Set<Entity>(); |
(...skipping 16 matching lines...) Expand all Loading... |
57 if (resolvedAst.kind == ResolvedAstKind.PARSED) { | 57 if (resolvedAst.kind == ResolvedAstKind.PARSED) { |
58 node = resolvedAst.node; | 58 node = resolvedAst.node; |
59 } | 59 } |
60 FieldInitializationScope fieldScope = (analyzedNode is ir.Constructor) | 60 FieldInitializationScope fieldScope = (analyzedNode is ir.Constructor) |
61 ? new FieldInitializationScope(types) | 61 ? new FieldInitializationScope(types) |
62 : null; | 62 : null; |
63 locals = | 63 locals = |
64 new LocalsHandler(inferrer, types, compiler.options, node, fieldScope); | 64 new LocalsHandler(inferrer, types, compiler.options, node, fieldScope); |
65 } | 65 } |
66 | 66 |
67 factory KernelTypeGraphBuilder(Element element, ResolvedAst resolvedAst, | 67 factory KernelTypeGraphBuilder(MemberElement element, ResolvedAst resolvedAst, |
68 Compiler compiler, InferrerEngine inferrer, | 68 Compiler compiler, InferrerEngine inferrer, |
69 [LocalsHandler handler]) { | 69 [LocalsHandler handler]) { |
70 var adapter = _createKernelAdapter(compiler, resolvedAst); | 70 var adapter = _createKernelAdapter(compiler, resolvedAst); |
71 var node = adapter.getMemberNode(element); | 71 var node = adapter.getMemberNode(element); |
72 return new KernelTypeGraphBuilder.internal( | 72 return new KernelTypeGraphBuilder.internal( |
73 element, | 73 element, |
74 resolvedAst, | 74 resolvedAst, |
75 element.outermostEnclosingMemberOrTopLevel.implementation, | 75 element.outermostEnclosingMemberOrTopLevel.implementation, |
76 inferrer, | 76 inferrer, |
77 compiler, | 77 compiler, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 : types.simplifyPhi(null, null, elementType); | 163 : types.simplifyPhi(null, null, elementType); |
164 TypeInformation containerType = | 164 TypeInformation containerType = |
165 listLiteral.isConst ? types.constListType : types.growableListType; | 165 listLiteral.isConst ? types.constListType : types.growableListType; |
166 // TODO(efortuna): Change signature of allocateList and the rest of | 166 // TODO(efortuna): Change signature of allocateList and the rest of |
167 // type_system to deal with Kernel elements. | 167 // type_system to deal with Kernel elements. |
168 return types.allocateList(containerType, astAdapter.getNode(listLiteral), | 168 return types.allocateList(containerType, astAdapter.getNode(listLiteral), |
169 outermostElement, elementType, length); | 169 outermostElement, elementType, length); |
170 }); | 170 }); |
171 } | 171 } |
172 } | 172 } |
OLD | NEW |