| 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 ir.Name irName = invocation.name; |
| 90 Name name = new Name( |
| 91 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
| 92 |
| 93 int argumentCount = invocation.arguments.positional.length + |
| 94 invocation.arguments.named.length; |
| 95 List<String> namedArguments = |
| 96 invocation.arguments.named.map((e) => e.name).toList(); |
| 97 CallStructure callStructure = |
| 98 new CallStructure(argumentCount, namedArguments); |
| 99 |
| 100 return new Selector(kind, name, callStructure); |
| 77 } | 101 } |
| 78 | 102 |
| 79 TypeMask getTypeMask(ir.MethodInvocation invocation) { | 103 TypeMask getTypeMask(ir.MethodInvocation invocation) { |
| 80 return _elements.getTypeMask(getNode(invocation)); | 104 return _elements.getTypeMask(getNode(invocation)); |
| 81 } | 105 } |
| 82 | 106 |
| 83 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { | 107 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { |
| 84 return TypeMaskFactory.inferredTypeForSelector( | 108 return TypeMaskFactory.inferredTypeForSelector( |
| 85 getSelector(invocation), getTypeMask(invocation), _compiler); | 109 getSelector(invocation), getTypeMask(invocation), _compiler); |
| 86 } | 110 } |
| 87 | 111 |
| 88 bool isIntercepted(ir.MethodInvocation invocation) { | 112 bool isIntercepted(ir.MethodInvocation invocation) { |
| 89 return _backend.isInterceptedSelector(getSelector(invocation)); | 113 return _backend.isInterceptedSelector(getSelector(invocation)); |
| 90 } | 114 } |
| 91 } | 115 } |
| OLD | NEW |