| 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' | 7 import 'package:kernel/ast.dart' |
| 8 show | 8 show |
| 9 Arguments, | 9 Arguments, |
| 10 AsyncMarker, | 10 AsyncMarker, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 abstract class KernelFunctionBuilder | 75 abstract class KernelFunctionBuilder |
| 76 extends ProcedureBuilder<KernelTypeBuilder> { | 76 extends ProcedureBuilder<KernelTypeBuilder> { |
| 77 final String nativeMethodName; | 77 final String nativeMethodName; |
| 78 | 78 |
| 79 FunctionNode function; | 79 FunctionNode function; |
| 80 | 80 |
| 81 Statement actualBody; | 81 Statement actualBody; |
| 82 | 82 |
| 83 KernelFunctionBuilder( | 83 KernelFunctionBuilder( |
| 84 String documentationComment, | |
| 85 List<MetadataBuilder> metadata, | 84 List<MetadataBuilder> metadata, |
| 86 int modifiers, | 85 int modifiers, |
| 87 KernelTypeBuilder returnType, | 86 KernelTypeBuilder returnType, |
| 88 String name, | 87 String name, |
| 89 List<TypeVariableBuilder> typeVariables, | 88 List<TypeVariableBuilder> typeVariables, |
| 90 List<FormalParameterBuilder> formals, | 89 List<FormalParameterBuilder> formals, |
| 91 KernelLibraryBuilder compilationUnit, | 90 KernelLibraryBuilder compilationUnit, |
| 92 int charOffset, | 91 int charOffset, |
| 93 this.nativeMethodName) | 92 this.nativeMethodName) |
| 94 : super(documentationComment, metadata, modifiers, returnType, name, | 93 : super(metadata, modifiers, returnType, name, typeVariables, formals, |
| 95 typeVariables, formals, compilationUnit, charOffset); | 94 compilationUnit, charOffset); |
| 96 | 95 |
| 97 void set body(Statement newBody) { | 96 void set body(Statement newBody) { |
| 98 if (newBody != null) { | 97 if (newBody != null) { |
| 99 if (isAbstract) { | 98 if (isAbstract) { |
| 100 return internalProblem(messageInternalProblemBodyOnAbstractMethod, | 99 return internalProblem(messageInternalProblemBodyOnAbstractMethod, |
| 101 newBody.fileOffset, fileUri); | 100 newBody.fileOffset, fileUri); |
| 102 } | 101 } |
| 103 if (isExternal) { | 102 if (isExternal) { |
| 104 return library.addCompileTimeError( | 103 return library.addCompileTimeError( |
| 105 messageExternalMethodWithBody, newBody.fileOffset, fileUri); | 104 messageExternalMethodWithBody, newBody.fileOffset, fileUri); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 200 |
| 202 class KernelProcedureBuilder extends KernelFunctionBuilder { | 201 class KernelProcedureBuilder extends KernelFunctionBuilder { |
| 203 final KernelProcedure procedure; | 202 final KernelProcedure procedure; |
| 204 final int charOpenParenOffset; | 203 final int charOpenParenOffset; |
| 205 | 204 |
| 206 AsyncMarker actualAsyncModifier = AsyncMarker.Sync; | 205 AsyncMarker actualAsyncModifier = AsyncMarker.Sync; |
| 207 | 206 |
| 208 final ConstructorReferenceBuilder redirectionTarget; | 207 final ConstructorReferenceBuilder redirectionTarget; |
| 209 | 208 |
| 210 KernelProcedureBuilder( | 209 KernelProcedureBuilder( |
| 211 String documentationComment, | |
| 212 List<MetadataBuilder> metadata, | 210 List<MetadataBuilder> metadata, |
| 213 int modifiers, | 211 int modifiers, |
| 214 KernelTypeBuilder returnType, | 212 KernelTypeBuilder returnType, |
| 215 String name, | 213 String name, |
| 216 List<TypeVariableBuilder> typeVariables, | 214 List<TypeVariableBuilder> typeVariables, |
| 217 List<FormalParameterBuilder> formals, | 215 List<FormalParameterBuilder> formals, |
| 218 ProcedureKind kind, | 216 ProcedureKind kind, |
| 219 KernelLibraryBuilder compilationUnit, | 217 KernelLibraryBuilder compilationUnit, |
| 220 int charOffset, | 218 int charOffset, |
| 221 this.charOpenParenOffset, | 219 this.charOpenParenOffset, |
| 222 int charEndOffset, | 220 int charEndOffset, |
| 223 [String nativeMethodName, | 221 [String nativeMethodName, |
| 224 this.redirectionTarget]) | 222 this.redirectionTarget]) |
| 225 : procedure = new KernelProcedure(null, kind, null, returnType == null, | 223 : procedure = new KernelProcedure(null, kind, null, returnType == null, |
| 226 fileUri: compilationUnit?.relativeFileUri) | 224 fileUri: compilationUnit?.relativeFileUri) |
| 227 ..fileOffset = charOffset | 225 ..fileOffset = charOffset |
| 228 ..fileEndOffset = charEndOffset, | 226 ..fileEndOffset = charEndOffset, |
| 229 super( | 227 super(metadata, modifiers, returnType, name, typeVariables, formals, |
| 230 documentationComment, | 228 compilationUnit, charOffset, nativeMethodName); |
| 231 metadata, | |
| 232 modifiers, | |
| 233 returnType, | |
| 234 name, | |
| 235 typeVariables, | |
| 236 formals, | |
| 237 compilationUnit, | |
| 238 charOffset, | |
| 239 nativeMethodName); | |
| 240 | 229 |
| 241 ProcedureKind get kind => procedure.kind; | 230 ProcedureKind get kind => procedure.kind; |
| 242 | 231 |
| 243 AsyncMarker get asyncModifier => actualAsyncModifier; | 232 AsyncMarker get asyncModifier => actualAsyncModifier; |
| 244 | 233 |
| 245 Statement get body { | 234 Statement get body { |
| 246 if (actualBody == null && | 235 if (actualBody == null && |
| 247 redirectionTarget == null && | 236 redirectionTarget == null && |
| 248 !isAbstract && | 237 !isAbstract && |
| 249 !isExternal) { | 238 !isExternal) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 280 if (procedure.name == null) { | 269 if (procedure.name == null) { |
| 281 procedure.function = buildFunction(library); | 270 procedure.function = buildFunction(library); |
| 282 procedure.function.parent = procedure; | 271 procedure.function.parent = procedure; |
| 283 procedure.function.fileOffset = charOpenParenOffset; | 272 procedure.function.fileOffset = charOpenParenOffset; |
| 284 procedure.function.fileEndOffset = procedure.fileEndOffset; | 273 procedure.function.fileEndOffset = procedure.fileEndOffset; |
| 285 procedure.isAbstract = isAbstract; | 274 procedure.isAbstract = isAbstract; |
| 286 procedure.isStatic = isStatic; | 275 procedure.isStatic = isStatic; |
| 287 procedure.isExternal = isExternal; | 276 procedure.isExternal = isExternal; |
| 288 procedure.isConst = isConst; | 277 procedure.isConst = isConst; |
| 289 procedure.name = new Name(name, library.target); | 278 procedure.name = new Name(name, library.target); |
| 290 procedure.documentationComment = documentationComment; | |
| 291 } | 279 } |
| 292 if (isEligibleForTopLevelInference) { | 280 if (isEligibleForTopLevelInference) { |
| 293 library.loader.typeInferenceEngine.recordMember(procedure); | 281 library.loader.typeInferenceEngine.recordMember(procedure); |
| 294 } | 282 } |
| 295 return procedure; | 283 return procedure; |
| 296 } | 284 } |
| 297 | 285 |
| 298 Procedure get target => procedure; | 286 Procedure get target => procedure; |
| 299 | 287 |
| 300 @override | 288 @override |
| (...skipping 14 matching lines...) Expand all Loading... |
| 315 | 303 |
| 316 final int charOpenParenOffset; | 304 final int charOpenParenOffset; |
| 317 | 305 |
| 318 bool hasMovedSuperInitializer = false; | 306 bool hasMovedSuperInitializer = false; |
| 319 | 307 |
| 320 SuperInitializer superInitializer; | 308 SuperInitializer superInitializer; |
| 321 | 309 |
| 322 RedirectingInitializer redirectingInitializer; | 310 RedirectingInitializer redirectingInitializer; |
| 323 | 311 |
| 324 KernelConstructorBuilder( | 312 KernelConstructorBuilder( |
| 325 String documentationComment, | |
| 326 List<MetadataBuilder> metadata, | 313 List<MetadataBuilder> metadata, |
| 327 int modifiers, | 314 int modifiers, |
| 328 KernelTypeBuilder returnType, | 315 KernelTypeBuilder returnType, |
| 329 String name, | 316 String name, |
| 330 List<TypeVariableBuilder> typeVariables, | 317 List<TypeVariableBuilder> typeVariables, |
| 331 List<FormalParameterBuilder> formals, | 318 List<FormalParameterBuilder> formals, |
| 332 KernelLibraryBuilder compilationUnit, | 319 KernelLibraryBuilder compilationUnit, |
| 333 int charOffset, | 320 int charOffset, |
| 334 this.charOpenParenOffset, | 321 this.charOpenParenOffset, |
| 335 int charEndOffset, | 322 int charEndOffset, |
| 336 [String nativeMethodName]) | 323 [String nativeMethodName]) |
| 337 : constructor = new Constructor(null) | 324 : constructor = new Constructor(null) |
| 338 ..fileOffset = charOffset | 325 ..fileOffset = charOffset |
| 339 ..fileEndOffset = charEndOffset, | 326 ..fileEndOffset = charEndOffset, |
| 340 super( | 327 super(metadata, modifiers, returnType, name, typeVariables, formals, |
| 341 documentationComment, | 328 compilationUnit, charOffset, nativeMethodName); |
| 342 metadata, | |
| 343 modifiers, | |
| 344 returnType, | |
| 345 name, | |
| 346 typeVariables, | |
| 347 formals, | |
| 348 compilationUnit, | |
| 349 charOffset, | |
| 350 nativeMethodName); | |
| 351 | 329 |
| 352 bool get isInstanceMember => false; | 330 bool get isInstanceMember => false; |
| 353 | 331 |
| 354 bool get isConstructor => true; | 332 bool get isConstructor => true; |
| 355 | 333 |
| 356 AsyncMarker get asyncModifier => AsyncMarker.Sync; | 334 AsyncMarker get asyncModifier => AsyncMarker.Sync; |
| 357 | 335 |
| 358 ProcedureKind get kind => null; | 336 ProcedureKind get kind => null; |
| 359 | 337 |
| 360 bool get isRedirectingGenerativeConstructor { | 338 bool get isRedirectingGenerativeConstructor { |
| 361 return isRedirectingGenerativeConstructorImplementation(constructor); | 339 return isRedirectingGenerativeConstructorImplementation(constructor); |
| 362 } | 340 } |
| 363 | 341 |
| 364 Constructor build(SourceLibraryBuilder library) { | 342 Constructor build(SourceLibraryBuilder library) { |
| 365 if (constructor.name == null) { | 343 if (constructor.name == null) { |
| 366 constructor.function = buildFunction(library); | 344 constructor.function = buildFunction(library); |
| 367 constructor.function.parent = constructor; | 345 constructor.function.parent = constructor; |
| 368 constructor.function.fileOffset = charOpenParenOffset; | 346 constructor.function.fileOffset = charOpenParenOffset; |
| 369 constructor.function.fileEndOffset = constructor.fileEndOffset; | 347 constructor.function.fileEndOffset = constructor.fileEndOffset; |
| 370 constructor.isConst = isConst; | 348 constructor.isConst = isConst; |
| 371 constructor.isExternal = isExternal; | 349 constructor.isExternal = isExternal; |
| 372 constructor.name = new Name(name, library.target); | 350 constructor.name = new Name(name, library.target); |
| 373 constructor.documentationComment = documentationComment; | |
| 374 } | 351 } |
| 375 return constructor; | 352 return constructor; |
| 376 } | 353 } |
| 377 | 354 |
| 378 FunctionNode buildFunction(LibraryBuilder library) { | 355 FunctionNode buildFunction(LibraryBuilder library) { |
| 379 // TODO(ahe): Should complain if another type is explicitly set. | 356 // TODO(ahe): Should complain if another type is explicitly set. |
| 380 return super.buildFunction(library)..returnType = const VoidType(); | 357 return super.buildFunction(library)..returnType = const VoidType(); |
| 381 } | 358 } |
| 382 | 359 |
| 383 Constructor get target => constructor; | 360 Constructor get target => constructor; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 412 } |
| 436 } | 413 } |
| 437 initializers.add(initializer..parent = constructor); | 414 initializers.add(initializer..parent = constructor); |
| 438 initializers.add(superInitializer); | 415 initializers.add(superInitializer); |
| 439 return; | 416 return; |
| 440 } | 417 } |
| 441 initializers.add(initializer); | 418 initializers.add(initializer); |
| 442 initializer.parent = constructor; | 419 initializer.parent = constructor; |
| 443 } | 420 } |
| 444 } | 421 } |
| OLD | NEW |