| 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 FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 | 9 |
| 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; | 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } else { | 631 } else { |
| 632 return buildMethodInvocation( | 632 return buildMethodInvocation( |
| 633 toValue(receiver), callName, arguments, charOffset); | 633 toValue(receiver), callName, arguments, charOffset); |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 @override | 637 @override |
| 638 void beginCascade(Token token) { | 638 void beginCascade(Token token) { |
| 639 debugEvent("beginCascade"); | 639 debugEvent("beginCascade"); |
| 640 Expression expression = popForValue(); | 640 Expression expression = popForValue(); |
| 641 if (expression is CascadeReceiver) { | 641 if (expression is KernelCascadeExpression) { |
| 642 push(expression); | 642 push(expression); |
| 643 push(new VariableAccessor(this, token, expression.variable)); | 643 push(new VariableAccessor(this, token, expression.variable)); |
| 644 expression.extend(); | 644 expression.extend(); |
| 645 } else { | 645 } else { |
| 646 VariableDeclaration variable = | 646 VariableDeclaration variable = new KernelVariableDeclaration.forValue( |
| 647 new VariableDeclaration.forValue(expression); | 647 expression, functionNestingLevel); |
| 648 push(new CascadeReceiver(variable)); | 648 push(new KernelCascadeExpression(variable)); |
| 649 push(new VariableAccessor(this, token, variable)); | 649 push(new VariableAccessor(this, token, variable)); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 | 652 |
| 653 @override | 653 @override |
| 654 void endCascade() { | 654 void endCascade() { |
| 655 debugEvent("endCascade"); | 655 debugEvent("endCascade"); |
| 656 Expression expression = popForEffect(); | 656 Expression expression = popForEffect(); |
| 657 CascadeReceiver cascadeReceiver = pop(); | 657 KernelCascadeExpression cascadeReceiver = pop(); |
| 658 cascadeReceiver.finalize(expression); | 658 cascadeReceiver.finalize(expression); |
| 659 push(cascadeReceiver); | 659 push(cascadeReceiver); |
| 660 } | 660 } |
| 661 | 661 |
| 662 @override | 662 @override |
| 663 void handleBinaryExpression(Token token) { | 663 void handleBinaryExpression(Token token) { |
| 664 debugEvent("BinaryExpression"); | 664 debugEvent("BinaryExpression"); |
| 665 if (optional(".", token) || optional("..", token)) { | 665 if (optional(".", token) || optional("..", token)) { |
| 666 return doDotOrCascadeExpression(token); | 666 return doDotOrCascadeExpression(token); |
| 667 } | 667 } |
| (...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2746 | 2746 |
| 2747 // TODO(ahe): Shouldn't need to be an expression. | 2747 // TODO(ahe): Shouldn't need to be an expression. |
| 2748 class Label extends InvalidExpression { | 2748 class Label extends InvalidExpression { |
| 2749 String name; | 2749 String name; |
| 2750 | 2750 |
| 2751 Label(this.name); | 2751 Label(this.name); |
| 2752 | 2752 |
| 2753 String toString() => "label($name)"; | 2753 String toString() => "label($name)"; |
| 2754 } | 2754 } |
| 2755 | 2755 |
| 2756 class CascadeReceiver extends Let { | |
| 2757 Let nextCascade; | |
| 2758 | |
| 2759 CascadeReceiver(VariableDeclaration variable) | |
| 2760 : super( | |
| 2761 variable, | |
| 2762 makeLet(new VariableDeclaration.forValue(new InvalidExpression()), | |
| 2763 new VariableGet(variable))) { | |
| 2764 nextCascade = body; | |
| 2765 } | |
| 2766 | |
| 2767 void extend() { | |
| 2768 assert(nextCascade.variable.initializer is! InvalidExpression); | |
| 2769 Let newCascade = makeLet( | |
| 2770 new VariableDeclaration.forValue(new InvalidExpression()), | |
| 2771 nextCascade.body); | |
| 2772 nextCascade.body = newCascade; | |
| 2773 newCascade.parent = nextCascade; | |
| 2774 nextCascade = newCascade; | |
| 2775 } | |
| 2776 | |
| 2777 void finalize(Expression expression) { | |
| 2778 assert(nextCascade.variable.initializer is InvalidExpression); | |
| 2779 nextCascade.variable.initializer = expression; | |
| 2780 expression.parent = nextCascade.variable; | |
| 2781 } | |
| 2782 } | |
| 2783 | |
| 2784 abstract class ContextAccessor extends FastaAccessor { | 2756 abstract class ContextAccessor extends FastaAccessor { |
| 2785 final BuilderHelper helper; | 2757 final BuilderHelper helper; |
| 2786 | 2758 |
| 2787 final FastaAccessor accessor; | 2759 final FastaAccessor accessor; |
| 2788 | 2760 |
| 2789 final Token token; | 2761 final Token token; |
| 2790 | 2762 |
| 2791 ContextAccessor(this.helper, this.token, this.accessor); | 2763 ContextAccessor(this.helper, this.token, this.accessor); |
| 2792 | 2764 |
| 2793 @override | 2765 @override |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3197 if (starToken == null) { | 3169 if (starToken == null) { |
| 3198 return AsyncMarker.Async; | 3170 return AsyncMarker.Async; |
| 3199 } else { | 3171 } else { |
| 3200 assert(identical(starToken.stringValue, "*")); | 3172 assert(identical(starToken.stringValue, "*")); |
| 3201 return AsyncMarker.AsyncStar; | 3173 return AsyncMarker.AsyncStar; |
| 3202 } | 3174 } |
| 3203 } else { | 3175 } else { |
| 3204 return internalError("Unknown async modifier: $asyncToken"); | 3176 return internalError("Unknown async modifier: $asyncToken"); |
| 3205 } | 3177 } |
| 3206 } | 3178 } |
| OLD | NEW |