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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart

Issue 2990783002: Serialize typedef parameters (including function typed ones) to Kernel and use it to resynthesize t… (Closed)
Patch Set: Test for named parameters. Created 3 years, 5 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/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart
index f8c928d71fca40d3834266ce3e85311abbe1aad9..419d9c67ed0a4a1dd8c135a26d6005dda7cd75c4 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_function_type_alias_builder.dart
@@ -4,6 +4,8 @@
library fasta.kernel_function_type_alias_builder;
+import 'package:front_end/src/fasta/kernel/kernel_function_type_builder.dart';
+import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart';
import 'package:kernel/ast.dart'
show
DartType,
@@ -11,15 +13,15 @@ import 'package:kernel/ast.dart'
FunctionType,
InvalidType,
TypeParameter,
- Typedef;
-
+ Typedef,
+ VariableDeclaration;
import 'package:kernel/type_algebra.dart' show substitute;
import '../fasta_codes.dart' show templateCyclicTypedef;
-
import 'kernel_builder.dart'
show
FunctionTypeAliasBuilder,
+ KernelFormalParameterBuilder,
KernelFunctionTypeBuilder,
KernelTypeBuilder,
KernelTypeVariableBuilder,
@@ -61,6 +63,7 @@ class KernelFunctionTypeAliasBuilder
return thisType;
}
thisType = const InvalidType();
+
DartType builtType = type?.build(library) ?? const DynamicType();
if (typeVariables != null) {
for (KernelTypeVariableBuilder tv in typeVariables) {
@@ -68,6 +71,9 @@ class KernelFunctionTypeAliasBuilder
target.typeParameters.add(tv.parameter..parent = target);
}
}
+
+ _buildParameters(library);
+
return thisType = builtType;
}
@@ -103,4 +109,23 @@ class KernelFunctionTypeAliasBuilder
}
return buildTypesWithBuiltArguments(library, builtArguments);
}
+
+ /// Build and set formal parameters of this typedef.
+ void _buildParameters(LibraryBuilder library) {
+ int requiredCount = 0;
+ final positional = <VariableDeclaration>[];
+ final named = <VariableDeclaration>[];
+ if (type.formals != null) {
+ for (KernelFormalParameterBuilder formal in type.formals) {
+ KernelVariableDeclaration parameter = formal.build(library);
+ if (formal.isPositional) {
+ positional.add(parameter);
+ if (formal.isRequired) requiredCount++;
+ } else if (formal.isNamed) {
+ named.add(parameter);
+ }
+ }
+ target.setParameters(requiredCount, positional, named);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698