Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2908113002: Various constant checks. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 void handleVoidKeyword(Token token) { 1539 void handleVoidKeyword(Token token) {
1540 debugEvent("VoidKeyword"); 1540 debugEvent("VoidKeyword");
1541 push(const VoidType()); 1541 push(const VoidType());
1542 } 1542 }
1543 1543
1544 @override 1544 @override
1545 void handleAsOperator(Token operator, Token endToken) { 1545 void handleAsOperator(Token operator, Token endToken) {
1546 debugEvent("AsOperator"); 1546 debugEvent("AsOperator");
1547 DartType type = pop(); 1547 DartType type = pop();
1548 Expression expression = popForValue(); 1548 Expression expression = popForValue();
1549 push(new KernelAsExpression(expression, type) 1549 if (constantExpressionRequired) {
1550 ..fileOffset = offsetForToken(operator)); 1550 push(buildCompileTimeError(
1551 "Not a constant expression.", operator.charOffset));
1552 } else {
1553 push(new KernelAsExpression(expression, type)
1554 ..fileOffset = offsetForToken(operator));
1555 }
1551 } 1556 }
1552 1557
1553 @override 1558 @override
1554 void handleIsOperator(Token operator, Token not, Token endToken) { 1559 void handleIsOperator(Token operator, Token not, Token endToken) {
1555 debugEvent("IsOperator"); 1560 debugEvent("IsOperator");
1556 DartType type = pop(); 1561 DartType type = pop();
1557 Expression operand = popForValue(); 1562 Expression operand = popForValue();
1558 bool isInverted = not != null; 1563 bool isInverted = not != null;
1559 var offset = offsetForToken(operator); 1564 var offset = offsetForToken(operator);
1560 Expression isExpression = isInverted 1565 Expression isExpression = isInverted
1561 ? new KernelIsNotExpression(operand, type, offset) 1566 ? new KernelIsNotExpression(operand, type, offset)
1562 : new KernelIsExpression(operand, type) 1567 : new KernelIsExpression(operand, type)
1563 ..fileOffset = offset; 1568 ..fileOffset = offset;
1564 if (operand is VariableGet) { 1569 if (operand is VariableGet) {
1565 typePromoter.handleIsCheck(isExpression, isInverted, operand.variable, 1570 typePromoter.handleIsCheck(isExpression, isInverted, operand.variable,
1566 type, functionNestingLevel); 1571 type, functionNestingLevel);
1567 } 1572 }
1568 push(isExpression); 1573 if (constantExpressionRequired) {
1574 push(buildCompileTimeError(
1575 "Not a constant expression.", operator.charOffset));
1576 } else {
1577 push(isExpression);
1578 }
1569 } 1579 }
1570 1580
1571 @override 1581 @override
1572 void handleConditionalExpression(Token question, Token colon) { 1582 void handleConditionalExpression(Token question, Token colon) {
1573 debugEvent("ConditionalExpression"); 1583 debugEvent("ConditionalExpression");
1574 Expression elseExpression = popForValue(); 1584 Expression elseExpression = popForValue();
1575 Expression thenExpression = popForValue(); 1585 Expression thenExpression = popForValue();
1576 Expression condition = popForValue(); 1586 Expression condition = popForValue();
1577 push(new KernelConditionalExpression( 1587 push(new KernelConditionalExpression(
1578 condition, thenExpression, elseExpression)); 1588 condition, thenExpression, elseExpression));
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2901 2911
2902 Expression buildSimpleRead() { 2912 Expression buildSimpleRead() {
2903 return handleAssignment(false); 2913 return handleAssignment(false);
2904 } 2914 }
2905 2915
2906 Expression buildForEffect() { 2916 Expression buildForEffect() {
2907 return handleAssignment(true); 2917 return handleAssignment(true);
2908 } 2918 }
2909 2919
2910 Expression handleAssignment(bool voidContext) { 2920 Expression handleAssignment(bool voidContext) {
2921 if (helper.constantExpressionRequired) {
2922 return helper.buildCompileTimeError(
2923 "Not a constant expression.", offsetForToken(token));
2924 }
2911 if (identical("=", assignmentOperator)) { 2925 if (identical("=", assignmentOperator)) {
2912 return accessor.buildAssignment(value, voidContext: voidContext); 2926 return accessor.buildAssignment(value, voidContext: voidContext);
2913 } else if (identical("+=", assignmentOperator)) { 2927 } else if (identical("+=", assignmentOperator)) {
2914 return accessor.buildCompoundAssignment(plusName, value, 2928 return accessor.buildCompoundAssignment(plusName, value,
2915 offset: offsetForToken(token), voidContext: voidContext); 2929 offset: offsetForToken(token), voidContext: voidContext);
2916 } else if (identical("-=", assignmentOperator)) { 2930 } else if (identical("-=", assignmentOperator)) {
2917 return accessor.buildCompoundAssignment(minusName, value, 2931 return accessor.buildCompoundAssignment(minusName, value,
2918 offset: offsetForToken(token), voidContext: voidContext); 2932 offset: offsetForToken(token), voidContext: voidContext);
2919 } else if (identical("*=", assignmentOperator)) { 2933 } else if (identical("*=", assignmentOperator)) {
2920 return accessor.buildCompoundAssignment(multiplyName, value, 2934 return accessor.buildCompoundAssignment(multiplyName, value,
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
3240 if (starToken == null) { 3254 if (starToken == null) {
3241 return AsyncMarker.Async; 3255 return AsyncMarker.Async;
3242 } else { 3256 } else {
3243 assert(identical(starToken.stringValue, "*")); 3257 assert(identical(starToken.stringValue, "*"));
3244 return AsyncMarker.AsyncStar; 3258 return AsyncMarker.AsyncStar;
3245 } 3259 }
3246 } else { 3260 } else {
3247 return internalError("Unknown async modifier: $asyncToken"); 3261 return internalError("Unknown async modifier: $asyncToken");
3248 } 3262 }
3249 } 3263 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698