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

Unified Diff: frog/gen.dart

Issue 8802028: fix set index bug in frog. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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 | frog/minfrog » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/gen.dart
diff --git a/frog/gen.dart b/frog/gen.dart
index 8f97336186bfaccc60d80805d7530f1be14866b6..fbec44d6c46909a31d6481e749fd354c86e54242 100644
--- a/frog/gen.dart
+++ b/frog/gen.dart
@@ -1178,6 +1178,10 @@ class MethodGenerator implements TreeVisitor {
var value = visitPostfixExpression(node, /*isVoid:*/true);
value.checkFirstClass(node.span);
return value;
+ } else if (node is BinaryExpression) {
+ var value = visitBinaryExpression(node, /*isVoid:*/true);
Jennifer Messerly 2011/12/06 01:06:39 you could actually pass "isVoid:true" now :)
+ value.checkFirstClass(node.span);
+ return value;
}
// TODO(jimhug): Some level of warnings for non-void things here?
return visitValue(node);
@@ -1749,7 +1753,7 @@ class MethodGenerator implements TreeVisitor {
return target.invoke(this, ':index', node, new Arguments(null, [index]));
}
- visitBinaryExpression(BinaryExpression node) {
+ visitBinaryExpression(BinaryExpression node, [bool isVoid = false]) {
final kind = node.op.kind;
// TODO(jimhug): Ensure these have same semantics as JS!
if (kind == TokenKind.AND || kind == TokenKind.OR) {
@@ -1816,7 +1820,7 @@ class MethodGenerator implements TreeVisitor {
}
return x.invoke(this, name, node, new Arguments(null, [y]));
} else {
- return _visitAssign(assignKind, node.x, node.y, node, null);
+ return _visitAssign(assignKind, node.x, node.y, node, null, isVoid);
}
}
@@ -1827,7 +1831,7 @@ class MethodGenerator implements TreeVisitor {
* original value, before it has been modified.
*/
_visitAssign(int kind, Expression xn, Expression yn, Node position,
- Value captureOriginal(Value right)) {
+ Value captureOriginal(Value right), [bool isVoid = false]) {
if (captureOriginal == null) {
captureOriginal = (x) => x;
@@ -1837,7 +1841,7 @@ class MethodGenerator implements TreeVisitor {
if (xn is VarExpression) {
return _visitVarAssign(kind, xn, yn, position, captureOriginal);
} else if (xn is IndexExpression) {
- return _visitIndexAssign(kind, xn, yn, position, captureOriginal);
+ return _visitIndexAssign(kind, xn, yn, position, captureOriginal, isVoid);
} else if (xn is DotExpression) {
return _visitDotAssign(kind, xn, yn, position, captureOriginal);
} else {
@@ -1928,7 +1932,7 @@ class MethodGenerator implements TreeVisitor {
}
_visitIndexAssign(int kind, IndexExpression xn, Expression yn, Node position,
- Value captureOriginal(Value right)) {
+ Value captureOriginal(Value right), [bool isVoid = false]) {
var target = visitValue(xn.target);
var index = visitValue(xn.index);
var y = visitValue(yn);
@@ -1945,8 +1949,20 @@ class MethodGenerator implements TreeVisitor {
y = right.invoke(this, TokenKind.binaryMethodName(kind),
position, new Arguments(null, [y]));
}
+
+ var tmpy = null;
+ // If the assignment is an expression statement (x[i] = y;) it is translated
+ // as (x.$setindex(i, y)), otherwise as (x.$setindex(i, t = y), t).
+ if (!isVoid) {
+ tmpy = getTemp(y);
+ y = assignTemp(tmpy, y);
+ }
var ret = assignTemp(tmptarget, target).invoke(this, ':setindex',
position, new Arguments(null, [index, y]));
+ if (tmpy != null) {
+ ret = new Value(ret.type, '(${ret.code}, ${tmpy.code})', ret.span);
+ if (tmpy != y) freeTemp(tmpy);
+ }
if (tmptarget != target) freeTemp(tmptarget);
if (tmpindex != index) freeTemp(tmpindex);
return ret;
« no previous file with comments | « no previous file | frog/minfrog » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698