| 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 '../parser/parser.dart' show FormalParameterType, optional; | 7 import '../parser/parser.dart' show FormalParameterType, optional; |
| 8 | 8 |
| 9 import '../parser/error_kind.dart' show ErrorKind; | 9 import '../parser/error_kind.dart' show ErrorKind; |
| 10 | 10 |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 481 } |
| 482 } | 482 } |
| 483 | 483 |
| 484 @override | 484 @override |
| 485 void handleParenthesizedExpression(BeginGroupToken token) { | 485 void handleParenthesizedExpression(BeginGroupToken token) { |
| 486 debugEvent("ParenthesizedExpression"); | 486 debugEvent("ParenthesizedExpression"); |
| 487 push(popForValue()); | 487 push(popForValue()); |
| 488 } | 488 } |
| 489 | 489 |
| 490 @override | 490 @override |
| 491 void endSend(Token token) { | 491 void endSend(Token beginToken, Token endToken) { |
| 492 debugEvent("Send"); | 492 debugEvent("Send"); |
| 493 Arguments arguments = pop(); | 493 Arguments arguments = pop(); |
| 494 List<DartType> typeArguments = pop(); | 494 List<DartType> typeArguments = pop(); |
| 495 Object receiver = pop(); | 495 Object receiver = pop(); |
| 496 if (arguments != null && typeArguments != null) { | 496 if (arguments != null && typeArguments != null) { |
| 497 arguments.types.addAll(typeArguments); | 497 arguments.types.addAll(typeArguments); |
| 498 } else { | 498 } else { |
| 499 assert(typeArguments == null); | 499 assert(typeArguments == null); |
| 500 } | 500 } |
| 501 if (receiver is Identifier) { | 501 if (receiver is Identifier) { |
| 502 Name name = new Name(receiver.name, library.library); | 502 Name name = new Name(receiver.name, library.library); |
| 503 if (arguments == null) { | 503 if (arguments == null) { |
| 504 push(new IncompletePropertyAccessor(this, token.charOffset, name)); | 504 push(new IncompletePropertyAccessor(this, beginToken.charOffset, name)); |
| 505 } else { | 505 } else { |
| 506 push(new SendAccessor(this, token.charOffset, name, arguments)); | 506 push(new SendAccessor(this, endToken.charOffset, name, arguments)); |
| 507 } | 507 } |
| 508 } else if (arguments == null) { | 508 } else if (arguments == null) { |
| 509 push(receiver); | 509 push(receiver); |
| 510 } else { | 510 } else { |
| 511 push(finishSend(receiver, arguments, token.charOffset)); | 511 push(finishSend(receiver, arguments, beginToken.charOffset)); |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 | 514 |
| 515 @override | 515 @override |
| 516 finishSend(Object receiver, Arguments arguments, int charOffset) { | 516 finishSend(Object receiver, Arguments arguments, int charOffset) { |
| 517 if (receiver is BuilderAccessor) { | 517 if (receiver is BuilderAccessor) { |
| 518 return receiver.doInvocation(charOffset, arguments); | 518 return receiver.doInvocation(charOffset, arguments); |
| 519 } else if (receiver is UnresolvedIdentifier) { | 519 } else if (receiver is UnresolvedIdentifier) { |
| 520 return throwNoSuchMethodError( | 520 return throwNoSuchMethodError( |
| 521 receiver.name.name, arguments, receiver.fileOffset); | 521 receiver.name.name, arguments, receiver.fileOffset); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 | 852 |
| 853 @override | 853 @override |
| 854 void endReturnStatement( | 854 void endReturnStatement( |
| 855 bool hasExpression, Token beginToken, Token endToken) { | 855 bool hasExpression, Token beginToken, Token endToken) { |
| 856 debugEvent("ReturnStatement"); | 856 debugEvent("ReturnStatement"); |
| 857 Expression expression = hasExpression ? popForValue() : null; | 857 Expression expression = hasExpression ? popForValue() : null; |
| 858 if (expression != null && inConstructor) { | 858 if (expression != null && inConstructor) { |
| 859 push(buildCompileTimeErrorStatement( | 859 push(buildCompileTimeErrorStatement( |
| 860 "Can't return from a constructor.", beginToken.charOffset)); | 860 "Can't return from a constructor.", beginToken.charOffset)); |
| 861 } else { | 861 } else { |
| 862 push(new ReturnStatement(expression)); | 862 push(new ReturnStatement(expression)..fileOffset = beginToken.charOffset); |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 | 865 |
| 866 @override | 866 @override |
| 867 void endIfStatement(Token ifToken, Token elseToken) { | 867 void endIfStatement(Token ifToken, Token elseToken) { |
| 868 Statement elsePart = popStatementIfNotNull(elseToken); | 868 Statement elsePart = popStatementIfNotNull(elseToken); |
| 869 Statement thenPart = popStatement(); | 869 Statement thenPart = popStatement(); |
| 870 Expression condition = popForValue(); | 870 Expression condition = popForValue(); |
| 871 push(new IfStatement(condition, thenPart, elsePart)); | 871 push(new IfStatement(condition, thenPart, elsePart)); |
| 872 } | 872 } |
| 873 | 873 |
| 874 @override | 874 @override |
| 875 void endVariableInitializer(Token assignmentOperator) { | 875 void endVariableInitializer(Token assignmentOperator) { |
| 876 debugEvent("VariableInitializer"); | 876 debugEvent("VariableInitializer"); |
| 877 assert(assignmentOperator.stringValue == "="); | 877 assert(assignmentOperator.stringValue == "="); |
| 878 Expression initializer = popForValue(); | 878 Expression initializer = popForValue(); |
| 879 Identifier identifier = pop(); | 879 Identifier identifier = pop(); |
| 880 push(new VariableDeclaration(identifier.name, initializer: initializer)); | 880 push(new VariableDeclaration(identifier.name, initializer: initializer) |
| 881 ..fileEqualsOffset = assignmentOperator.charOffset); |
| 881 } | 882 } |
| 882 | 883 |
| 883 @override | 884 @override |
| 884 void handleNoVariableInitializer(Token token) { | 885 void handleNoVariableInitializer(Token token) { |
| 885 debugEvent("NoVariableInitializer"); | 886 debugEvent("NoVariableInitializer"); |
| 886 } | 887 } |
| 887 | 888 |
| 888 @override | 889 @override |
| 889 void endFieldInitializer(Token assignmentOperator) { | 890 void endFieldInitializer(Token assignmentOperator) { |
| 890 debugEvent("FieldInitializer"); | 891 debugEvent("FieldInitializer"); |
| 891 assert(assignmentOperator.stringValue == "="); | 892 assert(assignmentOperator.stringValue == "="); |
| 892 push(popForValue()); | 893 push(popForValue()); |
| 893 } | 894 } |
| 894 | 895 |
| 895 @override | 896 @override |
| 896 void handleNoFieldInitializer(Token token) { | 897 void handleNoFieldInitializer(Token token) { |
| 897 debugEvent("NoFieldInitializer"); | 898 debugEvent("NoFieldInitializer"); |
| 898 push(NullValue.FieldInitializer); | 899 push(NullValue.FieldInitializer); |
| 899 } | 900 } |
| 900 | 901 |
| 901 @override | 902 @override |
| 902 void endInitializedIdentifier() { | 903 void endInitializedIdentifier(Token nameToken) { |
| 903 // TODO(ahe): Use [InitializedIdentifier] here? | 904 // TODO(ahe): Use [InitializedIdentifier] here? |
| 904 debugEvent("InitializedIdentifier"); | 905 debugEvent("InitializedIdentifier"); |
| 905 TreeNode node = pop(); | 906 TreeNode node = pop(); |
| 906 VariableDeclaration variable; | 907 VariableDeclaration variable; |
| 907 if (node is VariableDeclaration) { | 908 if (node is VariableDeclaration) { |
| 908 variable = node; | 909 variable = node; |
| 909 } else if (node is Identifier) { | 910 } else if (node is Identifier) { |
| 910 variable = new VariableDeclaration(node.name); | 911 variable = new VariableDeclaration(node.name); |
| 911 } else { | 912 } else { |
| 912 internalError("unhandled identifier: ${node.runtimeType}"); | 913 internalError("unhandled identifier: ${node.runtimeType}"); |
| 913 } | 914 } |
| 915 variable.fileOffset = nameToken.charOffset; |
| 914 push(variable); | 916 push(variable); |
| 915 scope[variable.name] = new KernelVariableBuilder( | 917 scope[variable.name] = new KernelVariableBuilder( |
| 916 variable, member ?? classBuilder ?? library, uri); | 918 variable, member ?? classBuilder ?? library, uri); |
| 917 } | 919 } |
| 918 | 920 |
| 919 @override | 921 @override |
| 920 void endVariablesDeclaration(int count, Token endToken) { | 922 void endVariablesDeclaration(int count, Token endToken) { |
| 921 debugEvent("VariablesDeclaration"); | 923 debugEvent("VariablesDeclaration"); |
| 922 List<VariableDeclaration> variables = popList(count); | 924 List<VariableDeclaration> variables = popList(count); |
| 923 DartType type = pop(); | 925 DartType type = pop(); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 void handleVoidKeyword(Token token) { | 1232 void handleVoidKeyword(Token token) { |
| 1231 debugEvent("VoidKeyword"); | 1233 debugEvent("VoidKeyword"); |
| 1232 push(const VoidType()); | 1234 push(const VoidType()); |
| 1233 } | 1235 } |
| 1234 | 1236 |
| 1235 @override | 1237 @override |
| 1236 void handleAsOperator(Token operator, Token endToken) { | 1238 void handleAsOperator(Token operator, Token endToken) { |
| 1237 debugEvent("AsOperator"); | 1239 debugEvent("AsOperator"); |
| 1238 DartType type = pop(); | 1240 DartType type = pop(); |
| 1239 Expression expression = popForValue(); | 1241 Expression expression = popForValue(); |
| 1240 push(new AsExpression(expression, type)); | 1242 push(new AsExpression(expression, type)..fileOffset = operator.charOffset); |
| 1241 } | 1243 } |
| 1242 | 1244 |
| 1243 @override | 1245 @override |
| 1244 void handleIsOperator(Token operator, Token not, Token endToken) { | 1246 void handleIsOperator(Token operator, Token not, Token endToken) { |
| 1245 debugEvent("IsOperator"); | 1247 debugEvent("IsOperator"); |
| 1246 DartType type = pop(); | 1248 DartType type = pop(); |
| 1247 Expression expression = popForValue(); | 1249 Expression expression = popForValue(); |
| 1248 expression = new IsExpression(expression, type); | 1250 expression = new IsExpression(expression, type) |
| 1251 ..fileOffset = operator.charOffset; |
| 1249 if (not != null) { | 1252 if (not != null) { |
| 1250 expression = new Not(expression); | 1253 expression = new Not(expression); |
| 1251 } | 1254 } |
| 1252 push(expression); | 1255 push(expression); |
| 1253 } | 1256 } |
| 1254 | 1257 |
| 1255 @override | 1258 @override |
| 1256 void handleConditionalExpression(Token question, Token colon) { | 1259 void handleConditionalExpression(Token question, Token colon) { |
| 1257 debugEvent("ConditionalExpression"); | 1260 debugEvent("ConditionalExpression"); |
| 1258 Expression elseExpression = popForValue(); | 1261 Expression elseExpression = popForValue(); |
| (...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2692 } else if (node is TypeDeclarationBuilder) { | 2695 } else if (node is TypeDeclarationBuilder) { |
| 2693 return node.name; | 2696 return node.name; |
| 2694 } else if (node is PrefixBuilder) { | 2697 } else if (node is PrefixBuilder) { |
| 2695 return node.name; | 2698 return node.name; |
| 2696 } else if (node is ThisPropertyAccessor) { | 2699 } else if (node is ThisPropertyAccessor) { |
| 2697 return node.name.name; | 2700 return node.name.name; |
| 2698 } else { | 2701 } else { |
| 2699 return internalError("Unhandled: ${node.runtimeType}"); | 2702 return internalError("Unhandled: ${node.runtimeType}"); |
| 2700 } | 2703 } |
| 2701 } | 2704 } |
| OLD | NEW |