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 analyzer.src.dart.element.type; | 5 library analyzer.src.dart.element.type; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 if (type is TypeParameterType) { | 920 if (type is TypeParameterType) { |
921 free.add(type); | 921 free.add(type); |
922 } else if (type is FunctionType) { | 922 } else if (type is FunctionType) { |
923 _freeVariablesInFunctionType(type, free); | 923 _freeVariablesInFunctionType(type, free); |
924 } else if (type is InterfaceType) { | 924 } else if (type is InterfaceType) { |
925 _freeVariablesInInterfaceType(type, free); | 925 _freeVariablesInInterfaceType(type, free); |
926 } | 926 } |
927 } | 927 } |
928 | 928 |
929 /** | 929 /** |
930 * Given a generic function type [g] and an instantiated function type [f], | |
931 * find a list of type arguments TArgs such that `g<TArgs> == f`, | |
932 * and return TArgs. | |
933 * | |
934 * This function must be called with type [f] that was instantiated from [g]. | |
935 */ | |
936 static Iterable<DartType> recoverTypeArguments( | |
Jennifer Messerly
2016/06/22 23:58:06
Moved from DDC:
https://github.com/dart-lang/dev_
| |
937 FunctionType g, FunctionType f) { | |
938 // TODO(jmesserly): perhaps a better design here would be: instead of | |
939 // recording staticInvokeType on InvocationExpression, we could record the | |
940 // instantiated type arguments, that way we wouldn't need to recover them. | |
941 // | |
942 // For now though, this is a pretty quick operation. | |
943 assert(identical(g.element, f.element)); | |
944 assert(g.typeFormals.isNotEmpty && f.typeFormals.isEmpty); | |
945 assert(g.typeFormals.length + g.typeArguments.length == | |
946 f.typeArguments.length); | |
947 | |
948 // Instantiation in Analyzer works like this: | |
949 // Given: | |
950 // {U/T} <S> T -> S | |
951 // Where {U/T} represents the typeArguments (U) and typeParameters (T) list, | |
952 // and <S> represents the typeFormals. | |
953 // | |
954 // Now instantiate([V]), and the result should be: | |
955 // {U/T, V/S} T -> S. | |
956 // | |
957 // Therefore, we can recover the typeArguments from our instantiated | |
958 // function. | |
959 return f.typeArguments.skip(g.typeArguments.length); | |
960 } | |
961 | |
962 /** | |
930 * Compares two function types [t] and [s] to see if their corresponding | 963 * Compares two function types [t] and [s] to see if their corresponding |
931 * parameter types match [parameterRelation] and their return types match | 964 * parameter types match [parameterRelation] and their return types match |
932 * [returnRelation]. | 965 * [returnRelation]. |
933 * | 966 * |
934 * Used for the various relations on function types which have the same | 967 * Used for the various relations on function types which have the same |
935 * structural rules for handling optional parameters and arity, but use their | 968 * structural rules for handling optional parameters and arity, but use their |
936 * own relation for comparing corresponding paramaters or return types. | 969 * own relation for comparing corresponding paramaters or return types. |
937 * | 970 * |
938 * If [returnRelation] is omitted, uses [parameterRelation] for both. | 971 * If [returnRelation] is omitted, uses [parameterRelation] for both. |
939 */ | 972 */ |
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2645 | 2678 |
2646 @override | 2679 @override |
2647 TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this; | 2680 TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this; |
2648 | 2681 |
2649 @override | 2682 @override |
2650 VoidTypeImpl substitute2( | 2683 VoidTypeImpl substitute2( |
2651 List<DartType> argumentTypes, List<DartType> parameterTypes, | 2684 List<DartType> argumentTypes, List<DartType> parameterTypes, |
2652 [List<FunctionTypeAliasElement> prune]) => | 2685 [List<FunctionTypeAliasElement> prune]) => |
2653 this; | 2686 this; |
2654 } | 2687 } |
OLD | NEW |