Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 13420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13431 * Return the type representing the built-in type 'Null'. | 13431 * Return the type representing the built-in type 'Null'. |
| 13432 */ | 13432 */ |
| 13433 InterfaceType get nullType; | 13433 InterfaceType get nullType; |
| 13434 | 13434 |
| 13435 /** | 13435 /** |
| 13436 * Return the type representing the built-in type 'num'. | 13436 * Return the type representing the built-in type 'num'. |
| 13437 */ | 13437 */ |
| 13438 InterfaceType get numType; | 13438 InterfaceType get numType; |
| 13439 | 13439 |
| 13440 /** | 13440 /** |
| 13441 * Return a Map mapping the method and getter names on the built-in type | |
| 13442 * 'Object' to their types and return types (respectively). | |
| 13443 */ | |
| 13444 Map<String, DartType> get objectMemberTypes; | |
|
Brian Wilkerson
2015/09/22 18:36:53
I'm not thrilled with this getter for three reason
Jennifer Messerly
2015/09/22 18:45:52
+1 ... I recall trying this refactoring myself at
Leaf
2015/09/22 19:55:22
I can take a look at changing this. I don't think
Brian Wilkerson
2015/09/22 20:01:32
Another option would be to add a 'getInstanceGette
| |
| 13445 | |
| 13446 /** | |
| 13441 * Return the type representing the built-in type 'Object'. | 13447 * Return the type representing the built-in type 'Object'. |
| 13442 */ | 13448 */ |
| 13443 InterfaceType get objectType; | 13449 InterfaceType get objectType; |
| 13444 | 13450 |
| 13445 /** | 13451 /** |
| 13446 * Return the type representing the built-in type 'StackTrace'. | 13452 * Return the type representing the built-in type 'StackTrace'. |
| 13447 */ | 13453 */ |
| 13448 InterfaceType get stackTraceType; | 13454 InterfaceType get stackTraceType; |
| 13449 | 13455 |
| 13450 /** | 13456 /** |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13562 * The type representing the type 'Null'. | 13568 * The type representing the type 'Null'. |
| 13563 */ | 13569 */ |
| 13564 InterfaceType _nullType; | 13570 InterfaceType _nullType; |
| 13565 | 13571 |
| 13566 /** | 13572 /** |
| 13567 * The type representing the built-in type 'num'. | 13573 * The type representing the built-in type 'num'. |
| 13568 */ | 13574 */ |
| 13569 InterfaceType _numType; | 13575 InterfaceType _numType; |
| 13570 | 13576 |
| 13571 /** | 13577 /** |
| 13578 * The types and return types of the methods and getters (respectively) in | |
| 13579 * the built-in type 'Object'. | |
| 13580 */ | |
| 13581 Map<String, DartType> _objectMemberTypes; | |
| 13582 | |
| 13583 /** | |
| 13572 * The type representing the built-in type 'Object'. | 13584 * The type representing the built-in type 'Object'. |
| 13573 */ | 13585 */ |
| 13574 InterfaceType _objectType; | 13586 InterfaceType _objectType; |
| 13575 | 13587 |
| 13576 /** | 13588 /** |
| 13577 * The type representing the built-in type 'StackTrace'. | 13589 * The type representing the built-in type 'StackTrace'. |
| 13578 */ | 13590 */ |
| 13579 InterfaceType _stackTraceType; | 13591 InterfaceType _stackTraceType; |
| 13580 | 13592 |
| 13581 /** | 13593 /** |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13689 return _nullObject; | 13701 return _nullObject; |
| 13690 } | 13702 } |
| 13691 | 13703 |
| 13692 @override | 13704 @override |
| 13693 InterfaceType get nullType => _nullType; | 13705 InterfaceType get nullType => _nullType; |
| 13694 | 13706 |
| 13695 @override | 13707 @override |
| 13696 InterfaceType get numType => _numType; | 13708 InterfaceType get numType => _numType; |
| 13697 | 13709 |
| 13698 @override | 13710 @override |
| 13711 Map<String, DartType> get objectMemberTypes { | |
| 13712 if (_objectMemberTypes == null) { | |
| 13713 Map<String, DartType> map = <String, DartType>{}; | |
| 13714 ClassElement element = objectType.element; | |
| 13715 // Add instance methods. | |
| 13716 element.methods.where((method) => !method.isStatic).forEach((method) { | |
| 13717 map[method.name] = method.type; | |
| 13718 }); | |
| 13719 // Add getters. | |
| 13720 element.accessors | |
| 13721 .where((member) => !member.isStatic && member.isGetter) | |
| 13722 .forEach((member) { | |
| 13723 map[member.name] = member.type.returnType; | |
| 13724 }); | |
| 13725 _objectMemberTypes = map; | |
| 13726 } | |
| 13727 return _objectMemberTypes; | |
| 13728 } | |
| 13729 | |
| 13730 @override | |
| 13699 InterfaceType get objectType => _objectType; | 13731 InterfaceType get objectType => _objectType; |
| 13700 | 13732 |
| 13701 @override | 13733 @override |
| 13702 InterfaceType get stackTraceType => _stackTraceType; | 13734 InterfaceType get stackTraceType => _stackTraceType; |
| 13703 | 13735 |
| 13704 @override | 13736 @override |
| 13705 InterfaceType get streamDynamicType => _streamDynamicType; | 13737 InterfaceType get streamDynamicType => _streamDynamicType; |
| 13706 | 13738 |
| 13707 @override | 13739 @override |
| 13708 InterfaceType get streamType => _streamType; | 13740 InterfaceType get streamType => _streamType; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13748 _doubleType = _getType(coreNamespace, "double"); | 13780 _doubleType = _getType(coreNamespace, "double"); |
| 13749 _dynamicType = DynamicTypeImpl.instance; | 13781 _dynamicType = DynamicTypeImpl.instance; |
| 13750 _functionType = _getType(coreNamespace, "Function"); | 13782 _functionType = _getType(coreNamespace, "Function"); |
| 13751 _futureType = _getType(asyncNamespace, "Future"); | 13783 _futureType = _getType(asyncNamespace, "Future"); |
| 13752 _intType = _getType(coreNamespace, "int"); | 13784 _intType = _getType(coreNamespace, "int"); |
| 13753 _iterableType = _getType(coreNamespace, "Iterable"); | 13785 _iterableType = _getType(coreNamespace, "Iterable"); |
| 13754 _listType = _getType(coreNamespace, "List"); | 13786 _listType = _getType(coreNamespace, "List"); |
| 13755 _mapType = _getType(coreNamespace, "Map"); | 13787 _mapType = _getType(coreNamespace, "Map"); |
| 13756 _nullType = _getType(coreNamespace, "Null"); | 13788 _nullType = _getType(coreNamespace, "Null"); |
| 13757 _numType = _getType(coreNamespace, "num"); | 13789 _numType = _getType(coreNamespace, "num"); |
| 13790 _objectMemberTypes = null; | |
| 13758 _objectType = _getType(coreNamespace, "Object"); | 13791 _objectType = _getType(coreNamespace, "Object"); |
| 13759 _stackTraceType = _getType(coreNamespace, "StackTrace"); | 13792 _stackTraceType = _getType(coreNamespace, "StackTrace"); |
| 13760 _streamType = _getType(asyncNamespace, "Stream"); | 13793 _streamType = _getType(asyncNamespace, "Stream"); |
| 13761 _stringType = _getType(coreNamespace, "String"); | 13794 _stringType = _getType(coreNamespace, "String"); |
| 13762 _symbolType = _getType(coreNamespace, "Symbol"); | 13795 _symbolType = _getType(coreNamespace, "Symbol"); |
| 13763 _typeType = _getType(coreNamespace, "Type"); | 13796 _typeType = _getType(coreNamespace, "Type"); |
| 13764 _undefinedType = UndefinedTypeImpl.instance; | 13797 _undefinedType = UndefinedTypeImpl.instance; |
| 13765 _futureDynamicType = _futureType.substitute4(<DartType>[_dynamicType]); | 13798 _futureDynamicType = _futureType.substitute4(<DartType>[_dynamicType]); |
| 13766 _futureNullType = _futureType.substitute4(<DartType>[_nullType]); | 13799 _futureNullType = _futureType.substitute4(<DartType>[_nullType]); |
| 13767 _iterableDynamicType = _iterableType.substitute4(<DartType>[_dynamicType]); | 13800 _iterableDynamicType = _iterableType.substitute4(<DartType>[_dynamicType]); |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15090 * https://github.com/dart-lang/dev_compiler/blob/master/STRONG_MODE.md | 15123 * https://github.com/dart-lang/dev_compiler/blob/master/STRONG_MODE.md |
| 15091 */ | 15124 */ |
| 15092 class StrongTypeSystemImpl implements TypeSystem { | 15125 class StrongTypeSystemImpl implements TypeSystem { |
| 15093 StrongTypeSystemImpl(); | 15126 StrongTypeSystemImpl(); |
| 15094 | 15127 |
| 15095 final _specTypeSystem = new TypeSystemImpl(); | 15128 final _specTypeSystem = new TypeSystemImpl(); |
| 15096 | 15129 |
| 15097 @override | 15130 @override |
| 15098 DartType getLeastUpperBound( | 15131 DartType getLeastUpperBound( |
| 15099 TypeProvider typeProvider, DartType type1, DartType type2) { | 15132 TypeProvider typeProvider, DartType type1, DartType type2) { |
| 15133 // TODO(vsm): The static type of a conditional should be the LUB of the | |
|
Paul Berry
2015/09/22 18:23:13
Are you sure this is necessary? I thought I fixed
Leaf
2015/09/22 18:37:28
Right you are, thanks! Code removed, tests still
| |
| 15134 // then and else expressions. The analyzer appears to compute dynamic when | |
| 15135 // one or the other is the null literal. Remove this fix once the | |
| 15136 // corresponding analyzer bug is fixed: | |
|
Jennifer Messerly
2015/09/22 18:17:21
I wonder if it's worth moving this fix into the an
| |
| 15137 // https://code.google.com/p/dart/issues/detail?id=22854 | |
| 15138 if (type1 != null && type2 != null) { | |
| 15139 if (type1.isBottom) { | |
| 15140 return type2; | |
| 15141 } | |
| 15142 if (type2.isBottom) { | |
| 15143 return type1; | |
| 15144 } | |
| 15145 } | |
| 15100 // TODO(leafp): Implement a strong mode version of this. | 15146 // TODO(leafp): Implement a strong mode version of this. |
| 15101 return _specTypeSystem.getLeastUpperBound(typeProvider, type1, type2); | 15147 return _specTypeSystem.getLeastUpperBound(typeProvider, type1, type2); |
| 15102 } | 15148 } |
| 15103 | 15149 |
| 15104 // TODO(leafp): Document the rules in play here | 15150 // TODO(leafp): Document the rules in play here |
| 15105 @override | 15151 @override |
| 15106 bool isAssignableTo(DartType toType, DartType fromType) { | 15152 bool isAssignableTo(DartType toType, DartType fromType) { |
| 15107 // An actual subtype | 15153 // An actual subtype |
| 15108 if (isSubtypeOf(fromType, toType)) { | 15154 if (isSubtypeOf(fromType, toType)) { |
| 15109 return true; | 15155 return true; |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15955 nonFields.add(node); | 16001 nonFields.add(node); |
| 15956 return null; | 16002 return null; |
| 15957 } | 16003 } |
| 15958 | 16004 |
| 15959 @override | 16005 @override |
| 15960 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 16006 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15961 | 16007 |
| 15962 @override | 16008 @override |
| 15963 Object visitWithClause(WithClause node) => null; | 16009 Object visitWithClause(WithClause node) => null; |
| 15964 } | 16010 } |
| OLD | NEW |