Chromium Code Reviews| 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 3378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3389 | 3389 |
| 3390 var target = _getTarget(node); | 3390 var target = _getTarget(node); |
| 3391 if (target == null || isLibraryPrefix(target)) { | 3391 if (target == null || isLibraryPrefix(target)) { |
| 3392 return _emitFunctionCall(node); | 3392 return _emitFunctionCall(node); |
| 3393 } | 3393 } |
| 3394 if (node.methodName.name == 'call') { | 3394 if (node.methodName.name == 'call') { |
| 3395 var targetType = target.staticType; | 3395 var targetType = target.staticType; |
| 3396 if (targetType is FunctionType) { | 3396 if (targetType is FunctionType) { |
| 3397 // Call methods on function types should be handled as regular function | 3397 // Call methods on function types should be handled as regular function |
| 3398 // invocations. | 3398 // invocations. |
| 3399 return _emitFunctionCall(node); | 3399 return _emitFunctionCall(node, node.target); |
| 3400 } | 3400 } |
| 3401 if (targetType.isDartCoreFunction || targetType.isDynamic) { | 3401 if (targetType.isDartCoreFunction || targetType.isDynamic) { |
| 3402 // TODO(vsm): Can a call method take generic type parameters? | 3402 // TODO(vsm): Can a call method take generic type parameters? |
| 3403 return _emitDynamicInvoke(node, _visit(target), | 3403 return _emitDynamicInvoke(node, _visit(target), |
| 3404 _visit(node.argumentList) as List<JS.Expression>); | 3404 _visit(node.argumentList) as List<JS.Expression>); |
| 3405 } | 3405 } |
| 3406 } | 3406 } |
| 3407 | 3407 |
| 3408 return _emitMethodCall(target, node); | 3408 return _emitMethodCall(target, node); |
| 3409 } | 3409 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3536 } else { | 3536 } else { |
| 3537 if (_inWhitelistCode(node, isCall: true)) { | 3537 if (_inWhitelistCode(node, isCall: true)) { |
| 3538 return new JS.Call(fn, args); | 3538 return new JS.Call(fn, args); |
| 3539 } | 3539 } |
| 3540 return _callHelper('dcall(#, #)', [fn, args]); | 3540 return _callHelper('dcall(#, #)', [fn, args]); |
| 3541 } | 3541 } |
| 3542 } | 3542 } |
| 3543 | 3543 |
| 3544 /// Emits a function call, to a top-level function, local function, or | 3544 /// Emits a function call, to a top-level function, local function, or |
| 3545 /// an expression. | 3545 /// an expression. |
| 3546 JS.Expression _emitFunctionCall(InvocationExpression node) { | 3546 JS.Expression _emitFunctionCall(InvocationExpression node, [Expression functio n]) { |
|
Jennifer Messerly
2016/12/01 23:20:33
do you mind running format?
| |
| 3547 var fn = _visit(node.function); | 3547 if (function == null) { |
| 3548 function = node.function; | |
| 3549 } | |
| 3550 var fn = _visit(function); | |
| 3548 var args = _visit(node.argumentList) as List<JS.Expression>; | 3551 var args = _visit(node.argumentList) as List<JS.Expression>; |
| 3549 if (isDynamicInvoke(node.function)) { | 3552 if (isDynamicInvoke(function)) { |
| 3550 return _emitDynamicInvoke(node, fn, args); | 3553 return _emitDynamicInvoke(node, fn, args); |
| 3551 } else { | 3554 } else { |
| 3552 return new JS.Call(_applyInvokeTypeArguments(fn, node), args); | 3555 return new JS.Call(_applyInvokeTypeArguments(fn, node), args); |
| 3553 } | 3556 } |
| 3554 } | 3557 } |
| 3555 | 3558 |
| 3556 JS.Expression _applyInvokeTypeArguments( | 3559 JS.Expression _applyInvokeTypeArguments( |
| 3557 JS.Expression target, InvocationExpression node) { | 3560 JS.Expression target, InvocationExpression node) { |
| 3558 var typeArgs = _emitInvokeTypeArguments(node); | 3561 var typeArgs = _emitInvokeTypeArguments(node); |
| 3559 if (typeArgs == null) return target; | 3562 if (typeArgs == null) return target; |
| (...skipping 2206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5766 var targetIdentifier = target as SimpleIdentifier; | 5769 var targetIdentifier = target as SimpleIdentifier; |
| 5767 | 5770 |
| 5768 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5771 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 5769 var prefix = targetIdentifier.staticElement as PrefixElement; | 5772 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 5770 | 5773 |
| 5771 // The library the prefix is referring to must come from a deferred import. | 5774 // The library the prefix is referring to must come from a deferred import. |
| 5772 var containingLibrary = (target.root as CompilationUnit).element.library; | 5775 var containingLibrary = (target.root as CompilationUnit).element.library; |
| 5773 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5776 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 5774 return imports.length == 1 && imports[0].isDeferred; | 5777 return imports.length == 1 && imports[0].isDeferred; |
| 5775 } | 5778 } |
| OLD | NEW |