| 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_procedure_builder; | 5 library fasta.kernel_procedure_builder; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' show | 7 import 'package:kernel/ast.dart' show |
| 8 Arguments, | 8 Arguments, |
| 9 AsyncMarker, | 9 AsyncMarker, |
| 10 Constructor, | 10 Constructor, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 VoidType, | 30 VoidType, |
| 31 setParents; | 31 setParents; |
| 32 | 32 |
| 33 import 'package:kernel/type_algebra.dart' show | 33 import 'package:kernel/type_algebra.dart' show |
| 34 containsTypeVariable, | 34 containsTypeVariable, |
| 35 substitute; | 35 substitute; |
| 36 | 36 |
| 37 import '../errors.dart' show | 37 import '../errors.dart' show |
| 38 internalError; | 38 internalError; |
| 39 | 39 |
| 40 import '../modifier.dart' show | |
| 41 abstractMask; | |
| 42 | 40 |
| 43 import '../util/relativize.dart' show | 41 import '../util/relativize.dart' show |
| 44 relativizeUri; | 42 relativizeUri; |
| 45 | 43 |
| 46 import 'kernel_builder.dart' show | 44 import 'kernel_builder.dart' show |
| 47 ClassBuilder, | 45 ClassBuilder, |
| 48 ConstructorReferenceBuilder, | 46 ConstructorReferenceBuilder, |
| 49 FormalParameterBuilder, | 47 FormalParameterBuilder, |
| 50 KernelFormalParameterBuilder, | 48 KernelFormalParameterBuilder, |
| 51 KernelLibraryBuilder, | 49 KernelLibraryBuilder, |
| 52 KernelTypeBuilder, | 50 KernelTypeBuilder, |
| 53 KernelTypeVariableBuilder, | 51 KernelTypeVariableBuilder, |
| 54 MetadataBuilder, | 52 MetadataBuilder, |
| 55 ProcedureBuilder, | 53 ProcedureBuilder, |
| 56 TypeBuilder, | |
| 57 TypeVariableBuilder, | 54 TypeVariableBuilder, |
| 58 memberError; | 55 memberError; |
| 59 | 56 |
| 60 abstract class KernelFunctionBuilder | 57 abstract class KernelFunctionBuilder |
| 61 extends ProcedureBuilder<KernelTypeBuilder> { | 58 extends ProcedureBuilder<KernelTypeBuilder> { |
| 62 FunctionNode function; | 59 FunctionNode function; |
| 63 | 60 |
| 64 Statement actualBody; | 61 Statement actualBody; |
| 65 | 62 |
| 66 KernelFunctionBuilder( | 63 KernelFunctionBuilder( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 procedure.function.parent = procedure; | 190 procedure.function.parent = procedure; |
| 194 procedure.isAbstract = isAbstract; | 191 procedure.isAbstract = isAbstract; |
| 195 procedure.isStatic = isStatic; | 192 procedure.isStatic = isStatic; |
| 196 procedure.isExternal = isExternal; | 193 procedure.isExternal = isExternal; |
| 197 procedure.isConst = isConst; | 194 procedure.isConst = isConst; |
| 198 procedure.name = new Name(name, library); | 195 procedure.name = new Name(name, library); |
| 199 } | 196 } |
| 200 return procedure; | 197 return procedure; |
| 201 } | 198 } |
| 202 | 199 |
| 203 KernelFunctionBuilder toConstructor(String name, | |
| 204 List<TypeVariableBuilder> classTypeVariables) { | |
| 205 assert(procedure.name == null); | |
| 206 assert(actualBody == null); | |
| 207 if (isFactory) { | |
| 208 if (this.typeVariables != null) { | |
| 209 return memberError(target, "Factories can't be generic."); | |
| 210 } | |
| 211 List<KernelTypeVariableBuilder> typeVariables; | |
| 212 KernelTypeBuilder returnType = this.returnType; | |
| 213 List<FormalParameterBuilder> formals; | |
| 214 if (classTypeVariables != null) { | |
| 215 typeVariables = <KernelTypeVariableBuilder>[]; | |
| 216 for (KernelTypeVariableBuilder variable in classTypeVariables) { | |
| 217 typeVariables.add(new KernelTypeVariableBuilder( | |
| 218 variable.name, null, -1)); | |
| 219 } | |
| 220 Map<TypeVariableBuilder, TypeBuilder> substitution = | |
| 221 <TypeVariableBuilder, TypeBuilder>{}; | |
| 222 int i = 0; | |
| 223 for (KernelTypeVariableBuilder variable in classTypeVariables) { | |
| 224 substitution[variable] = typeVariables[i++].asTypeBuilder(); | |
| 225 } | |
| 226 i = 0; | |
| 227 for (KernelTypeVariableBuilder variable in classTypeVariables) { | |
| 228 typeVariables[i++].bound = variable?.bound?.subst(substitution); | |
| 229 } | |
| 230 returnType = returnType?.subst(substitution); | |
| 231 i = 0; | |
| 232 if (this.formals != null) { | |
| 233 for (KernelFormalParameterBuilder formal in this.formals) { | |
| 234 KernelTypeBuilder type = formal.type?.subst(substitution); | |
| 235 if (type != formal.type) { | |
| 236 formals ??= this.formals.toList(); | |
| 237 formals[i] = new KernelFormalParameterBuilder(formal.metadata, | |
| 238 formal.modifiers, type, formal.name, formal.hasThis, null, | |
| 239 -1); | |
| 240 } | |
| 241 i++; | |
| 242 } | |
| 243 } | |
| 244 } | |
| 245 formals ??= this.formals; | |
| 246 KernelProcedureBuilder factory = new KernelProcedureBuilder( | |
| 247 metadata, modifiers, returnType, name, typeVariables, formals, | |
| 248 actualAsyncModifier, kind, null, -1, redirectionTarget) | |
| 249 ..parent = parent; | |
| 250 factory.procedure.fileUri = procedure.fileUri; | |
| 251 return factory; | |
| 252 } else { | |
| 253 return new KernelConstructorBuilder(metadata, modifiers & ~abstractMask, | |
| 254 returnType, name, typeVariables, formals, null, -1) | |
| 255 ..parent = parent; | |
| 256 } | |
| 257 } | |
| 258 | |
| 259 Procedure get target => procedure; | 200 Procedure get target => procedure; |
| 260 } | 201 } |
| 261 | 202 |
| 262 // TODO(ahe): Move this to own file? | 203 // TODO(ahe): Move this to own file? |
| 263 class KernelConstructorBuilder extends KernelFunctionBuilder { | 204 class KernelConstructorBuilder extends KernelFunctionBuilder { |
| 264 final Constructor constructor = new Constructor(null); | 205 final Constructor constructor = new Constructor(null); |
| 265 | 206 |
| 266 bool hasMovedSuperInitializer = false; | 207 bool hasMovedSuperInitializer = false; |
| 267 | 208 |
| 268 SuperInitializer superInitializer; | 209 SuperInitializer superInitializer; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 300 } |
| 360 } | 301 } |
| 361 initializers.add(initializer..parent = constructor); | 302 initializers.add(initializer..parent = constructor); |
| 362 initializers.add(superInitializer); | 303 initializers.add(superInitializer); |
| 363 return; | 304 return; |
| 364 } | 305 } |
| 365 initializers.add(initializer); | 306 initializers.add(initializer); |
| 366 initializer.parent = constructor; | 307 initializer.parent = constructor; |
| 367 } | 308 } |
| 368 } | 309 } |
| OLD | NEW |