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 '../constants/values.dart'; | 7 import '../constants/values.dart'; |
8 import '../diagnostics/invariant.dart'; | 8 import '../diagnostics/invariant.dart'; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../js_backend/js_backend.dart'; | 10 import '../js_backend/js_backend.dart'; |
11 import '../tree/tree.dart' as ast; | 11 import '../tree/tree.dart' as ast; |
| 12 import '../types/masks.dart'; |
| 13 import '../universe/side_effects.dart'; |
| 14 |
| 15 import 'types.dart'; |
12 | 16 |
13 /// A helper class that abstracts all accesses of the AST from Kernel nodes. | 17 /// A helper class that abstracts all accesses of the AST from Kernel nodes. |
14 /// | 18 /// |
15 /// The goal is to remove all need for the AST from the Kernel SSA builder. | 19 /// The goal is to remove all need for the AST from the Kernel SSA builder. |
16 class KernelAstAdapter { | 20 class KernelAstAdapter { |
17 final JavaScriptBackend backend; | 21 final JavaScriptBackend _backend; |
18 final ResolvedAst resolvedAst; | 22 final ResolvedAst _resolvedAst; |
19 final Map<ir.Node, ast.Node> nodeToAst; | 23 final Map<ir.Node, ast.Node> _nodeToAst; |
| 24 final Map<ir.Node, Element> _nodeToElement; |
20 | 25 |
21 KernelAstAdapter(this.backend, this.resolvedAst, this.nodeToAst); | 26 KernelAstAdapter(this._backend, this._resolvedAst, this._nodeToAst, |
| 27 this._nodeToElement, Map<FunctionElement, ir.Member> functions) { |
| 28 for (FunctionElement functionElement in functions.keys) { |
| 29 _nodeToElement[functions[functionElement]] = functionElement; |
| 30 } |
| 31 } |
22 | 32 |
23 ConstantValue getConstantFor(ir.Node node) { | 33 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { |
24 ast.Node astNode = nodeToAst[node]; | 34 ast.Node astNode = _nodeToAst[node]; |
25 ConstantValue constantValue = backend.constants | 35 ConstantValue constantValue = _backend.constants |
26 .getConstantValueForNode(astNode, resolvedAst.elements); | 36 .getConstantValueForNode(astNode, _resolvedAst.elements); |
27 assert(invariant(astNode, constantValue != null, | 37 assert(invariant(astNode, constantValue != null, |
28 message: 'No constant computed for $node')); | 38 message: 'No constant computed for $node')); |
29 return constantValue; | 39 return constantValue; |
30 } | 40 } |
| 41 |
| 42 Element getElement(ir.Node node) { |
| 43 Element result = _nodeToElement[node]; |
| 44 assert(result != null); |
| 45 return result; |
| 46 } |
| 47 |
| 48 bool getCanThrow(ir.Procedure procedure) { |
| 49 FunctionElement function = getElement(procedure); |
| 50 return !_backend.compiler.world.getCannotThrow(function); |
| 51 } |
| 52 |
| 53 TypeMask returnTypeOf(ir.Procedure node) { |
| 54 return TypeMaskFactory.inferredReturnTypeForElement( |
| 55 getElement(node), _backend.compiler); |
| 56 } |
| 57 |
| 58 SideEffects getSideEffects(ir.Node node) { |
| 59 return _backend.compiler.world.getSideEffectsOfElement(getElement(node)); |
| 60 } |
31 } | 61 } |
OLD | NEW |