Commit 04540faa authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

ensure that index expression in element access doesn't get evaluated more

2007-07-25  Juerg Billeter  <j@bitron.ch>

	* gobject/valacodegeneratorassignment.vala: ensure that index expression
	  in element access doesn't get evaluated more than once

svn path=/trunk/; revision=385
parent 625a5e71
2007-07-25 Jürg Billeter <j@bitron.ch>
* gobject/valacodegeneratorassignment.vala: ensure that index expression
in element access doesn't get evaluated more than once
2007-07-25 Jürg Billeter <j@bitron.ch>
* ccode/valaccodefunction.vala: add void to function declarations
......
......@@ -258,6 +258,24 @@ public class Vala.CodeGenerator {
}
a.ccodenode = new CCodeAssignment ((CCodeExpression) a.left.ccodenode, rhs, cop);
if (unref_old && a.left.ccodenode is CCodeElementAccess) {
// ensure that index expression in element access doesn't get evaluated more than once
// except when it's a simple expression
var cea = (CCodeElementAccess) a.left.ccodenode;
if (!(cea.index is CCodeConstant || cea.index is CCodeIdentifier)) {
var index_temp_decl = get_temp_variable_declarator (int_type);
temp_vars.prepend (index_temp_decl);
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (index_temp_decl.name), cea.index));
ccomma.append_expression ((CCodeExpression) a.ccodenode);
cea.index = new CCodeIdentifier (index_temp_decl.name);
a.ccodenode = ccomma;
}
}
}
}
......
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