| 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:js_runtime/shared/embedded_names.dart'; | 5 import 'package:js_runtime/shared/embedded_names.dart'; |
| 6 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
| 7 | 7 |
| 8 import '../closure.dart'; | 8 import '../closure.dart'; |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 for (LocalFunctionElement localFunction in kernel.localFunctions.keys) { | 79 for (LocalFunctionElement localFunction in kernel.localFunctions.keys) { |
| 80 _nodeToElement[kernel.localFunctions[localFunction]] = localFunction; | 80 _nodeToElement[kernel.localFunctions[localFunction]] = localFunction; |
| 81 } | 81 } |
| 82 for (TypeVariableElement typeVariable in kernel.typeParameters.keys) { | 82 for (TypeVariableElement typeVariable in kernel.typeParameters.keys) { |
| 83 _nodeToElement[kernel.typeParameters[typeVariable]] = typeVariable; | 83 _nodeToElement[kernel.typeParameters[typeVariable]] = typeVariable; |
| 84 } | 84 } |
| 85 _typeConverter = new DartTypeConverter(this); | 85 _typeConverter = new DartTypeConverter(this); |
| 86 } | 86 } |
| 87 | 87 |
| 88 @override | 88 @override |
| 89 ConstantValue computeConstantValue(ConstantExpression constant) { | 89 ConstantValue computeConstantValue(ConstantExpression constant, |
| 90 return _compiler.constants.getConstantValue(constant); | 90 {bool requireConstant: true}) { |
| 91 _compiler.backend.constants.evaluate(constant); |
| 92 ConstantValue value = |
| 93 _compiler.backend.constants.getConstantValue(constant); |
| 94 if (value == null && requireConstant) { |
| 95 throw new UnsupportedError( |
| 96 'No constant value for ${constant.toStructuredText()}'); |
| 97 } |
| 98 return value; |
| 91 } | 99 } |
| 92 | 100 |
| 93 /// Called to find the corresponding Kernel element for a particular Element | 101 /// Called to find the corresponding Kernel element for a particular Element |
| 94 /// before traversing over it with a Kernel visitor. | 102 /// before traversing over it with a Kernel visitor. |
| 95 ir.Node getInitialKernelNode(MemberElement originTarget) { | 103 ir.Node getInitialKernelNode(MemberElement originTarget) { |
| 96 ir.Node target; | 104 ir.Node target; |
| 97 if (originTarget.isPatch) { | 105 if (originTarget.isPatch) { |
| 98 originTarget = originTarget.origin; | 106 originTarget = originTarget.origin; |
| 99 } | 107 } |
| 100 if (originTarget is MethodElement) { | 108 if (originTarget is MethodElement) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 149 |
| 142 void assertAtResolvedAstFor(ir.Node node) { | 150 void assertAtResolvedAstFor(ir.Node node) { |
| 143 assert(invariant(getElement(node), | 151 assert(invariant(getElement(node), |
| 144 _resolvedAst.element == getElement(node).declaration)); | 152 _resolvedAst.element == getElement(node).declaration)); |
| 145 } | 153 } |
| 146 | 154 |
| 147 Compiler get _compiler => _backend.compiler; | 155 Compiler get _compiler => _backend.compiler; |
| 148 TreeElements get elements => _resolvedAst.elements; | 156 TreeElements get elements => _resolvedAst.elements; |
| 149 DiagnosticReporter get reporter => _compiler.reporter; | 157 DiagnosticReporter get reporter => _compiler.reporter; |
| 150 | 158 |
| 151 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { | |
| 152 if (kernel.syntheticNodes.contains(node)) { | |
| 153 return _backend.constantSystem | |
| 154 .createSymbol(_compiler.commonElements, node.value); | |
| 155 } | |
| 156 ast.Node astNode = getNode(node); | |
| 157 ConstantValue constantValue = _backend.constants | |
| 158 .getConstantValueForNode(astNode, _resolvedAst.elements); | |
| 159 assert(invariant(astNode, constantValue != null, | |
| 160 message: 'No constant computed for $node')); | |
| 161 return constantValue; | |
| 162 } | |
| 163 | |
| 164 // TODO(johnniwinther): Use the more precise functions below. | 159 // TODO(johnniwinther): Use the more precise functions below. |
| 165 Element getElement(ir.Node node) { | 160 Element getElement(ir.Node node) { |
| 166 Element result = _nodeToElement[node]; | 161 Element result = _nodeToElement[node]; |
| 167 assert(invariant(CURRENT_ELEMENT_SPANNABLE, result != null, | 162 assert(invariant(CURRENT_ELEMENT_SPANNABLE, result != null, |
| 168 message: "No element found for $node.")); | 163 message: "No element found for $node.")); |
| 169 return result; | 164 return result; |
| 170 } | 165 } |
| 171 | 166 |
| 172 ConstructorElement getConstructor(ir.Member node) => | 167 ConstructorElement getConstructor(ir.Member node) => |
| 173 getElement(node).declaration; | 168 getElement(node).declaration; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 return _syntheticLocals.putIfAbsent( | 217 return _syntheticLocals.putIfAbsent( |
| 223 variable, () => new SyntheticLocal("x", null, null)); | 218 variable, () => new SyntheticLocal("x", null, null)); |
| 224 } | 219 } |
| 225 return getElement(variable) as LocalElement; | 220 return getElement(variable) as LocalElement; |
| 226 } | 221 } |
| 227 | 222 |
| 228 FunctionSignature getFunctionSignature(ir.FunctionNode function) { | 223 FunctionSignature getFunctionSignature(ir.FunctionNode function) { |
| 229 return getElement(function).asFunctionElement().functionSignature; | 224 return getElement(function).asFunctionElement().functionSignature; |
| 230 } | 225 } |
| 231 | 226 |
| 232 ConstantValue getConstantFor(ir.Node node) { | |
| 233 // Some `null`s are not mapped when they correspond to errors, e.g. missing | |
| 234 // `const` initializers. | |
| 235 if (node is ir.NullLiteral) return new NullConstantValue(); | |
| 236 | |
| 237 ConstantValue constantValue = | |
| 238 _backend.constants.getConstantValueForNode(getNode(node), elements); | |
| 239 assert(invariant(getNode(node), constantValue != null, | |
| 240 message: 'No constant computed for $node')); | |
| 241 return constantValue; | |
| 242 } | |
| 243 | |
| 244 ConstantValue getConstantForParameterDefaultValue(ir.Node defaultExpression) { | |
| 245 // TODO(27394): Evaluate constant expressions in ir.Node domain. | |
| 246 // In the interim, expand the Constantifier and do this: | |
| 247 // | |
| 248 // ConstantExpression constantExpression = | |
| 249 // defaultExpression.accept(new Constantifier(this)); | |
| 250 // assert(constantExpression != null); | |
| 251 ConstantExpression constantExpression = | |
| 252 kernel.parameterInitializerNodeToConstant[defaultExpression]; | |
| 253 if (constantExpression == null) return null; | |
| 254 return _backend.constants.getConstantValue(constantExpression); | |
| 255 } | |
| 256 | |
| 257 ConstantValue getConstantForType(ir.DartType irType) { | |
| 258 ResolutionDartType type = getDartType(irType); | |
| 259 return _backend.constantSystem | |
| 260 .createType(_compiler.commonElements, type.asRaw()); | |
| 261 } | |
| 262 | |
| 263 // Is the member a lazy initialized static or top-level member? | 227 // Is the member a lazy initialized static or top-level member? |
| 264 bool isLazyStatic(ir.Member member) { | 228 bool isLazyStatic(ir.Member member) { |
| 265 if (member is ir.Field) { | 229 if (member is ir.Field) { |
| 266 FieldElement field = _nodeToElement[member]; | 230 FieldElement field = _nodeToElement[member]; |
| 267 return field.constant == null; | 231 return field.constant == null; |
| 268 } | 232 } |
| 269 return false; | 233 return false; |
| 270 } | 234 } |
| 271 | 235 |
| 272 KernelJumpTarget getJumpTarget(ir.TreeNode node, | 236 KernelJumpTarget getJumpTarget(ir.TreeNode node, |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { | 649 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { |
| 686 return TypeMaskFactory.inferredTypeForSelector( | 650 return TypeMaskFactory.inferredTypeForSelector( |
| 687 selector, mask, _globalInferenceResults); | 651 selector, mask, _globalInferenceResults); |
| 688 } | 652 } |
| 689 | 653 |
| 690 TypeMask typeFromNativeBehavior( | 654 TypeMask typeFromNativeBehavior( |
| 691 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { | 655 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { |
| 692 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); | 656 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); |
| 693 } | 657 } |
| 694 } | 658 } |
| OLD | NEW |