Chromium Code Reviews| 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..489e4525585936fcd32b5ed69b4fd11742722234 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) { |
|
Johnni Winther
2016/04/29 07:21:06
Use dartfmt on the code (i.e. this seem like a bad
eernst
2016/04/29 13:24:50
Done.
|
| + 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)'; |
| +} |