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 '../compiler.dart'; | 7 import '../compiler.dart'; |
8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
9 import '../diagnostics/invariant.dart'; | 9 import '../diagnostics/invariant.dart'; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
11 import '../js_backend/js_backend.dart'; | 11 import '../js_backend/js_backend.dart'; |
12 import '../resolution/tree_elements.dart'; | 12 import '../resolution/tree_elements.dart'; |
13 import '../tree/tree.dart' as ast; | 13 import '../tree/tree.dart' as ast; |
14 import '../types/masks.dart'; | 14 import '../types/masks.dart'; |
15 import '../universe/call_structure.dart'; | |
15 import '../universe/selector.dart'; | 16 import '../universe/selector.dart'; |
16 import '../universe/side_effects.dart'; | 17 import '../universe/side_effects.dart'; |
17 | 18 |
18 import 'types.dart'; | 19 import 'types.dart'; |
19 | 20 |
20 /// A helper class that abstracts all accesses of the AST from Kernel nodes. | 21 /// A helper class that abstracts all accesses of the AST from Kernel nodes. |
21 /// | 22 /// |
22 /// The goal is to remove all need for the AST from the Kernel SSA builder. | 23 /// The goal is to remove all need for the AST from the Kernel SSA builder. |
23 class KernelAstAdapter { | 24 class KernelAstAdapter { |
24 final JavaScriptBackend _backend; | 25 final JavaScriptBackend _backend; |
25 final ResolvedAst _resolvedAst; | 26 final ResolvedAst _resolvedAst; |
26 final Map<ir.Node, ast.Node> _nodeToAst; | 27 final Map<ir.Node, ast.Node> _nodeToAst; |
27 final Map<ir.Node, Element> _nodeToElement; | 28 final Map<ir.Node, Element> _nodeToElement; |
28 | 29 |
29 KernelAstAdapter(this._backend, this._resolvedAst, this._nodeToAst, | 30 KernelAstAdapter( |
30 this._nodeToElement, Map<FunctionElement, ir.Member> functions) { | 31 this._backend, |
32 this._resolvedAst, | |
33 this._nodeToAst, | |
34 this._nodeToElement, | |
35 Map<FunctionElement, ir.Member> functions, | |
36 Map<LibraryElement, ir.Library> libraries) { | |
31 for (FunctionElement functionElement in functions.keys) { | 37 for (FunctionElement functionElement in functions.keys) { |
32 _nodeToElement[functions[functionElement]] = functionElement; | 38 _nodeToElement[functions[functionElement]] = functionElement; |
33 } | 39 } |
40 for (LibraryElement libraryElement in libraries.keys) { | |
41 _nodeToElement[libraries[libraryElement]] = libraryElement; | |
42 } | |
34 } | 43 } |
35 | 44 |
36 Compiler get _compiler => _backend.compiler; | 45 Compiler get _compiler => _backend.compiler; |
37 TreeElements get _elements => _resolvedAst.elements; | 46 TreeElements get _elements => _resolvedAst.elements; |
38 | 47 |
39 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { | 48 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { |
40 ast.Node astNode = getNode(node); | 49 ast.Node astNode = getNode(node); |
41 ConstantValue constantValue = _backend.constants | 50 ConstantValue constantValue = _backend.constants |
42 .getConstantValueForNode(astNode, _resolvedAst.elements); | 51 .getConstantValueForNode(astNode, _resolvedAst.elements); |
43 assert(invariant(astNode, constantValue != null, | 52 assert(invariant(astNode, constantValue != null, |
(...skipping 22 matching lines...) Expand all Loading... | |
66 return TypeMaskFactory.inferredReturnTypeForElement( | 75 return TypeMaskFactory.inferredReturnTypeForElement( |
67 getElement(node), _compiler); | 76 getElement(node), _compiler); |
68 } | 77 } |
69 | 78 |
70 SideEffects getSideEffects(ir.Node node) { | 79 SideEffects getSideEffects(ir.Node node) { |
71 return _compiler.world.getSideEffectsOfElement(getElement(node)); | 80 return _compiler.world.getSideEffectsOfElement(getElement(node)); |
72 } | 81 } |
73 | 82 |
74 // TODO(het): Create the selector directly from the invocation | 83 // TODO(het): Create the selector directly from the invocation |
75 Selector getSelector(ir.MethodInvocation invocation) { | 84 Selector getSelector(ir.MethodInvocation invocation) { |
76 return _elements.getSelector(getNode(invocation)); | 85 SelectorKind kind = Elements.isOperatorName(invocation.name.name) |
86 ? SelectorKind.OPERATOR | |
87 : SelectorKind.CALL; | |
88 | |
89 // TODO(het): If this is a private name, include the library | |
Siggi Cherem (dart-lang)
2016/08/31 17:42:36
remove TODO? Or is this something more than what y
Harry Terkelsen
2016/08/31 17:45:58
Oops! I forgot to remove once I actually did it
| |
90 Name name; | |
91 if (invocation.name.isPrivate) { | |
92 name = | |
93 new Name(invocation.name.name, getElement(invocation.name.library)); | |
Siggi Cherem (dart-lang)
2016/08/31 17:42:36
minor style nit, consider:
ir.Name irName = invoc
Harry Terkelsen
2016/08/31 17:45:58
Done.
| |
94 } else { | |
95 name = new Name(invocation.name.name, null); | |
96 } | |
97 | |
98 int argumentCount = invocation.arguments.positional.length + | |
99 invocation.arguments.named.length; | |
100 List<String> namedArguments = | |
101 invocation.arguments.named.map((e) => e.name).toList(); | |
102 CallStructure callStructure = | |
103 new CallStructure(argumentCount, namedArguments); | |
104 | |
105 return new Selector(kind, name, callStructure); | |
77 } | 106 } |
78 | 107 |
79 TypeMask getTypeMask(ir.MethodInvocation invocation) { | 108 TypeMask getTypeMask(ir.MethodInvocation invocation) { |
80 return _elements.getTypeMask(getNode(invocation)); | 109 return _elements.getTypeMask(getNode(invocation)); |
81 } | 110 } |
82 | 111 |
83 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { | 112 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { |
84 return TypeMaskFactory.inferredTypeForSelector( | 113 return TypeMaskFactory.inferredTypeForSelector( |
85 getSelector(invocation), getTypeMask(invocation), _compiler); | 114 getSelector(invocation), getTypeMask(invocation), _compiler); |
86 } | 115 } |
87 | 116 |
88 bool isIntercepted(ir.MethodInvocation invocation) { | 117 bool isIntercepted(ir.MethodInvocation invocation) { |
89 return _backend.isInterceptedSelector(getSelector(invocation)); | 118 return _backend.isInterceptedSelector(getSelector(invocation)); |
90 } | 119 } |
91 } | 120 } |
OLD | NEW |