| 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 '../constants/values.dart'; | 8 import '../constants/values.dart'; |
| 8 import '../diagnostics/invariant.dart'; | 9 import '../diagnostics/invariant.dart'; |
| 9 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 10 import '../js_backend/js_backend.dart'; | 11 import '../js_backend/js_backend.dart'; |
| 12 import '../resolution/tree_elements.dart'; |
| 11 import '../tree/tree.dart' as ast; | 13 import '../tree/tree.dart' as ast; |
| 12 import '../types/masks.dart'; | 14 import '../types/masks.dart'; |
| 15 import '../universe/selector.dart'; |
| 13 import '../universe/side_effects.dart'; | 16 import '../universe/side_effects.dart'; |
| 14 | 17 |
| 15 import 'types.dart'; | 18 import 'types.dart'; |
| 16 | 19 |
| 17 /// A helper class that abstracts all accesses of the AST from Kernel nodes. | 20 /// A helper class that abstracts all accesses of the AST from Kernel nodes. |
| 18 /// | 21 /// |
| 19 /// The goal is to remove all need for the AST from the Kernel SSA builder. | 22 /// The goal is to remove all need for the AST from the Kernel SSA builder. |
| 20 class KernelAstAdapter { | 23 class KernelAstAdapter { |
| 21 final JavaScriptBackend _backend; | 24 final JavaScriptBackend _backend; |
| 22 final ResolvedAst _resolvedAst; | 25 final ResolvedAst _resolvedAst; |
| 23 final Map<ir.Node, ast.Node> _nodeToAst; | 26 final Map<ir.Node, ast.Node> _nodeToAst; |
| 24 final Map<ir.Node, Element> _nodeToElement; | 27 final Map<ir.Node, Element> _nodeToElement; |
| 25 | 28 |
| 26 KernelAstAdapter(this._backend, this._resolvedAst, this._nodeToAst, | 29 KernelAstAdapter(this._backend, this._resolvedAst, this._nodeToAst, |
| 27 this._nodeToElement, Map<FunctionElement, ir.Member> functions) { | 30 this._nodeToElement, Map<FunctionElement, ir.Member> functions) { |
| 28 for (FunctionElement functionElement in functions.keys) { | 31 for (FunctionElement functionElement in functions.keys) { |
| 29 _nodeToElement[functions[functionElement]] = functionElement; | 32 _nodeToElement[functions[functionElement]] = functionElement; |
| 30 } | 33 } |
| 31 } | 34 } |
| 32 | 35 |
| 36 Compiler get _compiler => _backend.compiler; |
| 37 TreeElements get _elements => _resolvedAst.elements; |
| 38 |
| 33 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { | 39 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { |
| 34 ast.Node astNode = _nodeToAst[node]; | 40 ast.Node astNode = getNode(node); |
| 35 ConstantValue constantValue = _backend.constants | 41 ConstantValue constantValue = _backend.constants |
| 36 .getConstantValueForNode(astNode, _resolvedAst.elements); | 42 .getConstantValueForNode(astNode, _resolvedAst.elements); |
| 37 assert(invariant(astNode, constantValue != null, | 43 assert(invariant(astNode, constantValue != null, |
| 38 message: 'No constant computed for $node')); | 44 message: 'No constant computed for $node')); |
| 39 return constantValue; | 45 return constantValue; |
| 40 } | 46 } |
| 41 | 47 |
| 42 Element getElement(ir.Node node) { | 48 Element getElement(ir.Node node) { |
| 43 Element result = _nodeToElement[node]; | 49 Element result = _nodeToElement[node]; |
| 44 assert(result != null); | 50 assert(result != null); |
| 45 return result; | 51 return result; |
| 46 } | 52 } |
| 47 | 53 |
| 54 ast.Node getNode(ir.Node node) { |
| 55 ast.Node result = _nodeToAst[node]; |
| 56 assert(result != null); |
| 57 return result; |
| 58 } |
| 59 |
| 48 bool getCanThrow(ir.Procedure procedure) { | 60 bool getCanThrow(ir.Procedure procedure) { |
| 49 FunctionElement function = getElement(procedure); | 61 FunctionElement function = getElement(procedure); |
| 50 return !_backend.compiler.world.getCannotThrow(function); | 62 return !_compiler.world.getCannotThrow(function); |
| 51 } | 63 } |
| 52 | 64 |
| 53 TypeMask returnTypeOf(ir.Procedure node) { | 65 TypeMask returnTypeOf(ir.Procedure node) { |
| 54 return TypeMaskFactory.inferredReturnTypeForElement( | 66 return TypeMaskFactory.inferredReturnTypeForElement( |
| 55 getElement(node), _backend.compiler); | 67 getElement(node), _compiler); |
| 56 } | 68 } |
| 57 | 69 |
| 58 SideEffects getSideEffects(ir.Node node) { | 70 SideEffects getSideEffects(ir.Node node) { |
| 59 return _backend.compiler.world.getSideEffectsOfElement(getElement(node)); | 71 return _compiler.world.getSideEffectsOfElement(getElement(node)); |
| 72 } |
| 73 |
| 74 // TODO(het): Create the selector directly from the invocation |
| 75 Selector getSelector(ir.MethodInvocation invocation) { |
| 76 return _elements.getSelector(getNode(invocation)); |
| 77 } |
| 78 |
| 79 TypeMask getTypeMask(ir.MethodInvocation invocation) { |
| 80 return _elements.getTypeMask(getNode(invocation)); |
| 81 } |
| 82 |
| 83 TypeMask selectorTypeOf(ir.MethodInvocation invocation) { |
| 84 return TypeMaskFactory.inferredTypeForSelector( |
| 85 getSelector(invocation), getTypeMask(invocation), _compiler); |
| 86 } |
| 87 |
| 88 bool isIntercepted(ir.MethodInvocation invocation) { |
| 89 return _backend.isInterceptedSelector(getSelector(invocation)); |
| 60 } | 90 } |
| 61 } | 91 } |
| OLD | NEW |