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.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show | 8 show |
9 FastaMessage, | 9 FastaMessage, |
10 codeConstFieldWithoutInitializer, | 10 codeConstFieldWithoutInitializer, |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 } | 439 } |
440 field.initializer = initializer; | 440 field.initializer = initializer; |
441 _typeInferrer.inferFieldInitializer( | 441 _typeInferrer.inferFieldInitializer( |
442 field.hasImplicitType ? null : field.builtType, initializer); | 442 field.hasImplicitType ? null : field.builtType, initializer); |
443 } | 443 } |
444 } | 444 } |
445 pop(); // Type. | 445 pop(); // Type. |
446 pop(); // Modifiers. | 446 pop(); // Modifiers. |
447 List annotations = pop(); | 447 List annotations = pop(); |
448 if (annotations != null) { | 448 if (annotations != null) { |
449 _typeInferrer.inferMetadata(annotations); | |
ahe
2017/06/28 07:39:49
Can you move all these calls to endMetadataStar? A
Paul Berry
2017/06/28 12:15:59
I could do that now, but it would not work in the
| |
449 Field field = fields.first.target; | 450 Field field = fields.first.target; |
450 // The first (and often only field) will not get a clone. | 451 // The first (and often only field) will not get a clone. |
451 annotations.forEach(field.addAnnotation); | 452 annotations.forEach(field.addAnnotation); |
452 for (int i = 1; i < fields.length; i++) { | 453 for (int i = 1; i < fields.length; i++) { |
453 // We have to clone the annotations on the remaining fields. | 454 // We have to clone the annotations on the remaining fields. |
454 field = fields[i].target; | 455 field = fields[i].target; |
455 cloner ??= new CloneVisitor(); | 456 cloner ??= new CloneVisitor(); |
456 for (Expression annotation in annotations) { | 457 for (Expression annotation in annotations) { |
457 field.addAnnotation(cloner.clone(annotation)); | 458 field.addAnnotation(cloner.clone(annotation)); |
458 } | 459 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 @override | 583 @override |
583 void finishFunction(List annotations, FormalParameters formals, | 584 void finishFunction(List annotations, FormalParameters formals, |
584 AsyncMarker asyncModifier, Statement body) { | 585 AsyncMarker asyncModifier, Statement body) { |
585 debugEvent("finishFunction"); | 586 debugEvent("finishFunction"); |
586 typePromoter.finished(); | 587 typePromoter.finished(); |
587 _typeInferrer.inferFunctionBody( | 588 _typeInferrer.inferFunctionBody( |
588 _computeReturnTypeContext(member), asyncModifier, body); | 589 _computeReturnTypeContext(member), asyncModifier, body); |
589 KernelFunctionBuilder builder = member; | 590 KernelFunctionBuilder builder = member; |
590 builder.body = body; | 591 builder.body = body; |
591 Member target = builder.target; | 592 Member target = builder.target; |
593 _typeInferrer.inferMetadata(annotations); | |
592 for (Expression annotation in annotations ?? const []) { | 594 for (Expression annotation in annotations ?? const []) { |
593 target.addAnnotation(annotation); | 595 target.addAnnotation(annotation); |
594 } | 596 } |
595 if (formals?.optional != null) { | 597 if (formals?.optional != null) { |
596 Iterator<FormalParameterBuilder> formalBuilders = | 598 Iterator<FormalParameterBuilder> formalBuilders = |
597 builder.formals.skip(formals.required.length).iterator; | 599 builder.formals.skip(formals.required.length).iterator; |
598 for (VariableDeclaration parameter in formals.optional.formals) { | 600 for (VariableDeclaration parameter in formals.optional.formals) { |
599 bool hasMore = formalBuilders.moveNext(); | 601 bool hasMore = formalBuilders.moveNext(); |
600 assert(hasMore); | 602 assert(hasMore); |
601 VariableDeclaration realParameter = formalBuilders.current.target; | 603 VariableDeclaration realParameter = formalBuilders.current.target; |
602 Expression initializer = | 604 Expression initializer = |
603 parameter.initializer ?? new KernelNullLiteral(); | 605 parameter.initializer ?? new KernelNullLiteral(); |
604 _typeInferrer.inferParameterInitializer( | 606 _typeInferrer.inferParameterInitializer( |
605 initializer, realParameter.type); | 607 initializer, realParameter.type); |
606 realParameter.initializer = initializer..parent = realParameter; | 608 realParameter.initializer = initializer..parent = realParameter; |
607 } | 609 } |
608 } | 610 } |
609 if (builder is KernelConstructorBuilder) { | 611 if (builder is KernelConstructorBuilder) { |
610 finishConstructor(builder, asyncModifier); | 612 finishConstructor(builder, asyncModifier); |
611 } else if (builder is KernelProcedureBuilder) { | 613 } else if (builder is KernelProcedureBuilder) { |
612 builder.asyncModifier = asyncModifier; | 614 builder.asyncModifier = asyncModifier; |
613 } else { | 615 } else { |
614 internalError("Unhandled: ${builder.runtimeType}"); | 616 internalError("Unhandled: ${builder.runtimeType}"); |
615 } | 617 } |
616 } | 618 } |
617 | 619 |
620 @override | |
621 List<Expression> finishMetadata() { | |
622 List<Expression> expressions = pop(); | |
623 _typeInferrer.inferMetadata(expressions); | |
624 return expressions; | |
625 } | |
626 | |
618 void finishConstructor( | 627 void finishConstructor( |
619 KernelConstructorBuilder builder, AsyncMarker asyncModifier) { | 628 KernelConstructorBuilder builder, AsyncMarker asyncModifier) { |
620 /// Quotes below are from [Dart Programming Language Specification, 4th | 629 /// Quotes below are from [Dart Programming Language Specification, 4th |
621 /// Edition]( | 630 /// Edition]( |
622 /// https://ecma-international.org/publications/files/ECMA-ST/ECMA-408.pdf). | 631 /// https://ecma-international.org/publications/files/ECMA-ST/ECMA-408.pdf). |
623 assert(builder == member); | 632 assert(builder == member); |
624 Constructor constructor = builder.constructor; | 633 Constructor constructor = builder.constructor; |
625 if (asyncModifier != AsyncMarker.Sync) { | 634 if (asyncModifier != AsyncMarker.Sync) { |
626 // TODO(ahe): Change this to a null check. | 635 // TODO(ahe): Change this to a null check. |
627 int offset = builder.body?.fileOffset ?? builder.charOffset; | 636 int offset = builder.body?.fileOffset ?? builder.charOffset; |
(...skipping 3067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3695 if (starToken == null) { | 3704 if (starToken == null) { |
3696 return AsyncMarker.Async; | 3705 return AsyncMarker.Async; |
3697 } else { | 3706 } else { |
3698 assert(identical(starToken.stringValue, "*")); | 3707 assert(identical(starToken.stringValue, "*")); |
3699 return AsyncMarker.AsyncStar; | 3708 return AsyncMarker.AsyncStar; |
3700 } | 3709 } |
3701 } else { | 3710 } else { |
3702 return internalError("Unknown async modifier: $asyncToken"); | 3711 return internalError("Unknown async modifier: $asyncToken"); |
3703 } | 3712 } |
3704 } | 3713 } |
OLD | NEW |