| 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 '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart'; | 10 import '../common/names.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 Compiler get _compiler => _backend.compiler; | 66 Compiler get _compiler => _backend.compiler; |
| 67 TreeElements get elements => _resolvedAst.elements; | 67 TreeElements get elements => _resolvedAst.elements; |
| 68 DiagnosticReporter get reporter => _compiler.reporter; | 68 DiagnosticReporter get reporter => _compiler.reporter; |
| 69 Element get _target => _resolvedAst.element; | 69 Element get _target => _resolvedAst.element; |
| 70 | 70 |
| 71 GlobalTypeInferenceElementResult _resultOf(Element e) => | 71 GlobalTypeInferenceElementResult _resultOf(Element e) => |
| 72 _compiler.globalInference.results.resultOf(e); | 72 _compiler.globalInference.results.resultOf(e); |
| 73 | 73 |
| 74 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { | 74 ConstantValue getConstantForSymbol(ir.SymbolLiteral node) { |
| 75 if (kernel.syntheticNodes.contains(node)) { |
| 76 return _backend.constantSystem.createSymbol(_compiler, node.value); |
| 77 } |
| 75 ast.Node astNode = getNode(node); | 78 ast.Node astNode = getNode(node); |
| 76 ConstantValue constantValue = _backend.constants | 79 ConstantValue constantValue = _backend.constants |
| 77 .getConstantValueForNode(astNode, _resolvedAst.elements); | 80 .getConstantValueForNode(astNode, _resolvedAst.elements); |
| 78 assert(invariant(astNode, constantValue != null, | 81 assert(invariant(astNode, constantValue != null, |
| 79 message: 'No constant computed for $node')); | 82 message: 'No constant computed for $node')); |
| 80 return constantValue; | 83 return constantValue; |
| 81 } | 84 } |
| 82 | 85 |
| 83 // TODO(johnniwinther): Use the more precise functions below. | 86 // TODO(johnniwinther): Use the more precise functions below. |
| 84 Element getElement(ir.Node node) { | 87 Element getElement(ir.Node node) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 | 99 |
| 97 ClassElement getClass(ir.Node node) => getElement(node).declaration; | 100 ClassElement getClass(ir.Node node) => getElement(node).declaration; |
| 98 | 101 |
| 99 ast.Node getNode(ir.Node node) { | 102 ast.Node getNode(ir.Node node) { |
| 100 ast.Node result = _nodeToAst[node]; | 103 ast.Node result = _nodeToAst[node]; |
| 101 assert(invariant(CURRENT_ELEMENT_SPANNABLE, result != null, | 104 assert(invariant(CURRENT_ELEMENT_SPANNABLE, result != null, |
| 102 message: "No node found for $node")); | 105 message: "No node found for $node")); |
| 103 return result; | 106 return result; |
| 104 } | 107 } |
| 105 | 108 |
| 109 ast.Node getNodeOrNull(ir.Node node) { |
| 110 return _nodeToAst[node]; |
| 111 } |
| 112 |
| 113 void assertNodeIsSynthetic(ir.Node node) { |
| 114 assert(invariant( |
| 115 CURRENT_ELEMENT_SPANNABLE, kernel.syntheticNodes.contains(node), |
| 116 message: "No synthetic marker found for $node")); |
| 117 } |
| 118 |
| 106 Local getLocal(ir.VariableDeclaration variable) { | 119 Local getLocal(ir.VariableDeclaration variable) { |
| 107 // If this is a synthetic local, return the synthetic local | 120 // If this is a synthetic local, return the synthetic local |
| 108 if (variable.name == null) { | 121 if (variable.name == null) { |
| 109 return _syntheticLocals.putIfAbsent( | 122 return _syntheticLocals.putIfAbsent( |
| 110 variable, () => new SyntheticLocal("x", null)); | 123 variable, () => new SyntheticLocal("x", null)); |
| 111 } | 124 } |
| 112 return getElement(variable) as LocalElement; | 125 return getElement(variable) as LocalElement; |
| 113 } | 126 } |
| 114 | 127 |
| 115 bool getCanThrow(ir.Node procedure) { | 128 bool getCanThrow(ir.Node procedure) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 212 |
| 200 TypeMask typeOfSet(ir.PropertySet setter) { | 213 TypeMask typeOfSet(ir.PropertySet setter) { |
| 201 return _compiler.closedWorld.commonMasks.dynamicType; | 214 return _compiler.closedWorld.commonMasks.dynamicType; |
| 202 } | 215 } |
| 203 | 216 |
| 204 TypeMask typeOfSend(ir.Expression send) { | 217 TypeMask typeOfSend(ir.Expression send) { |
| 205 assert(send is ir.InvocationExpression || send is ir.PropertyGet); | 218 assert(send is ir.InvocationExpression || send is ir.PropertyGet); |
| 206 return _resultOf(_target).typeOfSend(getNode(send)); | 219 return _resultOf(_target).typeOfSend(getNode(send)); |
| 207 } | 220 } |
| 208 | 221 |
| 209 TypeMask typeOfNewList(Element owner, ir.ListLiteral listLiteral) { | 222 TypeMask typeOfListLiteral(Element owner, ir.ListLiteral listLiteral) { |
| 223 ast.Node node = getNodeOrNull(listLiteral); |
| 224 if (node == null) { |
| 225 assertNodeIsSynthetic(listLiteral); |
| 226 return _compiler.closedWorld.commonMasks.growableListType; |
| 227 } |
| 210 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? | 228 return _resultOf(owner).typeOfNewList(getNode(listLiteral)) ?? |
| 211 _compiler.closedWorld.commonMasks.dynamicType; | 229 _compiler.closedWorld.commonMasks.dynamicType; |
| 212 } | 230 } |
| 213 | 231 |
| 214 TypeMask typeOfIterator(ir.ForInStatement forInStatement) { | 232 TypeMask typeOfIterator(ir.ForInStatement forInStatement) { |
| 215 return _resultOf(_target).typeOfIterator(getNode(forInStatement)); | 233 return _resultOf(_target).typeOfIterator(getNode(forInStatement)); |
| 216 } | 234 } |
| 217 | 235 |
| 218 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) { | 236 TypeMask typeOfIteratorCurrent(ir.ForInStatement forInStatement) { |
| 219 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement)); | 237 return _resultOf(_target).typeOfIteratorCurrent(getNode(forInStatement)); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 415 } |
| 398 | 416 |
| 399 DartType getDartType(ir.DartType type) { | 417 DartType getDartType(ir.DartType type) { |
| 400 return type.accept(_typeConverter); | 418 return type.accept(_typeConverter); |
| 401 } | 419 } |
| 402 | 420 |
| 403 List<DartType> getDartTypes(List<ir.DartType> types) { | 421 List<DartType> getDartTypes(List<ir.DartType> types) { |
| 404 return types.map(getDartType).toList(); | 422 return types.map(getDartType).toList(); |
| 405 } | 423 } |
| 406 | 424 |
| 425 DartType getDartTypeOfListLiteral(ir.ListLiteral list) { |
| 426 ast.Node node = getNodeOrNull(list); |
| 427 if (node != null) return elements.getType(node); |
| 428 assertNodeIsSynthetic(list); |
| 429 return _compiler.coreTypes.listType(getDartType(list.typeArgument)); |
| 430 } |
| 431 |
| 432 DartType getDartTypeOfMapLiteral(ir.MapLiteral literal) { |
| 433 ast.Node node = getNodeOrNull(literal); |
| 434 if (node != null) return elements.getType(node); |
| 435 assertNodeIsSynthetic(literal); |
| 436 return _compiler.coreTypes |
| 437 .mapType(getDartType(literal.keyType), getDartType(literal.valueType)); |
| 438 } |
| 439 |
| 407 DartType getFunctionReturnType(ir.FunctionNode node) { | 440 DartType getFunctionReturnType(ir.FunctionNode node) { |
| 408 return getDartType(node.returnType); | 441 return getDartType(node.returnType); |
| 409 } | 442 } |
| 410 | 443 |
| 411 /// Computes the function type corresponding the signature of [node]. | 444 /// Computes the function type corresponding the signature of [node]. |
| 412 FunctionType getFunctionType(ir.FunctionNode node) { | 445 FunctionType getFunctionType(ir.FunctionNode node) { |
| 413 DartType returnType = getFunctionReturnType(node); | 446 DartType returnType = getFunctionReturnType(node); |
| 414 List<DartType> parameterTypes = <DartType>[]; | 447 List<DartType> parameterTypes = <DartType>[]; |
| 415 List<DartType> optionalParameterTypes = <DartType>[]; | 448 List<DartType> optionalParameterTypes = <DartType>[]; |
| 416 for (ir.VariableDeclaration variable in node.positionalParameters) { | 449 for (ir.VariableDeclaration variable in node.positionalParameters) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 astAdapter.reporter.internalError( | 814 astAdapter.reporter.internalError( |
| 782 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); | 815 CURRENT_ELEMENT_SPANNABLE, "Unexpected constant target: $element."); |
| 783 return null; | 816 return null; |
| 784 } | 817 } |
| 785 | 818 |
| 786 @override | 819 @override |
| 787 ConstantExpression visitStringLiteral(ir.StringLiteral node) { | 820 ConstantExpression visitStringLiteral(ir.StringLiteral node) { |
| 788 return new StringConstantExpression(node.value); | 821 return new StringConstantExpression(node.value); |
| 789 } | 822 } |
| 790 } | 823 } |
| OLD | NEW |