| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 | 2 |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
| 7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 4537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4548 if (_isNull(left) || _isNull(right)) return true; | 4548 if (_isNull(left) || _isNull(right)) return true; |
| 4549 | 4549 |
| 4550 var leftType = _canonicalizeNumTypes(getStaticType(left)); | 4550 var leftType = _canonicalizeNumTypes(getStaticType(left)); |
| 4551 var rightType = _canonicalizeNumTypes(getStaticType(right)); | 4551 var rightType = _canonicalizeNumTypes(getStaticType(right)); |
| 4552 return isPrimitiveType(leftType) && leftType == rightType; | 4552 return isPrimitiveType(leftType) && leftType == rightType; |
| 4553 } | 4553 } |
| 4554 | 4554 |
| 4555 bool _isNull(Expression expr) => expr is NullLiteral; | 4555 bool _isNull(Expression expr) => expr is NullLiteral; |
| 4556 | 4556 |
| 4557 SimpleIdentifier _createTemporary(String name, DartType type, | 4557 SimpleIdentifier _createTemporary(String name, DartType type, |
| 4558 {bool nullable: true, JS.Expression variable}) { | 4558 {bool nullable: true, JS.Expression variable, bool dynamicInvoke}) { |
| 4559 // We use an invalid source location to signal that this is a temporary. | 4559 // We use an invalid source location to signal that this is a temporary. |
| 4560 // See [_isTemporary]. | 4560 // See [_isTemporary]. |
| 4561 // TODO(jmesserly): alternatives are | 4561 // TODO(jmesserly): alternatives are |
| 4562 // * (ab)use Element.isSynthetic, which isn't currently used for | 4562 // * (ab)use Element.isSynthetic, which isn't currently used for |
| 4563 // LocalVariableElementImpl, so we could repurpose to mean "temp". | 4563 // LocalVariableElementImpl, so we could repurpose to mean "temp". |
| 4564 // * add a new property to LocalVariableElementImpl. | 4564 // * add a new property to LocalVariableElementImpl. |
| 4565 // * create a new subtype of LocalVariableElementImpl to mark a temp. | 4565 // * create a new subtype of LocalVariableElementImpl to mark a temp. |
| 4566 var id = astFactory | 4566 var id = astFactory |
| 4567 .simpleIdentifier(new StringToken(TokenType.IDENTIFIER, name, -1)); | 4567 .simpleIdentifier(new StringToken(TokenType.IDENTIFIER, name, -1)); |
| 4568 | 4568 |
| 4569 variable ??= new JS.TemporaryId(name); | 4569 variable ??= new JS.TemporaryId(name); |
| 4570 | 4570 |
| 4571 id.staticElement = new TemporaryVariableElement.forNode(id, variable); | 4571 id.staticElement = new TemporaryVariableElement.forNode(id, variable); |
| 4572 id.staticType = type; | 4572 id.staticType = type; |
| 4573 setIsDynamicInvoke(id, type.isDynamic); | 4573 setIsDynamicInvoke(id, dynamicInvoke ?? type.isDynamic); |
| 4574 addTemporaryVariable(id.staticElement, nullable: nullable); | 4574 addTemporaryVariable(id.staticElement, nullable: nullable); |
| 4575 return id; | 4575 return id; |
| 4576 } | 4576 } |
| 4577 | 4577 |
| 4578 JS.Expression _cacheConst(JS.Expression expr()) { | 4578 JS.Expression _cacheConst(JS.Expression expr()) { |
| 4579 var savedTypeParams = _typeParamInConst; | 4579 var savedTypeParams = _typeParamInConst; |
| 4580 _typeParamInConst = []; | 4580 _typeParamInConst = []; |
| 4581 | 4581 |
| 4582 var jsExpr = expr(); | 4582 var jsExpr = expr(); |
| 4583 | 4583 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4658 /// variables), then the resulting code will be simplified automatically. | 4658 /// variables), then the resulting code will be simplified automatically. |
| 4659 /// | 4659 /// |
| 4660 /// [scope] will be mutated to contain the new temporary's initialization. | 4660 /// [scope] will be mutated to contain the new temporary's initialization. |
| 4661 Expression _bindValue(Map<JS.MetaLetVariable, JS.Expression> scope, | 4661 Expression _bindValue(Map<JS.MetaLetVariable, JS.Expression> scope, |
| 4662 String name, Expression expr, | 4662 String name, Expression expr, |
| 4663 {Expression context}) { | 4663 {Expression context}) { |
| 4664 // No need to do anything for stateless expressions. | 4664 // No need to do anything for stateless expressions. |
| 4665 if (isStateless(_currentFunction, expr, context)) return expr; | 4665 if (isStateless(_currentFunction, expr, context)) return expr; |
| 4666 | 4666 |
| 4667 var variable = new JS.MetaLetVariable(name); | 4667 var variable = new JS.MetaLetVariable(name); |
| 4668 var t = _createTemporary(name, getStaticType(expr), variable: variable); | 4668 var t = _createTemporary(name, getStaticType(expr), |
| 4669 variable: variable, |
| 4670 dynamicInvoke: isDynamicInvoke(expr), |
| 4671 nullable: isNullable(expr)); |
| 4669 scope[variable] = _visit(expr); | 4672 scope[variable] = _visit(expr); |
| 4670 return t; | 4673 return t; |
| 4671 } | 4674 } |
| 4672 | 4675 |
| 4673 /// Desugars postfix increment. | 4676 /// Desugars postfix increment. |
| 4674 /// | 4677 /// |
| 4675 /// In the general case [expr] can be one of [IndexExpression], | 4678 /// In the general case [expr] can be one of [IndexExpression], |
| 4676 /// [PrefixExpression] or [PropertyAccess] and we need to | 4679 /// [PrefixExpression] or [PropertyAccess] and we need to |
| 4677 /// ensure sub-expressions are evaluated once. | 4680 /// ensure sub-expressions are evaluated once. |
| 4678 /// | 4681 /// |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4860 var tail = <JS.Expression>[]; | 4863 var tail = <JS.Expression>[]; |
| 4861 for (;;) { | 4864 for (;;) { |
| 4862 var op = _getOperator(node); | 4865 var op = _getOperator(node); |
| 4863 if (op != null && op.lexeme == '?.') { | 4866 if (op != null && op.lexeme == '?.') { |
| 4864 var nodeTarget = _getTarget(node); | 4867 var nodeTarget = _getTarget(node); |
| 4865 if (!isNullable(nodeTarget)) { | 4868 if (!isNullable(nodeTarget)) { |
| 4866 node = _stripNullAwareOp(node, nodeTarget); | 4869 node = _stripNullAwareOp(node, nodeTarget); |
| 4867 break; | 4870 break; |
| 4868 } | 4871 } |
| 4869 | 4872 |
| 4870 var param = | 4873 var param = _createTemporary('_', nodeTarget.staticType, |
| 4871 _createTemporary('_', nodeTarget.staticType, nullable: false); | 4874 nullable: false, dynamicInvoke: isDynamicInvoke(node)); |
| 4872 var baseNode = _stripNullAwareOp(node, param); | 4875 var baseNode = _stripNullAwareOp(node, param); |
| 4873 tail.add( | 4876 tail.add( |
| 4874 new JS.ArrowFun(<JS.Parameter>[_visit(param)], _visit(baseNode))); | 4877 new JS.ArrowFun(<JS.Parameter>[_visit(param)], _visit(baseNode))); |
| 4875 node = nodeTarget; | 4878 node = nodeTarget; |
| 4876 } else { | 4879 } else { |
| 4877 break; | 4880 break; |
| 4878 } | 4881 } |
| 4879 } | 4882 } |
| 4880 if (tail.isEmpty) return _visit(node); | 4883 if (tail.isEmpty) return _visit(node); |
| 4881 return _callHelper( | 4884 return _callHelper( |
| (...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6128 if (targetIdentifier.staticElement is! PrefixElement) return false; | 6131 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 6129 var prefix = targetIdentifier.staticElement as PrefixElement; | 6132 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 6130 | 6133 |
| 6131 // The library the prefix is referring to must come from a deferred import. | 6134 // The library the prefix is referring to must come from a deferred import. |
| 6132 var containingLibrary = resolutionMap | 6135 var containingLibrary = resolutionMap |
| 6133 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 6136 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 6134 .library; | 6137 .library; |
| 6135 var imports = containingLibrary.getImportsWithPrefix(prefix); | 6138 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 6136 return imports.length == 1 && imports[0].isDeferred; | 6139 return imports.length == 1 && imports[0].isDeferred; |
| 6137 } | 6140 } |
| OLD | NEW |