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

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

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Fixes after rebase. Created 3 years, 10 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
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 ac7b6d847833a9eef77a2036176213907bb5d8ad..58e9177e091aa199f43d04501bd2fb865e2d9bf5 100644
--- a/pkg/compiler/lib/src/resolution/signatures.dart
+++ b/pkg/compiler/lib/src/resolution/signatures.dart
@@ -93,7 +93,9 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
reporter.internalError(node, 'function type parameters not supported');
}
currentDefinitions = node;
- FormalElementX element = definition.accept(this);
+ FormalElementX element = definition == null
+ ? createUnnamedParameter() // This happens in function types.
+ : definition.accept(this);
if (currentDefinitions.metadata != null) {
element.metadataInternal =
resolution.resolver.resolveMetadata(element, node);
@@ -112,7 +114,8 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
void computeParameterType(FormalElementX element,
[VariableElement fieldElement]) {
- void computeFunctionType(FunctionExpression functionExpression) {
+ // Function-type as in `foo(int bar(String x))`
+ void computeInlineFunctionType(FunctionExpression functionExpression) {
FunctionSignature functionSignature = SignatureResolver.analyze(
resolution,
scope,
@@ -134,13 +137,14 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
assert(invariant(currentDefinitions, link.tail.isEmpty));
if (link.head.asFunctionExpression() != null) {
// Inline function typed parameter, like `void m(int f(String s))`.
- computeFunctionType(link.head);
+ computeInlineFunctionType(link.head);
} else if (link.head.asSend() != null &&
link.head.asSend().selector.asFunctionExpression() != null) {
// Inline function typed initializing formal or
// parameter with default value, like `C(int this.f(String s))` or
// `void m([int f(String s) = null])`.
- computeFunctionType(link.head.asSend().selector.asFunctionExpression());
+ computeInlineFunctionType(
+ link.head.asSend().selector.asFunctionExpression());
} else {
assert(invariant(currentDefinitions,
link.head.asIdentifier() != null || link.head.asSend() != null));
@@ -197,6 +201,15 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
return parameter;
}
+ FormalElementX createUnnamedParameter() {
+ FormalElementX parameter;
+ assert(!createRealParameters);
+ parameter = new FormalElementX.unnamed(
+ ElementKind.PARAMETER, enclosingElement, currentDefinitions);
+ computeParameterType(parameter);
+ return parameter;
+ }
+
InitializingFormalElementX createFieldParameter(
Send node, Expression initializer) {
InitializingFormalElementX element;
@@ -426,7 +439,7 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
List<Element> orderedOptionalParameters =
visitor.optionalParameters.toList();
if (visitor.optionalParametersAreNamed) {
- // TODO(karlklose); replace when [visitor.optinalParameters] is a [List].
+ // TODO(karlklose); replace when [visitor.optionalParameters] is a [List].
orderedOptionalParameters.sort((Element a, Element b) {
return a.name.compareTo(b.name);
});
@@ -441,7 +454,7 @@ class SignatureResolver extends MappingVisitor<FormalElementX> {
namedParameterTypes =
namedParameterTypesBuilder.toLink().toList(growable: false);
} else {
- // TODO(karlklose); replace when [visitor.optinalParameters] is a [List].
+ // TODO(karlklose); replace when [visitor.optionalParameters] is a [List].
LinkBuilder<ResolutionDartType> optionalParameterTypesBuilder =
new LinkBuilder<ResolutionDartType>();
for (FormalElement parameter in visitor.optionalParameters) {

Powered by Google App Engine
This is Rietveld 408576698