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 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| (...skipping 14907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14918 return identical(parent.type, node); | 14918 return identical(parent.type, node); |
| 14919 } | 14919 } |
| 14920 if (parent is SimpleFormalParameter) { | 14920 if (parent is SimpleFormalParameter) { |
| 14921 return identical(parent.type, node); | 14921 return identical(parent.type, node); |
| 14922 } | 14922 } |
| 14923 return false; | 14923 return false; |
| 14924 } | 14924 } |
| 14925 } | 14925 } |
| 14926 | 14926 |
| 14927 /** | 14927 /** |
| 14928 * The interface `TypeSystem` defines the behavior of an object representing | |
| 14929 * the type system. This provides a common location to put methods that act on | |
| 14930 * types but may need access to more global data structures, and it paves the | |
| 14931 * way for a possible future where we may wish to make the type system | |
| 14932 * pluggable. | |
| 14933 */ | |
| 14934 abstract class TypeSystem { | |
| 14935 /** | |
| 14936 * Return the [TypeProvider] associated with this [TypeSystem]. | |
| 14937 */ | |
| 14938 TypeProvider get typeProvider; | |
| 14939 | |
| 14940 /** | |
| 14941 * Compute the least upper bound of two types. | |
| 14942 */ | |
| 14943 DartType getLeastUpperBound(DartType type1, DartType type2); | |
| 14944 } | |
| 14945 | |
| 14946 /** | |
| 14947 * Implementation of [TypeSystem] using the rules in the Dart specification. | |
| 14948 */ | |
| 14949 class TypeSystemImpl implements TypeSystem { | |
| 14950 @override | |
| 14951 final TypeProvider typeProvider; | |
| 14952 | |
| 14953 TypeSystemImpl(this.typeProvider); | |
| 14954 | |
| 14955 @override | |
| 14956 DartType getLeastUpperBound(DartType type1, DartType type2) { | |
| 14957 // The least upper bound relation is reflexive. | |
| 14958 if (identical(type1, type2)) { | |
| 14959 return type1; | |
| 14960 } | |
| 14961 // The least upper bound of dynamic and any type T is dynamic. | |
| 14962 if (type1.isDynamic) { | |
| 14963 return type1; | |
| 14964 } | |
| 14965 if (type2.isDynamic) { | |
| 14966 return type2; | |
| 14967 } | |
| 14968 // The least upper bound of void and any type T != dynamic is void. | |
| 14969 if (type1.isVoid) { | |
| 14970 return type1; | |
| 14971 } | |
| 14972 if (type2.isVoid) { | |
| 14973 return type2; | |
| 14974 } | |
| 14975 // The least upper bound of bottom and any type T is T. | |
| 14976 if (type1.isBottom) { | |
| 14977 return type2; | |
| 14978 } | |
| 14979 if (type2.isBottom) { | |
| 14980 return type1; | |
| 14981 } | |
| 14982 // Let U be a type variable with upper bound B. The least upper bound of U | |
| 14983 // and a type T is the least upper bound of B and T. | |
| 14984 while (type1 is TypeParameterType) { | |
| 14985 // TODO(paulberry): is this correct in the complex of F-bounded | |
| 14986 // polymorphism? | |
| 14987 DartType bound = (type1 as TypeParameterType).element.bound; | |
| 14988 if (bound == null) { | |
| 14989 bound = typeProvider.objectType; | |
| 14990 } | |
| 14991 type1 = bound; | |
| 14992 } | |
| 14993 while (type2 is TypeParameterType) { | |
| 14994 // TODO(paulberry): is this correct in the context of F-bounded | |
| 14995 // polymorphism? | |
| 14996 DartType bound = (type2 as TypeParameterType).element.bound; | |
| 14997 if (bound == null) { | |
| 14998 bound = typeProvider.objectType; | |
| 14999 } | |
| 15000 type2 = bound; | |
| 15001 } | |
| 15002 // The least upper bound of a function type and an interface type T is the | |
| 15003 // least upper bound of Function and T. | |
| 15004 if (type1 is FunctionType && type2 is InterfaceType) { | |
| 15005 type1 = typeProvider.functionType; | |
| 15006 } | |
| 15007 if (type2 is FunctionType && type1 is InterfaceType) { | |
| 15008 type2 = typeProvider.functionType; | |
| 15009 } | |
| 15010 | |
| 15011 // At this point type1 and type2 should both either be interface types or | |
| 15012 // function types. | |
| 15013 if (type1 is InterfaceType && type2 is InterfaceType) { | |
| 15014 InterfaceType result = | |
| 15015 InterfaceTypeImpl.computeLeastUpperBound(type1, type2); | |
| 15016 if (result == null) { | |
| 15017 return typeProvider.dynamicType; | |
| 15018 } | |
| 15019 return result; | |
| 15020 } else if (type1 is FunctionType && type2 is FunctionType) { | |
| 15021 FunctionType result = | |
| 15022 FunctionTypeImpl.computeLeastUpperBound(type1, type2); | |
| 15023 if (result == null) { | |
| 15024 return typeProvider.functionType; | |
| 15025 } | |
| 15026 return result; | |
| 15027 } else { | |
| 15028 // Should never happen. As a defensive measure, return the dynamic type. | |
| 15029 assert(false); | |
|
Brian Wilkerson
2015/06/16 21:35:19
We should log information about which types we hav
| |
| 15030 return typeProvider.dynamicType; | |
| 15031 } | |
| 15032 } | |
| 15033 } | |
| 15034 | |
| 15035 /** | |
| 14928 * Instances of the class [UnusedLocalElementsVerifier] traverse an element | 15036 * Instances of the class [UnusedLocalElementsVerifier] traverse an element |
| 14929 * structure looking for cases of [HintCode.UNUSED_ELEMENT], | 15037 * structure looking for cases of [HintCode.UNUSED_ELEMENT], |
| 14930 * [HintCode.UNUSED_FIELD], [HintCode.UNUSED_LOCAL_VARIABLE], etc. | 15038 * [HintCode.UNUSED_FIELD], [HintCode.UNUSED_LOCAL_VARIABLE], etc. |
| 14931 */ | 15039 */ |
| 14932 class UnusedLocalElementsVerifier extends RecursiveElementVisitor { | 15040 class UnusedLocalElementsVerifier extends RecursiveElementVisitor { |
| 14933 /** | 15041 /** |
| 14934 * The error listener to which errors will be reported. | 15042 * The error listener to which errors will be reported. |
| 14935 */ | 15043 */ |
| 14936 final AnalysisErrorListener _errorListener; | 15044 final AnalysisErrorListener _errorListener; |
| 14937 | 15045 |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15488 nonFields.add(node); | 15596 nonFields.add(node); |
| 15489 return null; | 15597 return null; |
| 15490 } | 15598 } |
| 15491 | 15599 |
| 15492 @override | 15600 @override |
| 15493 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15601 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15494 | 15602 |
| 15495 @override | 15603 @override |
| 15496 Object visitWithClause(WithClause node) => null; | 15604 Object visitWithClause(WithClause node) => null; |
| 15497 } | 15605 } |
| OLD | NEW |