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

Unified Diff: runtime/vm/parser.cc

Issue 9310007: Allow assignment expressions in conditional expressions (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/src/CondExprTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 3740)
+++ runtime/vm/parser.cc (working copy)
@@ -5453,7 +5453,7 @@
intptr_t token_id,
const char* s) {
char name[64];
- OS::SNPrint(name, 64, "%s%d", s, token_id);
+ OS::SNPrint(name, 64, ":%s%d", s, token_id);
LocalVariable* temp =
new LocalVariable(token_index,
String::ZoneHandle(String::NewSymbol(name)),
@@ -5473,28 +5473,32 @@
intptr_t token_id = node->id();
intptr_t token_index = node->token_index();
node = NULL; // Do not use it.
- if (!IsLocalOrLiteralNode(load_indexed->index_expr())) {
+ // The array object access may not have side effects.
+ // First, evaluate the array object expression if it might have side
+ // effects.
+ if (!IsLocalOrLiteralNode(load_indexed->array())) {
LocalVariable* temp =
- CreateTempConstVariable(token_index, token_id, "lix");
+ CreateTempConstVariable(token_index, token_id, "lia");
AstNode* save =
- new StoreLocalNode(token_index, *temp, load_indexed->index_expr());
+ new StoreLocalNode(token_index, *temp, load_indexed->array());
current_block_->statements->Add(save);
AstNode* load = new LoadLocalNode(token_index, *temp);
load_indexed = new LoadIndexedNode(token_index,
- load_indexed->array(),
- load);
+ load,
+ load_indexed->index_expr());
}
- // The array object access may not have side effects.
- if (!IsLocalOrLiteralNode(load_indexed->array())) {
+ // Second, evaluate the index expression and store in a temporary
+ // variable if it might have side effects.
+ if (!IsLocalOrLiteralNode(load_indexed->index_expr())) {
LocalVariable* temp =
- CreateTempConstVariable(token_index, token_id, "lia");
+ CreateTempConstVariable(token_index, token_id, "lix");
AstNode* save =
- new StoreLocalNode(token_index, *temp, load_indexed->array());
+ new StoreLocalNode(token_index, *temp, load_indexed->index_expr());
current_block_->statements->Add(save);
AstNode* load = new LoadLocalNode(token_index, *temp);
load_indexed = new LoadIndexedNode(token_index,
- load,
- load_indexed->index_expr());
+ load_indexed->array(),
+ load);
}
return load_indexed;
}
@@ -5643,9 +5647,9 @@
AstNode* expr = ParseBinaryExpr(Token::Precedence(Token::kOR));
if (CurrentToken() == Token::kCONDITIONAL) {
ConsumeToken();
- AstNode* expr1 = ParseConditionalExpr();
+ AstNode* expr1 = ParseExpr(kAllowConst);
ExpectToken(Token::kCOLON);
- AstNode* expr2 = ParseConditionalExpr();
+ AstNode* expr2 = ParseExpr(kAllowConst);
expr = new ConditionalExprNode(expr_pos, expr, expr1, expr2);
}
return expr;
@@ -7691,9 +7695,9 @@
SkipBinaryExpr();
if (CurrentToken() == Token::kCONDITIONAL) {
ConsumeToken();
- SkipConditionalExpr();
+ SkipExpr();
ExpectToken(Token::kCOLON);
- SkipConditionalExpr();
+ SkipExpr();
}
}
« no previous file with comments | « no previous file | tests/language/src/CondExprTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698