Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Unified Diff: pkg/compiler/lib/src/resolution/signatures.dart

Issue 1915123008: Implements support for ignoring method type arguments in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased again Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/resolution/scope.dart ('k') | pkg/compiler/lib/src/resolution/type_resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/resolution/signatures.dart
diff --git a/pkg/compiler/lib/src/resolution/signatures.dart b/pkg/compiler/lib/src/resolution/signatures.dart
index 36ea970e008838fe9d2237f07eee05856c08998b..04db4ebf27859e31ca1112242ba6f680f7a07c96 100644
--- a/pkg/compiler/lib/src/resolution/signatures.dart
+++ b/pkg/compiler/lib/src/resolution/signatures.dart
@@ -15,14 +15,15 @@ import '../elements/modelx.dart'
FormalElementX,
FunctionSignatureX,
InitializingFormalElementX,
- LocalParameterElementX;
+ LocalParameterElementX,
+ TypeVariableElementX;
import '../tree/tree.dart';
import '../universe/use.dart' show TypeUse;
import '../util/util.dart' show Link, LinkBuilder;
import 'members.dart' show ResolverVisitor;
import 'registry.dart' show ResolutionRegistry;
import 'resolution_common.dart' show MappingVisitor;
-import 'scope.dart' show Scope;
+import 'scope.dart' show Scope, TypeVariablesScope;
/**
* [SignatureResolver] resolves function signatures.
@@ -40,12 +41,13 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
VariableDefinitions currentDefinitions;
SignatureResolver(Compiler compiler, FunctionTypedElement enclosingElement,
+ Scope scope,
ResolutionRegistry registry,
{this.defaultValuesError, this.createRealParameters})
- : this.enclosingElement = enclosingElement,
- this.scope = enclosingElement.buildScope(),
- this.resolver =
- new ResolverVisitor(compiler, enclosingElement, registry),
+ : this.scope = scope,
+ this.enclosingElement = enclosingElement,
+ this.resolver = new ResolverVisitor(
+ compiler, enclosingElement, registry, scope: scope),
super(compiler, registry);
bool get defaultValuesAllowed => defaultValuesError == null;
@@ -110,6 +112,8 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
void computeFunctionType(FunctionExpression functionExpression) {
FunctionSignature functionSignature = SignatureResolver.analyze(
compiler,
+ scope,
+ functionExpression.typeVariables,
functionExpression.parameters,
functionExpression.returnType,
element,
@@ -287,6 +291,8 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
*/
static FunctionSignature analyze(
Compiler compiler,
+ Scope scope,
+ NodeList typeVariables,
NodeList formalParameters,
Node returnNode,
FunctionTypedElement element,
@@ -296,8 +302,32 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
bool isFunctionExpression: false}) {
DiagnosticReporter reporter = compiler.reporter;
+ List<DartType> createTypeVariables(NodeList typeVariableNodes) {
+ if (typeVariableNodes == null) return const <DartType>[];
+
+ // Create the types and elements corresponding to [typeVariableNodes].
+ Link<Node> nodes = typeVariableNodes.nodes;
+ List<DartType> arguments =
+ new List.generate(nodes.slowLength(), (int index) {
+ TypeVariable node = nodes.head;
+ String variableName = node.name.source;
+ nodes = nodes.tail;
+ TypeVariableElementX variableElement =
+ new TypeVariableElementX(variableName, element, index, node);
+ // TODO(eernst): When type variables are implemented fully we will need
+ // to resolve the actual bounds; currently we just claim [dynamic].
+ variableElement.boundCache = const DynamicType();
+ TypeVariableType variableType = new TypeVariableType(variableElement);
+ variableElement.typeCache = variableType;
+ return variableType;
+ }, growable: false);
+ return arguments;
+ }
+
+ List<DartType> typeVariableTypes = createTypeVariables(typeVariables);
+ scope = new FunctionSignatureBuildingScope(scope, typeVariableTypes);
SignatureResolver visitor = new SignatureResolver(
- compiler, element, registry,
+ compiler, element, scope, registry,
defaultValuesError: defaultValuesError,
createRealParameters: createRealParameters);
List<Element> parameters = const <Element>[];
@@ -411,6 +441,7 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
namedParameters,
namedParameterTypes);
return new FunctionSignatureX(
+ typeVariables: typeVariableTypes,
requiredParameters: parameters,
optionalParameters: visitor.optionalParameters,
requiredParameterCount: requiredParameterCount,
@@ -437,3 +468,15 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
return result;
}
}
+
+/// Used during `SignatureResolver.analyze` to provide access to the type
+/// variables of the function signature itself when its signature is analyzed.
+class FunctionSignatureBuildingScope extends TypeVariablesScope {
+ @override
+ final List<DartType> typeVariables;
+
+ FunctionSignatureBuildingScope(Scope parent, this.typeVariables)
+ : super(parent);
+
+ String toString() => 'FunctionSignatureBuildingScope($typeVariables)';
+}
« no previous file with comments | « pkg/compiler/lib/src/resolution/scope.dart ('k') | pkg/compiler/lib/src/resolution/type_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698