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

Unified Diff: frog/gen.dart

Issue 8947008: When += (and similar operations) are converted to = + , (Closed) Base URL: http://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
===================================================================
--- frog/gen.dart (revision 2468)
+++ frog/gen.dart (working copy)
@@ -1804,6 +1804,11 @@
return target.invoke(this, ':index', node, new Arguments(null, [index]));
}
+ bool _expressionNeedsParens(Expression e) {
+ return (e is BinaryExpression || e is ConditionalExpression
+ || e is PostfixExpression || _isUnaryIncrement(e));
+ }
+
visitBinaryExpression(BinaryExpression node, [bool isVoid = false]) {
final kind = node.op.kind;
// TODO(jimhug): Ensure these have same semantics as JS!
@@ -1870,7 +1875,10 @@
return;
}
return x.invoke(this, name, node, new Arguments(null, [y]));
- } else {
+ } else if ((assignKind != 0) && _expressionNeedsParens(node.y)) {
+ return _visitAssign(assignKind, node.x,
+ new ParenExpression(node.y, node.y.span), node, null, isVoid);
+ } else {
return _visitAssign(assignKind, node.x, node.y, node, null, isVoid);
}
}
@@ -2388,8 +2396,7 @@
// TODO(jmesserly): We could be smarter about prefix/postfix, but we'd
// need to know if it will compile to a ++ or to some sort of += form.
var code = val.code;
- if (item is BinaryExpression || item is ConditionalExpression
- || item is PostfixExpression || _isUnaryIncrement(item)) {
+ if (_expressionNeedsParens(item)) {
code = '(${code})';
}
// No need to concat empty strings except the first.
« 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