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/expressions.dart'; | 7 import '../constants/expressions.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 _nodeToElement[kernel.libraries[libraryElement]] = libraryElement; | 56 _nodeToElement[kernel.libraries[libraryElement]] = libraryElement; |
57 } | 57 } |
58 for (LocalFunctionElement localFunction in kernel.localFunctions.keys) { | 58 for (LocalFunctionElement localFunction in kernel.localFunctions.keys) { |
59 _nodeToElement[kernel.localFunctions[localFunction]] = localFunction; | 59 _nodeToElement[kernel.localFunctions[localFunction]] = localFunction; |
60 } | 60 } |
61 _typeConverter = new DartTypeConverter(this); | 61 _typeConverter = new DartTypeConverter(this); |
62 } | 62 } |
63 | 63 |
64 Compiler get _compiler => _backend.compiler; | 64 Compiler get _compiler => _backend.compiler; |
65 TreeElements get elements => _resolvedAst.elements; | 65 TreeElements get elements => _resolvedAst.elements; |
66 GlobalTypeInferenceResults get _inferenceResults => | |
67 _compiler.globalInference.results; | |
68 DiagnosticReporter get reporter => _compiler.reporter; | 66 DiagnosticReporter get reporter => _compiler.reporter; |
| 67 Element get _target => _resolvedAst.element; |
| 68 |
| 69 GlobalTypeInferenceElementResult _resultOf(Element e) => |
| 70 _compiler.globalInference.results.resultOf(e); |
69 | 71 |
70 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { | 72 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { |
71 ast.Node astNode = getNode(node); | 73 ast.Node astNode = getNode(node); |
72 ConstantValue constantValue = _backend.constants | 74 ConstantValue constantValue = _backend.constants |
73 .getConstantValueForNode(astNode, _resolvedAst.elements); | 75 .getConstantValueForNode(astNode, _resolvedAst.elements); |
74 assert(invariant(astNode, constantValue != null, | 76 assert(invariant(astNode, constantValue != null, |
75 message: 'No constant computed for $node')); | 77 message: 'No constant computed for $node')); |
76 return constantValue; | 78 return constantValue; |
77 } | 79 } |
78 | 80 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 151 } |
150 | 152 |
151 Selector getGetterSelector(ir.PropertyGet getter) { | 153 Selector getGetterSelector(ir.PropertyGet getter) { |
152 ir.Name irName = getter.name; | 154 ir.Name irName = getter.name; |
153 Name name = new Name( | 155 Name name = new Name( |
154 irName.name, irName.isPrivate ? getElement(irName.library) : null); | 156 irName.name, irName.isPrivate ? getElement(irName.library) : null); |
155 return new Selector.getter(name); | 157 return new Selector.getter(name); |
156 } | 158 } |
157 | 159 |
158 TypeMask typeOfInvocation(ir.Expression send) { | 160 TypeMask typeOfInvocation(ir.Expression send) { |
159 return _inferenceResults.typeOfSend(getNode(send), elements); | 161 return _resultOf(_target).typeOfSend(getNode(send)); |
160 } | 162 } |
161 | 163 |
162 TypeMask typeOfGet(ir.PropertyGet getter) { | 164 TypeMask typeOfGet(ir.PropertyGet getter) { |
163 return _inferenceResults.typeOfSend(getNode(getter), elements); | 165 return _resultOf(_target).typeOfSend(getNode(getter)); |
164 } | 166 } |
165 | 167 |
166 TypeMask typeOfSend(ir.Expression send) { | 168 TypeMask typeOfSend(ir.Expression send) { |
167 assert(send is ir.InvocationExpression || send is ir.PropertyGet); | 169 assert(send is ir.InvocationExpression || send is ir.PropertyGet); |
168 return _inferenceResults.typeOfSend(getNode(send), elements); | 170 return _resultOf(_target).typeOfSend(getNode(send)); |
169 } | 171 } |
170 | 172 |
171 TypeMask typeOfNewList(Element owner, ir.ListLiteral listLiteral) { | 173 TypeMask typeOfNewList(Element owner, ir.ListLiteral listLiteral) { |
172 return _inferenceResults.typeOfNewList(owner, getNode(listLiteral)) ?? | 174 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? |
173 _compiler.commonMasks.dynamicType; | 175 _compiler.commonMasks.dynamicType; |
174 } | 176 } |
175 | 177 |
176 TypeMask typeOfIterator(ir.ForInStatement forInStatement) { | 178 TypeMask typeOfIterator(ir.ForInStatement forInStatement) { |
177 return _inferenceResults.typeOfIterator(getNode(forInStatement), elements); | 179 return _resultOf(_target).typeOfIterator(getNode(forInStatement)); |
178 } | 180 } |
179 | 181 |
180 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) { | 182 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) { |
181 return _inferenceResults.typeOfIteratorCurrent( | 183 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement)); |
182 getNode(forInStatement), elements); | |
183 } | 184 } |
184 | 185 |
185 TypeMask typeOfIteratorMoveNext(ir.ForInStatement forInStatement) { | 186 TypeMask typeOfIteratorMoveNext(ir.ForInStatement forInStatement) { |
186 return _inferenceResults.typeOfIteratorMoveNext( | 187 return _resultOf(_target).typeOfIteratorMoveNext(getNode(forInStatement)); |
187 getNode(forInStatement), elements); | |
188 } | 188 } |
189 | 189 |
190 bool isJsIndexableIterator(ir.ForInStatement forInStatement) { | 190 bool isJsIndexableIterator(ir.ForInStatement forInStatement) { |
191 TypeMask mask = typeOfIterator(forInStatement); | 191 TypeMask mask = typeOfIterator(forInStatement); |
192 ClosedWorld closedWorld = _compiler.closedWorld; | 192 ClosedWorld closedWorld = _compiler.closedWorld; |
193 return mask != null && | 193 return mask != null && |
194 mask.satisfies(_backend.helpers.jsIndexableClass, closedWorld) && | 194 mask.satisfies(_backend.helpers.jsIndexableClass, closedWorld) && |
195 // String is indexable but not iterable. | 195 // String is indexable but not iterable. |
196 !mask.satisfies(_backend.helpers.jsStringClass, closedWorld); | 196 !mask.satisfies(_backend.helpers.jsStringClass, closedWorld); |
197 } | 197 } |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 node.arguments.positional.length + argumentNames.length, | 629 node.arguments.positional.length + argumentNames.length, |
630 argumentNames), | 630 argumentNames), |
631 arguments); | 631 arguments); |
632 } | 632 } |
633 | 633 |
634 @override | 634 @override |
635 ConstantExpression visitStringLiteral(ir.StringLiteral node) { | 635 ConstantExpression visitStringLiteral(ir.StringLiteral node) { |
636 return new StringConstantExpression(node.value); | 636 return new StringConstantExpression(node.value); |
637 } | 637 } |
638 } | 638 } |
OLD | NEW |