| 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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 var node = arguments[i]; | 570 var node = arguments[i]; |
| 571 if (node is NamedExpression) { | 571 if (node is NamedExpression) { |
| 572 firstNamedArgumentIndex = | 572 firstNamedArgumentIndex = |
| 573 i < firstNamedArgumentIndex ? i : firstNamedArgumentIndex; | 573 i < firstNamedArgumentIndex ? i : firstNamedArgumentIndex; |
| 574 } else { | 574 } else { |
| 575 arguments[i] = toValue(node); | 575 arguments[i] = toValue(node); |
| 576 if (i > firstNamedArgumentIndex) { | 576 if (i > firstNamedArgumentIndex) { |
| 577 arguments[i] = new NamedExpression( | 577 arguments[i] = new NamedExpression( |
| 578 "#$i", | 578 "#$i", |
| 579 buildCompileTimeError( | 579 buildCompileTimeError( |
| 580 "Expected named argument.", arguments[i].fileOffset)); | 580 "Expected named argument.", arguments[i].fileOffset)) |
| 581 ..fileOffset = beginToken.charOffset; |
| 581 } | 582 } |
| 582 } | 583 } |
| 583 } | 584 } |
| 584 if (firstNamedArgumentIndex < arguments.length) { | 585 if (firstNamedArgumentIndex < arguments.length) { |
| 585 List<Expression> positional = new List<Expression>.from( | 586 List<Expression> positional = new List<Expression>.from( |
| 586 arguments.getRange(0, firstNamedArgumentIndex)); | 587 arguments.getRange(0, firstNamedArgumentIndex)); |
| 587 List<NamedExpression> named = new List<NamedExpression>.from( | 588 List<NamedExpression> named = new List<NamedExpression>.from( |
| 588 arguments.getRange(firstNamedArgumentIndex, arguments.length)); | 589 arguments.getRange(firstNamedArgumentIndex, arguments.length)); |
| 589 push(new KernelArguments(positional, named: named)); | 590 push(new KernelArguments(positional, named: named) |
| 591 ..fileOffset = beginToken.charOffset); |
| 590 } else { | 592 } else { |
| 591 push(new KernelArguments(arguments)); | 593 push(new KernelArguments(arguments)..fileOffset = beginToken.charOffset); |
| 592 } | 594 } |
| 593 } | 595 } |
| 594 | 596 |
| 595 @override | 597 @override |
| 596 void handleParenthesizedExpression(BeginToken token) { | 598 void handleParenthesizedExpression(BeginToken token) { |
| 597 debugEvent("ParenthesizedExpression"); | 599 debugEvent("ParenthesizedExpression"); |
| 598 push(new ParenthesizedExpression(this, popForValue(), token.endGroup)); | 600 push(new ParenthesizedExpression(this, popForValue(), token.endGroup)); |
| 599 } | 601 } |
| 600 | 602 |
| 601 @override | 603 @override |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 VariableDeclaration variable = new VariableDeclaration.forValue(a); | 733 VariableDeclaration variable = new VariableDeclaration.forValue(a); |
| 732 push(makeLet( | 734 push(makeLet( |
| 733 variable, | 735 variable, |
| 734 new ConditionalExpression(buildIsNull(new VariableGet(variable)), b, | 736 new ConditionalExpression(buildIsNull(new VariableGet(variable)), b, |
| 735 new VariableGet(variable), const DynamicType()))); | 737 new VariableGet(variable), const DynamicType()))); |
| 736 } | 738 } |
| 737 | 739 |
| 738 /// Handle `a?.b(...)`. | 740 /// Handle `a?.b(...)`. |
| 739 void doIfNotNull(Token token) { | 741 void doIfNotNull(Token token) { |
| 740 IncompleteSend send = pop(); | 742 IncompleteSend send = pop(); |
| 741 push(send.withReceiver(pop(), isNullAware: true)); | 743 push(send.withReceiver(pop(), token.charOffset, isNullAware: true)); |
| 742 } | 744 } |
| 743 | 745 |
| 744 void doDotOrCascadeExpression(Token token) { | 746 void doDotOrCascadeExpression(Token token) { |
| 745 // TODO(ahe): Handle null-aware. | 747 // TODO(ahe): Handle null-aware. |
| 746 IncompleteSend send = pop(); | 748 IncompleteSend send = pop(); |
| 747 Object receiver = optional(".", token) ? pop() : popForValue(); | 749 Object receiver = optional(".", token) ? pop() : popForValue(); |
| 748 push(send.withReceiver(receiver)); | 750 push(send.withReceiver(receiver, token.charOffset)); |
| 749 } | 751 } |
| 750 | 752 |
| 751 @override | 753 @override |
| 752 Expression toSuperMethodInvocation(MethodInvocation node) { | 754 Expression toSuperMethodInvocation(MethodInvocation node) { |
| 753 Member target = lookupSuperMember(node.name); | 755 Member target = lookupSuperMember(node.name); |
| 754 bool isNoSuchMethod = target == null; | 756 bool isNoSuchMethod = target == null; |
| 755 if (target is Procedure) { | 757 if (target is Procedure) { |
| 756 if (!target.isAccessor) { | 758 if (!target.isAccessor) { |
| 757 if (areArgumentsCompatible(target.function, node.arguments)) { | 759 if (areArgumentsCompatible(target.function, node.arguments)) { |
| 758 // TODO(ahe): Use [DirectMethodInvocation] when possible. | |
| 759 Expression result = new KernelDirectMethodInvocation( | 760 Expression result = new KernelDirectMethodInvocation( |
| 760 new ThisExpression(), target, node.arguments); | 761 new ThisExpression()..fileOffset = node.fileOffset, |
| 762 target, |
| 763 node.arguments); |
| 764 // TODO(ahe): Use [DirectMethodInvocation] when possible, that is, |
| 765 // remove the next line: |
| 761 result = | 766 result = |
| 762 new KernelSuperMethodInvocation(node.name, node.arguments, null); | 767 new KernelSuperMethodInvocation(node.name, node.arguments, null); |
| 763 return result; | 768 return result; |
| 764 } else { | 769 } else { |
| 765 isNoSuchMethod = true; | 770 isNoSuchMethod = true; |
| 766 } | 771 } |
| 767 } | 772 } |
| 768 } | 773 } |
| 769 if (isNoSuchMethod) { | 774 if (isNoSuchMethod) { |
| 770 return throwNoSuchMethodError( | 775 return throwNoSuchMethodError( |
| 771 node.name.name, node.arguments, node.fileOffset, | 776 node.name.name, node.arguments, node.fileOffset, |
| 772 isSuper: true); | 777 isSuper: true); |
| 773 } | 778 } |
| 774 // TODO(ahe): Use [DirectPropertyGet] when possible. | 779 Expression receiver = new KernelDirectPropertyGet( |
| 775 Expression receiver = | 780 new ThisExpression()..fileOffset = node.fileOffset, target); |
| 776 new KernelDirectPropertyGet(new ThisExpression(), target); | 781 // TODO(ahe): Use [DirectPropertyGet] when possible, that is, remove the |
| 782 // next line: |
| 777 receiver = new KernelSuperPropertyGet(node.name, target); | 783 receiver = new KernelSuperPropertyGet(node.name, target); |
| 778 return buildMethodInvocation( | 784 return buildMethodInvocation( |
| 779 receiver, callName, node.arguments, node.fileOffset); | 785 receiver, callName, node.arguments, node.fileOffset); |
| 780 } | 786 } |
| 781 | 787 |
| 782 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { | 788 bool areArgumentsCompatible(FunctionNode function, Arguments arguments) { |
| 783 // TODO(ahe): Implement this. | 789 // TODO(ahe): Implement this. |
| 784 return true; | 790 return true; |
| 785 } | 791 } |
| 786 | 792 |
| (...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2094 push(new IncompleteError( | 2100 push(new IncompleteError( |
| 2095 this, token, "Expected identifier, but got 'super'.")); | 2101 this, token, "Expected identifier, but got 'super'.")); |
| 2096 } | 2102 } |
| 2097 } | 2103 } |
| 2098 | 2104 |
| 2099 @override | 2105 @override |
| 2100 void handleNamedArgument(Token colon) { | 2106 void handleNamedArgument(Token colon) { |
| 2101 debugEvent("NamedArgument"); | 2107 debugEvent("NamedArgument"); |
| 2102 Expression value = popForValue(); | 2108 Expression value = popForValue(); |
| 2103 Identifier identifier = pop(); | 2109 Identifier identifier = pop(); |
| 2104 push(new NamedExpression(identifier.name, value)); | 2110 push(new NamedExpression(identifier.name, value) |
| 2111 ..fileOffset = offsetForToken(identifier.token)); |
| 2105 } | 2112 } |
| 2106 | 2113 |
| 2107 @override | 2114 @override |
| 2108 void endFunctionName(Token beginToken, Token token) { | 2115 void endFunctionName(Token beginToken, Token token) { |
| 2109 debugEvent("FunctionName"); | 2116 debugEvent("FunctionName"); |
| 2110 Identifier name = pop(); | 2117 Identifier name = pop(); |
| 2111 VariableDeclaration variable = new KernelVariableDeclaration( | 2118 VariableDeclaration variable = new KernelVariableDeclaration( |
| 2112 name.name, functionNestingLevel, | 2119 name.name, functionNestingLevel, |
| 2113 isFinal: true, isLocalFunction: true) | 2120 isFinal: true, isLocalFunction: true) |
| 2114 ..fileOffset = offsetForToken(name.token); | 2121 ..fileOffset = offsetForToken(name.token); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3266 if (starToken == null) { | 3273 if (starToken == null) { |
| 3267 return AsyncMarker.Async; | 3274 return AsyncMarker.Async; |
| 3268 } else { | 3275 } else { |
| 3269 assert(identical(starToken.stringValue, "*")); | 3276 assert(identical(starToken.stringValue, "*")); |
| 3270 return AsyncMarker.AsyncStar; | 3277 return AsyncMarker.AsyncStar; |
| 3271 } | 3278 } |
| 3272 } else { | 3279 } else { |
| 3273 return internalError("Unknown async modifier: $asyncToken"); | 3280 return internalError("Unknown async modifier: $asyncToken"); |
| 3274 } | 3281 } |
| 3275 } | 3282 } |
| OLD | NEW |