Commit f6dad615 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

transform compund assignments into simple assignments add default argument

2006-10-05  Jürg Billeter  <j@bitron.ch>

	* vala/valasemanticanalyzer.vala: transform compund assignments into
	  simple assignments
	* vala/valabinaryexpression.vala: add default argument to construction
	  method
	* tests/test-021.vala: test string += assignment

svn path=/trunk/; revision=141
parent dec15a0f
2006-10-05 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: transform compund assignments into
simple assignments
* vala/valabinaryexpression.vala: add default argument to construction
method
* tests/test-021.vala: test string += assignment
2006-10-04 Jürg Billeter <j@bitron.ch>
* vala/valasymbolresolver.vala: correct takes_ownership in arrays
......
......@@ -5,8 +5,13 @@ class Maman.Foo {
stdout.printf ("String + operator: 1");
stdout.printf (" 2" + " 3");
string s = " 4";
s += " 5";
stdout.printf ("%s", s);
stdout.printf (" 4\n");
stdout.printf (" 6\n");
return 0;
}
......
......@@ -71,7 +71,7 @@ public class Vala.BinaryExpression : Expression {
* @param source reference to source code
* @return newly created binary expression
*/
public construct (BinaryOperator op, Expression! _left, Expression! _right, SourceReference source) {
public construct (BinaryOperator op, Expression! _left, Expression! _right, SourceReference source = null) {
operator = op;
left = _left;
right = _right;
......
......@@ -1475,6 +1475,47 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
a.error = true;
return;
}
if (a.operator != AssignmentOperator.SIMPLE && a.left is MemberAccess) {
// transform into simple assignment
// FIXME: only do this if the backend doesn't support
// the assignment natively
var ma = (MemberAccess) a.left;
if (!(ma.symbol_reference.node is Signal)) {
var old_value = new MemberAccess (ma.inner, ma.member_name);
var bin = new BinaryExpression (BinaryOperator.PLUS, old_value, a.right);
if (a.operator == AssignmentOperator.BITWISE_OR) {
bin.operator = BinaryOperator.BITWISE_OR;
} else if (a.operator == AssignmentOperator.BITWISE_AND) {
bin.operator = BinaryOperator.BITWISE_AND;
} else if (a.operator == AssignmentOperator.BITWISE_XOR) {
bin.operator = BinaryOperator.BITWISE_XOR;
} else if (a.operator == AssignmentOperator.ADD) {
bin.operator = BinaryOperator.PLUS;
} else if (a.operator == AssignmentOperator.SUB) {
bin.operator = BinaryOperator.MINUS;
} else if (a.operator == AssignmentOperator.MUL) {
bin.operator = BinaryOperator.MUL;
} else if (a.operator == AssignmentOperator.DIV) {
bin.operator = BinaryOperator.DIV;
} else if (a.operator == AssignmentOperator.PERCENT) {
bin.operator = BinaryOperator.MOD;
} else if (a.operator == AssignmentOperator.SHIFT_LEFT) {
bin.operator = BinaryOperator.SHIFT_LEFT;
} else if (a.operator == AssignmentOperator.SHIFT_RIGHT) {
bin.operator = BinaryOperator.SHIFT_RIGHT;
}
a.right = bin;
a.right.accept (this);
a.operator = AssignmentOperator.SIMPLE;
}
}
if (a.left is MemberAccess) {
var ma = (MemberAccess) a.left;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment