OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 '../common.dart'; | 7 import '../common.dart'; |
8 import '../compiler.dart'; | 8 import '../compiler.dart'; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
12 import '../js_backend/backend.dart' show JavaScriptBackend; | 12 import '../js_backend/backend.dart' show JavaScriptBackend; |
13 import '../kernel/kernel.dart'; | 13 import '../kernel/kernel.dart'; |
14 import '../kernel/kernel_visitor.dart'; | 14 import '../kernel/kernel_visitor.dart'; |
15 import '../resolution/registry.dart' show ResolutionWorldImpactBuilder; | 15 import '../resolution/registry.dart' show ResolutionWorldImpactBuilder; |
16 import '../universe/feature.dart'; | 16 import '../universe/feature.dart'; |
17 import '../universe/use.dart'; | 17 import '../universe/use.dart'; |
18 | 18 |
19 import 'kernel_ast_adapter.dart'; | 19 import 'kernel_ast_adapter.dart'; |
20 import '../common/resolution.dart'; | 20 import '../common/resolution.dart'; |
21 | 21 |
22 /// Computes the [ResolutionImpact] for [resolvedAst] through kernel. | 22 /// Computes the [ResolutionImpact] for [resolvedAst] through kernel. |
23 ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) { | 23 ResolutionImpact build(Compiler compiler, ResolvedAst resolvedAst) { |
24 AstElement element = resolvedAst.element.implementation; | 24 AstElement element = resolvedAst.element.implementation; |
25 Kernel kernel = new Kernel(compiler); | 25 // Kernel kernel = new Kernel(compiler); |
Siggi Cherem (dart-lang)
2016/09/09 22:49:23
ditto?
Harry Terkelsen
2016/09/09 22:56:47
Done.
| |
26 KernelVisitor visitor = | 26 // KernelVisitor visitor = |
27 new KernelVisitor(element, resolvedAst.elements, kernel); | 27 // new KernelVisitor(element, resolvedAst.elements, kernel); |
28 IrFunction function; | 28 // IrFunction function; |
29 try { | 29 // try { |
30 function = visitor.buildFunction(); | 30 // function = visitor.buildFunction(); |
31 } catch (e) { | 31 // } catch (e) { |
32 throw "Failed to convert to Kernel IR: $e"; | 32 // throw "Failed to convert to Kernel IR: $e"; |
33 // } | |
34 JavaScriptBackend backend = compiler.backend; | |
35 Kernel kernel = backend.kernelTask.kernel; | |
36 ir.Procedure function = kernel.functions[element]; | |
37 if (function == null) { | |
38 print("FOUND NULL FUNCTION: $element"); | |
39 print(kernel.functions); | |
33 } | 40 } |
34 KernelImpactBuilder builder = new KernelImpactBuilder( | 41 KernelImpactBuilder builder = |
35 function, element, resolvedAst, compiler, visitor, kernel); | 42 new KernelImpactBuilder(function, element, resolvedAst, compiler, kernel); |
36 return builder.build(); | 43 return builder.build(); |
37 } | 44 } |
38 | 45 |
39 class KernelImpactBuilder extends ir.Visitor { | 46 class KernelImpactBuilder extends ir.Visitor { |
40 final IrFunction function; | 47 final ir.Procedure function; |
41 final FunctionElement functionElement; | 48 final FunctionElement functionElement; |
42 final ResolvedAst resolvedAst; | 49 final ResolvedAst resolvedAst; |
43 final Compiler compiler; | 50 final Compiler compiler; |
44 | 51 |
45 JavaScriptBackend get backend => compiler.backend; | 52 JavaScriptBackend get backend => compiler.backend; |
46 | 53 |
47 ResolutionWorldImpactBuilder impactBuilder; | 54 ResolutionWorldImpactBuilder impactBuilder; |
48 KernelAstAdapter astAdapter; | 55 KernelAstAdapter astAdapter; |
49 | 56 |
50 KernelImpactBuilder(this.function, this.functionElement, this.resolvedAst, | 57 KernelImpactBuilder(this.function, this.functionElement, this.resolvedAst, |
51 this.compiler, KernelVisitor visitor, Kernel kernel) { | 58 this.compiler, Kernel kernel) { |
52 this.impactBuilder = new ResolutionWorldImpactBuilder('$functionElement'); | 59 this.impactBuilder = new ResolutionWorldImpactBuilder('$functionElement'); |
53 this.astAdapter = new KernelAstAdapter( | 60 this.astAdapter = new KernelAstAdapter( |
54 compiler.backend, | 61 compiler.backend, |
55 resolvedAst, | 62 resolvedAst, |
56 visitor.nodeToAst, | 63 kernel.nodeToAst, |
57 visitor.nodeToElement, | 64 kernel.nodeToElement, |
58 kernel.functions, | 65 kernel.functions, |
59 kernel.classes, | 66 kernel.classes, |
60 kernel.libraries); | 67 kernel.libraries); |
61 } | 68 } |
62 | 69 |
63 ResolutionImpact build() { | 70 ResolutionImpact build() { |
64 if (function.kind == ir.ProcedureKind.Method || | 71 if (function.kind == ir.ProcedureKind.Method || |
65 function.kind == ir.ProcedureKind.Operator) { | 72 function.kind == ir.ProcedureKind.Operator) { |
66 buildMethod(function); | 73 buildMethod(function); |
67 } else { | 74 } else { |
68 compiler.reporter.internalError( | 75 compiler.reporter.internalError( |
69 functionElement, | 76 functionElement, |
70 "Unable to compute resolution impact for this kind of Kernel " | 77 "Unable to compute resolution impact for this kind of Kernel " |
71 "procedure: ${function.kind}"); | 78 "procedure: ${function.kind}"); |
72 } | 79 } |
73 return impactBuilder; | 80 return impactBuilder; |
74 } | 81 } |
75 | 82 |
76 /// Add a checked-mode type use of [type] if it is not `dynamic`. | 83 /// Add a checked-mode type use of [type] if it is not `dynamic`. |
77 DartType checkType(DartType type) { | 84 DartType checkType(DartType type) { |
78 if (!type.isDynamic) { | 85 if (!type.isDynamic) { |
79 impactBuilder.registerTypeUse(new TypeUse.checkedModeCheck(type)); | 86 impactBuilder.registerTypeUse(new TypeUse.checkedModeCheck(type)); |
80 } | 87 } |
81 return type; | 88 return type; |
82 } | 89 } |
83 | 90 |
84 void buildMethod(IrFunction method) { | 91 void buildMethod(ir.Procedure method) { |
85 method.node.body.accept(this); | 92 method.function.body.accept(this); |
86 } | 93 } |
87 | 94 |
88 void visitNodes(Iterable<ir.Node> nodes) { | 95 void visitNodes(Iterable<ir.Node> nodes) { |
89 nodes.forEach((ir.Node node) => node.accept(this)); | 96 nodes.forEach((ir.Node node) => node.accept(this)); |
90 } | 97 } |
91 | 98 |
92 @override | 99 @override |
93 void visitBlock(ir.Block block) => visitNodes(block.statements); | 100 void visitBlock(ir.Block block) => visitNodes(block.statements); |
94 | 101 |
95 @override | 102 @override |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 _visitArguments(invocation.arguments); | 201 _visitArguments(invocation.arguments); |
195 impactBuilder.registerDynamicUse( | 202 impactBuilder.registerDynamicUse( |
196 new DynamicUse(astAdapter.getSelector(invocation), null)); | 203 new DynamicUse(astAdapter.getSelector(invocation), null)); |
197 } | 204 } |
198 | 205 |
199 @override | 206 @override |
200 void visitNot(ir.Not not) { | 207 void visitNot(ir.Not not) { |
201 not.operand.accept(this); | 208 not.operand.accept(this); |
202 } | 209 } |
203 } | 210 } |
OLD | NEW |