| 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 // 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it | 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it |
| 6 /// computes types on expressions to use our restricted set of types. | 6 /// computes types on expressions to use our restricted set of types. |
| 7 library dev_compiler.src.checker.resolver; | 7 library dev_compiler.src.checker.resolver; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } else { | 630 } else { |
| 631 var coreLib = _typeProvider.objectType.element.library; | 631 var coreLib = _typeProvider.objectType.element.library; |
| 632 var classElem = coreLib.getType(typeStr); | 632 var classElem = coreLib.getType(typeStr); |
| 633 if (classElem != null) { | 633 if (classElem != null) { |
| 634 var type = fillDynamicTypeArgs(classElem.type, _typeProvider); | 634 var type = fillDynamicTypeArgs(classElem.type, _typeProvider); |
| 635 node.staticType = type; | 635 node.staticType = type; |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 |
| 641 // Pretend dart:math's min and max are generic: |
| 642 // |
| 643 // T min<T extends num>(T x, T y); |
| 644 // |
| 645 // and infer T. In practice, this just means if the type of x and y are |
| 646 // both double or both int, we treat that as the return type. |
| 647 // |
| 648 // The Dart spec has similar treatment for binary operations on numbers. |
| 649 // |
| 650 // TODO(jmesserly): remove this when we have a fix for |
| 651 // https://github.com/dart-lang/dev_compiler/issues/28 |
| 652 if (isDartMathMinMax(e)) { |
| 653 var args = node.argumentList.arguments; |
| 654 if (args.length == 2) { |
| 655 var tx = args[0].staticType; |
| 656 var ty = args[1].staticType; |
| 657 if (tx == ty && |
| 658 (tx == _typeProvider.intType || tx == _typeProvider.doubleType)) { |
| 659 node.staticType = tx; |
| 660 } |
| 661 } |
| 662 } |
| 640 } | 663 } |
| 641 | 664 |
| 642 void _inferObjectAccess( | 665 void _inferObjectAccess( |
| 643 Expression node, Expression target, SimpleIdentifier id) { | 666 Expression node, Expression target, SimpleIdentifier id) { |
| 644 // Search for Object accesses. | 667 // Search for Object accesses. |
| 645 var name = id.name; | 668 var name = id.name; |
| 646 if (node.staticType.isDynamic && | 669 if (node.staticType.isDynamic && |
| 647 _objectMembers.containsKey(name) && | 670 _objectMembers.containsKey(name) && |
| 648 isDynamicTarget(target)) { | 671 isDynamicTarget(target)) { |
| 649 target.staticType = _typeProvider.objectType; | 672 target.staticType = _typeProvider.objectType; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 } | 713 } |
| 691 } | 714 } |
| 692 | 715 |
| 693 // Review note: no longer need to override visitFunctionExpression, this is | 716 // Review note: no longer need to override visitFunctionExpression, this is |
| 694 // handled by the analyzer internally. | 717 // handled by the analyzer internally. |
| 695 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 718 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 696 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 719 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 697 // type in a (...) => expr or just the written type? | 720 // type in a (...) => expr or just the written type? |
| 698 | 721 |
| 699 } | 722 } |
| OLD | NEW |