| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.kernel_function_type_alias_builder; | 5 library fasta.kernel_function_type_alias_builder; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/kernel/kernel_function_type_builder.dart'; |
| 8 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; |
| 7 import 'package:kernel/ast.dart' | 9 import 'package:kernel/ast.dart' |
| 8 show | 10 show |
| 9 DartType, | 11 DartType, |
| 10 DynamicType, | 12 DynamicType, |
| 11 FunctionType, | 13 FunctionType, |
| 12 InvalidType, | 14 InvalidType, |
| 13 TypeParameter, | 15 TypeParameter, |
| 14 Typedef; | 16 Typedef, |
| 15 | 17 VariableDeclaration; |
| 16 import 'package:kernel/type_algebra.dart' show substitute; | 18 import 'package:kernel/type_algebra.dart' show substitute; |
| 17 | 19 |
| 18 import '../fasta_codes.dart' show templateCyclicTypedef; | 20 import '../fasta_codes.dart' show templateCyclicTypedef; |
| 19 | |
| 20 import 'kernel_builder.dart' | 21 import 'kernel_builder.dart' |
| 21 show | 22 show |
| 22 FunctionTypeAliasBuilder, | 23 FunctionTypeAliasBuilder, |
| 24 KernelFormalParameterBuilder, |
| 23 KernelFunctionTypeBuilder, | 25 KernelFunctionTypeBuilder, |
| 24 KernelTypeBuilder, | 26 KernelTypeBuilder, |
| 25 KernelTypeVariableBuilder, | 27 KernelTypeVariableBuilder, |
| 26 LibraryBuilder, | 28 LibraryBuilder, |
| 27 MetadataBuilder, | 29 MetadataBuilder, |
| 28 TypeVariableBuilder, | 30 TypeVariableBuilder, |
| 29 computeDefaultTypeArguments; | 31 computeDefaultTypeArguments; |
| 30 | 32 |
| 31 class KernelFunctionTypeAliasBuilder | 33 class KernelFunctionTypeAliasBuilder |
| 32 extends FunctionTypeAliasBuilder<KernelFunctionTypeBuilder, DartType> { | 34 extends FunctionTypeAliasBuilder<KernelFunctionTypeBuilder, DartType> { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 54 DartType buildThisType(LibraryBuilder library) { | 56 DartType buildThisType(LibraryBuilder library) { |
| 55 if (thisType != null) { | 57 if (thisType != null) { |
| 56 if (const InvalidType() == thisType) { | 58 if (const InvalidType() == thisType) { |
| 57 library.addCompileTimeError( | 59 library.addCompileTimeError( |
| 58 templateCyclicTypedef.withArguments(name), charOffset, fileUri); | 60 templateCyclicTypedef.withArguments(name), charOffset, fileUri); |
| 59 return const DynamicType(); | 61 return const DynamicType(); |
| 60 } | 62 } |
| 61 return thisType; | 63 return thisType; |
| 62 } | 64 } |
| 63 thisType = const InvalidType(); | 65 thisType = const InvalidType(); |
| 66 |
| 64 DartType builtType = type?.build(library) ?? const DynamicType(); | 67 DartType builtType = type?.build(library) ?? const DynamicType(); |
| 65 if (typeVariables != null) { | 68 if (typeVariables != null) { |
| 66 for (KernelTypeVariableBuilder tv in typeVariables) { | 69 for (KernelTypeVariableBuilder tv in typeVariables) { |
| 67 tv.parameter.bound = tv?.bound?.build(library); | 70 tv.parameter.bound = tv?.bound?.build(library); |
| 68 target.typeParameters.add(tv.parameter..parent = target); | 71 target.typeParameters.add(tv.parameter..parent = target); |
| 69 } | 72 } |
| 70 } | 73 } |
| 74 |
| 75 _buildParameters(library); |
| 76 |
| 71 return thisType = builtType; | 77 return thisType = builtType; |
| 72 } | 78 } |
| 73 | 79 |
| 74 /// [arguments] have already been built. | 80 /// [arguments] have already been built. |
| 75 DartType buildTypesWithBuiltArguments( | 81 DartType buildTypesWithBuiltArguments( |
| 76 LibraryBuilder library, List<DartType> arguments) { | 82 LibraryBuilder library, List<DartType> arguments) { |
| 77 var thisType = buildThisType(library); | 83 var thisType = buildThisType(library); |
| 78 if (const DynamicType() == thisType) return thisType; | 84 if (const DynamicType() == thisType) return thisType; |
| 79 FunctionType result = thisType; | 85 FunctionType result = thisType; |
| 80 if (target.typeParameters.isEmpty && arguments == null) return result; | 86 if (target.typeParameters.isEmpty && arguments == null) return result; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 96 if (target.typeParameters.isEmpty && arguments == null) return result; | 102 if (target.typeParameters.isEmpty && arguments == null) return result; |
| 97 // Otherwise, substitute. | 103 // Otherwise, substitute. |
| 98 List<DartType> builtArguments = <DartType>[]; | 104 List<DartType> builtArguments = <DartType>[]; |
| 99 if (arguments != null) { | 105 if (arguments != null) { |
| 100 for (int i = 0; i < arguments.length; i++) { | 106 for (int i = 0; i < arguments.length; i++) { |
| 101 builtArguments.add(arguments[i].build(library)); | 107 builtArguments.add(arguments[i].build(library)); |
| 102 } | 108 } |
| 103 } | 109 } |
| 104 return buildTypesWithBuiltArguments(library, builtArguments); | 110 return buildTypesWithBuiltArguments(library, builtArguments); |
| 105 } | 111 } |
| 112 |
| 113 /// Build and set formal parameters of this typedef. |
| 114 void _buildParameters(LibraryBuilder library) { |
| 115 int requiredCount = 0; |
| 116 final positional = <VariableDeclaration>[]; |
| 117 final named = <VariableDeclaration>[]; |
| 118 if (type.formals != null) { |
| 119 for (KernelFormalParameterBuilder formal in type.formals) { |
| 120 KernelVariableDeclaration parameter = formal.build(library); |
| 121 if (formal.isPositional) { |
| 122 positional.add(parameter); |
| 123 if (formal.isRequired) requiredCount++; |
| 124 } else if (formal.isNamed) { |
| 125 named.add(parameter); |
| 126 } |
| 127 } |
| 128 target.setParameters(requiredCount, positional, named); |
| 129 } |
| 130 } |
| 106 } | 131 } |
| OLD | NEW |