| 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 'package:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
| 8 hide InvalidExpression, InvalidInitializer, InvalidStatement; | 8 hide InvalidExpression, InvalidInitializer, InvalidStatement; |
| 9 | 9 |
| 10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 FastaAccessor accessor = expression; | 382 FastaAccessor accessor = expression; |
| 383 expression = accessor.buildPropertyAccess( | 383 expression = accessor.buildPropertyAccess( |
| 384 new IncompletePropertyAccessor( | 384 new IncompletePropertyAccessor( |
| 385 this, period.next, new Name(name, library.library)), | 385 this, period.next, new Name(name, library.library)), |
| 386 period.next.offset, | 386 period.next.offset, |
| 387 false); | 387 false); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool savedConstantExpressionRequired = pop(); | 390 bool savedConstantExpressionRequired = pop(); |
| 391 if (expression is! StaticAccessor) { | 391 if (expression is! StaticAccessor) { |
| 392 push(deprecated_wrapInCompileTimeError( | 392 push(wrapInCompileTimeError( |
| 393 toValue(expression), | 393 toValue(expression), fasta.messageExpressionNotMetadata)); |
| 394 "This can't be used as metadata; metadata should be a reference to " | |
| 395 "a compile-time constant variable, or " | |
| 396 "a call to a constant constructor.")); | |
| 397 } else { | 394 } else { |
| 398 push(toValue(expression)); | 395 push(toValue(expression)); |
| 399 } | 396 } |
| 400 constantExpressionRequired = savedConstantExpressionRequired; | 397 constantExpressionRequired = savedConstantExpressionRequired; |
| 401 } | 398 } |
| 402 } | 399 } |
| 403 | 400 |
| 404 @override | 401 @override |
| 405 void endMetadataStar(int count, bool forParameter) { | 402 void endMetadataStar(int count, bool forParameter) { |
| 406 debugEvent("MetadataStar"); | 403 debugEvent("MetadataStar"); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 if (node is Initializer) { | 550 if (node is Initializer) { |
| 554 initializer = node; | 551 initializer = node; |
| 555 } else if (node is FastaAccessor) { | 552 } else if (node is FastaAccessor) { |
| 556 initializer = node.buildFieldInitializer(initializedFields); | 553 initializer = node.buildFieldInitializer(initializedFields); |
| 557 } else if (node is ConstructorInvocation) { | 554 } else if (node is ConstructorInvocation) { |
| 558 initializer = | 555 initializer = |
| 559 buildSuperInitializer(node.target, node.arguments, token.charOffset); | 556 buildSuperInitializer(node.target, node.arguments, token.charOffset); |
| 560 } else { | 557 } else { |
| 561 Expression value = toValue(node); | 558 Expression value = toValue(node); |
| 562 if (node is! Throw) { | 559 if (node is! Throw) { |
| 563 value = deprecated_wrapInCompileTimeError( | 560 value = |
| 564 value, "Expected an initializer."); | 561 wrapInCompileTimeError(value, fasta.messageExpectedAnInitializer); |
| 565 } | 562 } |
| 566 initializer = buildInvalidInitializer(node, token.charOffset); | 563 initializer = buildInvalidInitializer(node, token.charOffset); |
| 567 } | 564 } |
| 568 _typeInferrer.inferInitializer(initializer); | 565 _typeInferrer.inferInitializer(initializer); |
| 569 if (member is KernelConstructorBuilder && !member.isExternal) { | 566 if (member is KernelConstructorBuilder && !member.isExternal) { |
| 570 member.addInitializer(initializer); | 567 member.addInitializer(initializer); |
| 571 } else { | 568 } else { |
| 572 deprecated_addCompileTimeError( | 569 deprecated_addCompileTimeError( |
| 573 token.charOffset, "Can't have initializers: ${member.name}"); | 570 token.charOffset, "Can't have initializers: ${member.name}"); |
| 574 } | 571 } |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 exitLocalScope(); | 1422 exitLocalScope(); |
| 1426 push(block); | 1423 push(block); |
| 1427 } | 1424 } |
| 1428 | 1425 |
| 1429 @override | 1426 @override |
| 1430 void handleAssignmentExpression(Token token) { | 1427 void handleAssignmentExpression(Token token) { |
| 1431 debugEvent("AssignmentExpression"); | 1428 debugEvent("AssignmentExpression"); |
| 1432 Expression value = popForValue(); | 1429 Expression value = popForValue(); |
| 1433 var accessor = pop(); | 1430 var accessor = pop(); |
| 1434 if (accessor is! FastaAccessor) { | 1431 if (accessor is! FastaAccessor) { |
| 1435 push(deprecated_buildCompileTimeError( | 1432 push(buildCompileTimeError(fasta.messageNotAnLvalue, token.charOffset)); |
| 1436 "Can't assign to this.", token.charOffset)); | |
| 1437 } else { | 1433 } else { |
| 1438 push(new DelayedAssignment( | 1434 push(new DelayedAssignment( |
| 1439 this, token, accessor, value, token.stringValue)); | 1435 this, token, accessor, value, token.stringValue)); |
| 1440 } | 1436 } |
| 1441 } | 1437 } |
| 1442 | 1438 |
| 1443 @override | 1439 @override |
| 1444 void enterLoop(int charOffset) { | 1440 void enterLoop(int charOffset) { |
| 1445 if (peek() is LabelTarget) { | 1441 if (peek() is LabelTarget) { |
| 1446 LabelTarget target = peek(); | 1442 LabelTarget target = peek(); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2059 } | 2055 } |
| 2060 | 2056 |
| 2061 @override | 2057 @override |
| 2062 void handleUnaryPrefixAssignmentExpression(Token token) { | 2058 void handleUnaryPrefixAssignmentExpression(Token token) { |
| 2063 debugEvent("UnaryPrefixAssignmentExpression"); | 2059 debugEvent("UnaryPrefixAssignmentExpression"); |
| 2064 var accessor = pop(); | 2060 var accessor = pop(); |
| 2065 if (accessor is FastaAccessor) { | 2061 if (accessor is FastaAccessor) { |
| 2066 push(accessor.buildPrefixIncrement(incrementOperator(token), | 2062 push(accessor.buildPrefixIncrement(incrementOperator(token), |
| 2067 offset: token.charOffset)); | 2063 offset: token.charOffset)); |
| 2068 } else { | 2064 } else { |
| 2069 push(deprecated_wrapInCompileTimeError( | 2065 push(wrapInCompileTimeError(toValue(accessor), fasta.messageNotAnLvalue)); |
| 2070 toValue(accessor), "Can't assign to this.")); | |
| 2071 } | 2066 } |
| 2072 } | 2067 } |
| 2073 | 2068 |
| 2074 @override | 2069 @override |
| 2075 void handleUnaryPostfixAssignmentExpression(Token token) { | 2070 void handleUnaryPostfixAssignmentExpression(Token token) { |
| 2076 debugEvent("UnaryPostfixAssignmentExpression"); | 2071 debugEvent("UnaryPostfixAssignmentExpression"); |
| 2077 var accessor = pop(); | 2072 var accessor = pop(); |
| 2078 if (accessor is FastaAccessor) { | 2073 if (accessor is FastaAccessor) { |
| 2079 push(new DelayedPostfixIncrement( | 2074 push(new DelayedPostfixIncrement( |
| 2080 this, token, accessor, incrementOperator(token), null)); | 2075 this, token, accessor, incrementOperator(token), null)); |
| 2081 } else { | 2076 } else { |
| 2082 push(deprecated_wrapInCompileTimeError( | 2077 push(wrapInCompileTimeError(toValue(accessor), fasta.messageNotAnLvalue)); |
| 2083 toValue(accessor), "Can't assign to this.")); | |
| 2084 } | 2078 } |
| 2085 } | 2079 } |
| 2086 | 2080 |
| 2087 @override | 2081 @override |
| 2088 void endConstructorReference( | 2082 void endConstructorReference( |
| 2089 Token start, Token periodBeforeName, Token endToken) { | 2083 Token start, Token periodBeforeName, Token endToken) { |
| 2090 debugEvent("ConstructorReference"); | 2084 debugEvent("ConstructorReference"); |
| 2091 pushQualifiedReference(start, periodBeforeName); | 2085 pushQualifiedReference(start, periodBeforeName); |
| 2092 } | 2086 } |
| 2093 | 2087 |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3089 // TODO(ahe): This method should be passed the erroneous expression, wrap | 3083 // TODO(ahe): This method should be passed the erroneous expression, wrap |
| 3090 // it in a class (TBD) from which the erroneous expression can be easily | 3084 // it in a class (TBD) from which the erroneous expression can be easily |
| 3091 // extracted. Similar for statements and initializers. See also [issue | 3085 // extracted. Similar for statements and initializers. See also [issue |
| 3092 // 29717](https://github.com/dart-lang/sdk/issues/29717) | 3086 // 29717](https://github.com/dart-lang/sdk/issues/29717) |
| 3093 library.addCompileTimeError(message, charOffset, uri, wasHandled: true); | 3087 library.addCompileTimeError(message, charOffset, uri, wasHandled: true); |
| 3094 return new KernelSyntheticExpression(library.loader | 3088 return new KernelSyntheticExpression(library.loader |
| 3095 .throwCompileConstantError( | 3089 .throwCompileConstantError( |
| 3096 library.loader.buildCompileTimeError(message, charOffset, uri))); | 3090 library.loader.buildCompileTimeError(message, charOffset, uri))); |
| 3097 } | 3091 } |
| 3098 | 3092 |
| 3099 Expression deprecated_wrapInCompileTimeError( | 3093 Expression wrapInCompileTimeError(Expression expression, Message message) { |
| 3100 Expression expression, String message) { | |
| 3101 return new Let( | 3094 return new Let( |
| 3102 new VariableDeclaration.forValue(expression) | 3095 new VariableDeclaration.forValue(expression) |
| 3103 ..fileOffset = expression.fileOffset, | 3096 ..fileOffset = expression.fileOffset, |
| 3104 deprecated_buildCompileTimeError(message, expression.fileOffset)) | 3097 buildCompileTimeError(message, expression.fileOffset)) |
| 3105 ..fileOffset = expression.fileOffset; | 3098 ..fileOffset = expression.fileOffset; |
| 3106 } | 3099 } |
| 3107 | 3100 |
| 3108 Expression buildFallThroughError(int charOffset) { | 3101 Expression buildFallThroughError(int charOffset) { |
| 3109 warningNotError(fasta.messageSwitchCaseFallThrough, charOffset); | 3102 warningNotError(fasta.messageSwitchCaseFallThrough, charOffset); |
| 3110 | 3103 |
| 3111 Location location = messages.getLocationFromUri(uri, charOffset); | 3104 Location location = messages.getLocationFromUri(uri, charOffset); |
| 3112 | 3105 |
| 3113 return new Throw(buildStaticInvocation( | 3106 return new Throw(buildStaticInvocation( |
| 3114 library.loader.coreTypes.fallThroughErrorUrlAndLineConstructor, | 3107 library.loader.coreTypes.fallThroughErrorUrlAndLineConstructor, |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3800 return AsyncMarker.Async; | 3793 return AsyncMarker.Async; |
| 3801 } else { | 3794 } else { |
| 3802 assert(identical(starToken.stringValue, "*")); | 3795 assert(identical(starToken.stringValue, "*")); |
| 3803 return AsyncMarker.AsyncStar; | 3796 return AsyncMarker.AsyncStar; |
| 3804 } | 3797 } |
| 3805 } else { | 3798 } else { |
| 3806 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", | 3799 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", |
| 3807 asyncToken.charOffset, null); | 3800 asyncToken.charOffset, null); |
| 3808 } | 3801 } |
| 3809 } | 3802 } |
| OLD | NEW |