Commit 53e42b59 authored by Luca Bruno's avatar Luca Bruno Committed by Jürg Billeter

codegen: Add CCodeFunction.add_assignment convenience function

parent 1291020f
......@@ -245,6 +245,10 @@ public class Vala.CCodeFunction : CCodeNode {
current_block.add_statement (new CCodeExpressionStatement (expression));
}
public void add_assignment (CCodeExpression left, CCodeExpression right) {
add_expression (new CCodeAssignment (left, right));
}
public void add_return (CCodeExpression? expression = null) {
current_block.add_statement (new CCodeReturnStatement (expression));
}
......
......@@ -32,7 +32,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
if (rank > 1) {
append_initializer_list (name_cnode, (InitializerList) e, rank - 1, ref i);
} else {
ccode.add_expression (new CCodeAssignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), get_cvalue (e)));
ccode.add_assignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), get_cvalue (e));
i++;
}
}
......@@ -113,7 +113,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
emit_temp_var (temp_var);
ccode.add_expression (new CCodeAssignment (name_cnode, gnew));
ccode.add_assignment (name_cnode, gnew);
if (expr.initializer_list != null) {
append_initializer_list (name_cnode, expr.initializer_list, expr.rank, ref i);
......@@ -514,7 +514,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
gnew.add_argument (length_expr);
ccode.add_declaration (array_type.get_cname (), cvardecl);
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("result"), gnew));
ccode.add_assignment (new CCodeIdentifier ("result"), gnew);
ccode.add_declaration ("int", new CCodeVariableDeclarator ("i"));
......@@ -522,7 +522,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")),
new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
ccode.add_expression (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type)));
ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type));
ccode.close ();
ccode.add_return (new CCodeIdentifier ("result"));
......@@ -576,7 +576,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
ccode.add_expression (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type)));
ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type));
} else {
cfile.add_include ("string.h");
......@@ -647,15 +647,15 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var csizecheck = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, length, size);
ccode.open_if (csizecheck);
ccode.add_expression (new CCodeAssignment (size, new CCodeConditionalExpression (size, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("2"), size), new CCodeConstant ("4"))));
ccode.add_expression (new CCodeAssignment (array, renew_call));
ccode.add_assignment (size, new CCodeConditionalExpression (size, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("2"), size), new CCodeConstant ("4")));
ccode.add_assignment (array, renew_call);
ccode.close ();
ccode.add_expression (new CCodeAssignment (new CCodeElementAccess (array, new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, length)), value));
ccode.add_assignment (new CCodeElementAccess (array, new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, length)), value);
if (array_type.element_type.is_reference_type_or_type_parameter ()) {
// NULL terminate array
ccode.add_expression (new CCodeAssignment (new CCodeElementAccess (array, length), new CCodeConstant ("NULL")));
ccode.add_assignment (new CCodeElementAccess (array, length), new CCodeConstant ("NULL"));
}
pop_function ();
......
......@@ -55,13 +55,13 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
string lhs_temp_name = "_tmp%d_".printf (next_temp_var_id++);
var lhs_temp = new LocalVariable (lhs_value_type, "*" + lhs_temp_name);
emit_temp_var (lhs_temp);
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
ccode.add_assignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs));
lhs = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (lhs_temp_name)));
}
var temp_decl = get_temp_variable (assignment.left.value_type, true, null, false);
emit_temp_var (temp_decl);
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), rhs));
ccode.add_assignment (get_variable_cexpression (temp_decl.name), rhs);
if (unref_old) {
/* unref old value */
ccode.add_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
......@@ -72,7 +72,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
for (int dim = 1; dim <= array_type.rank; dim++) {
var lhs_array_len = get_array_length_cexpression (assignment.left, dim);
var rhs_array_len = get_array_length_cexpression (assignment.right, dim);
ccode.add_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
ccode.add_assignment (lhs_array_len, rhs_array_len);
}
if (array_type.rank == 1) {
var array_var = assignment.left.symbol_reference;
......@@ -81,16 +81,16 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
&& ((array_var is LocalVariable && !array_local.captured) || array_var is Field)) {
var lhs_array_size = get_array_size_cvalue (assignment.left.target_value);
var rhs_array_len = get_array_length_cexpression (assignment.left, 1);
ccode.add_expression (new CCodeAssignment (lhs_array_size, rhs_array_len));
ccode.add_assignment (lhs_array_size, rhs_array_len);
}
}
} else if (instance_delegate) {
CCodeExpression lhs_delegate_target_destroy_notify, rhs_delegate_target_destroy_notify;
var lhs_delegate_target = get_delegate_target_cexpression (assignment.left, out lhs_delegate_target_destroy_notify);
var rhs_delegate_target = get_delegate_target_cexpression (assignment.right, out rhs_delegate_target_destroy_notify);
ccode.add_expression (new CCodeAssignment (lhs_delegate_target, rhs_delegate_target));
ccode.add_assignment (lhs_delegate_target, rhs_delegate_target);
if (assignment.right.target_type.value_owned) {
ccode.add_expression (new CCodeAssignment (lhs_delegate_target_destroy_notify, rhs_delegate_target_destroy_notify));
ccode.add_assignment (lhs_delegate_target_destroy_notify, rhs_delegate_target_destroy_notify);
}
}
......@@ -177,21 +177,21 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
ccode.add_expression (destroy_value (lvalue));
}
ccode.add_expression (new CCodeAssignment (get_cvalue_ (lvalue), get_cvalue_ (value)));
ccode.add_assignment (get_cvalue_ (lvalue), get_cvalue_ (value));
var array_type = variable.variable_type as ArrayType;
if (array_type != null) {
for (int dim = 1; dim <= array_type.rank; dim++) {
if (get_array_length_cvalue (lvalue, dim) != null) {
ccode.add_expression (new CCodeAssignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim)));
ccode.add_assignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim));
}
}
if (array_type.rank == 1) {
if (get_array_size_cvalue (lvalue) != null) {
if (get_array_size_cvalue (value) != null) {
ccode.add_expression (new CCodeAssignment (get_array_size_cvalue (lvalue), get_array_size_cvalue (value)));
ccode.add_assignment (get_array_size_cvalue (lvalue), get_array_size_cvalue (value));
} else {
ccode.add_expression (new CCodeAssignment (get_array_size_cvalue (lvalue), get_array_length_cvalue (value, 1)));
ccode.add_assignment (get_array_size_cvalue (lvalue), get_array_length_cvalue (value, 1));
}
}
}
......@@ -200,9 +200,9 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
var delegate_type = variable.variable_type as DelegateType;
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
if (get_delegate_target_cvalue (lvalue) != null) {
ccode.add_expression (new CCodeAssignment (get_delegate_target_cvalue (lvalue), get_delegate_target_cvalue (value)));
ccode.add_assignment (get_delegate_target_cvalue (lvalue), get_delegate_target_cvalue (value));
if (get_delegate_target_destroy_notify_cvalue (lvalue) != null) {
ccode.add_expression (new CCodeAssignment (get_delegate_target_destroy_notify_cvalue (lvalue), get_delegate_target_destroy_notify_cvalue (value)));
ccode.add_assignment (get_delegate_target_destroy_notify_cvalue (lvalue), get_delegate_target_destroy_notify_cvalue (value));
}
}
}
......
This diff is collapsed.
......@@ -236,7 +236,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
var ccolvardecl = new CCodeVariableDeclarator (collection_backup.name);
ccode.add_declaration (collection_type.get_cname (), ccolvardecl);
}
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (collection_backup.name), get_cvalue (stmt.collection)));
ccode.add_assignment (get_variable_cexpression (collection_backup.name), get_cvalue (stmt.collection));
if (stmt.tree_can_fail && stmt.collection.tree_can_fail) {
// exception handling
......@@ -254,7 +254,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
} else {
ccode.add_declaration ("int", new CCodeVariableDeclarator (get_array_length_cname (collection_backup.name, 1)));
}
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (get_array_length_cname (collection_backup.name, 1)), array_len));
ccode.add_assignment (get_variable_cexpression (get_array_length_cname (collection_backup.name, 1)), array_len);
var it_name = (stmt.variable_name + "_it");
......@@ -281,7 +281,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
} else {
ccode.add_declaration (stmt.type_reference.get_cname (), new CCodeVariableDeclarator (stmt.variable_name));
}
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (stmt.variable_name), element_expr));
ccode.add_assignment (get_variable_cexpression (stmt.variable_name), element_expr);
// add array length variable for stacked arrays
if (stmt.type_reference is ArrayType) {
......@@ -289,7 +289,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
for (int dim = 1; dim <= inner_array_type.rank; dim++) {
if (current_method != null && current_method.coroutine) {
closure_struct.add_field ("int", get_array_length_cname (stmt.variable_name, dim));
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (get_array_length_cname (stmt.variable_name, dim)), new CCodeConstant ("-1")));
ccode.add_assignment (get_variable_cexpression (get_array_length_cname (stmt.variable_name, dim)), new CCodeConstant ("-1"));
} else {
ccode.add_declaration ("int", new CCodeVariableDeclarator (get_array_length_cname (stmt.variable_name, dim), new CCodeConstant ("-1")));
}
......@@ -334,7 +334,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
} else {
ccode.add_declaration (stmt.type_reference.get_cname (), new CCodeVariableDeclarator (stmt.variable_name));
}
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (stmt.variable_name), element_expr));
ccode.add_assignment (get_variable_cexpression (stmt.variable_name), element_expr);
stmt.body.emit (this);
......@@ -371,7 +371,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
} else {
ccode.add_declaration (stmt.type_reference.get_cname (), new CCodeVariableDeclarator (stmt.variable_name));
}
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (stmt.variable_name), element_expr));
ccode.add_assignment (get_variable_cexpression (stmt.variable_name), element_expr);
stmt.body.emit (this);
......
......@@ -436,7 +436,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
ccode.add_expression (ccall);
} else {
ccode.add_expression (new CCodeAssignment (ctemp, ccall));
ccode.add_assignment (ctemp, ccall);
array_type = base_property.property_type as ArrayType;
if (array_type != null && !base_property.no_array_length) {
......
......@@ -689,7 +689,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
// set state before calling async function to support immediate callbacks
int state = next_coroutine_state++;
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_state_"), new CCodeConstant (state.to_string ())));
ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_state_"), new CCodeConstant (state.to_string ()));
ccode.add_expression (async_call);
ccode.add_return (new CCodeConstant ("FALSE"));
ccode.add_label ("_state_%d".printf (state));
......@@ -721,16 +721,16 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
czero.add_argument (new CCodeConstant ("0"));
czero.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, csizeof, cdelta));
ccode.add_expression (new CCodeAssignment (temp_ref, new_size));
ccode.add_assignment (temp_ref, new_size);
ccode.add_expression (ccall_expr);
ccode.add_expression (new CCodeConditionalExpression (ccheck, czero, new CCodeConstant ("NULL")));
ccode.add_expression (new CCodeAssignment (get_array_length_cexpression (ma.inner, 1), temp_ref));
ccode.add_assignment (get_array_length_cexpression (ma.inner, 1), temp_ref);
var array_var = ma.inner.symbol_reference;
var array_local = array_var as LocalVariable;
if (array_var != null && array_var.is_internal_symbol ()
&& ((array_var is LocalVariable && !array_local.captured) || array_var is Field)) {
ccode.add_expression (new CCodeAssignment (get_array_size_cvalue (ma.inner.target_value), temp_ref));
ccode.add_assignment (get_array_size_cvalue (ma.inner.target_value), temp_ref);
}
return;
......@@ -757,7 +757,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
emit_temp_var (temp_var);
ccode.add_expression (new CCodeAssignment (temp_ref, ccall_expr));
ccode.add_assignment (temp_ref, ccall_expr);
set_cvalue (expr, temp_ref);
}
......@@ -782,18 +782,18 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
}
// assign new value
ccode.add_expression (new CCodeAssignment (get_cvalue (unary.inner), transform_expression (get_cvalue (unary), unary.target_type, unary.inner.value_type, arg)));
ccode.add_assignment (get_cvalue (unary.inner), transform_expression (get_cvalue (unary), unary.target_type, unary.inner.value_type, arg));
var array_type = arg.value_type as ArrayType;
if (array_type != null) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.add_expression (new CCodeAssignment (get_array_sizes (unary.inner).get (dim - 1), get_array_sizes (unary).get (dim - 1)));
ccode.add_assignment (get_array_sizes (unary.inner).get (dim - 1), get_array_sizes (unary).get (dim - 1));
}
}
var delegate_type = arg.value_type as DelegateType;
if (delegate_type != null) {
ccode.add_expression (new CCodeAssignment (get_delegate_target (unary.inner), get_delegate_target (unary)));
ccode.add_assignment (get_delegate_target (unary.inner), get_delegate_target (unary));
}
}
}
......
......@@ -391,7 +391,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
var parent_data = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_data%d_".printf (parent_block_id));
ccode.add_declaration ("Block%dData*".printf (parent_block_id), new CCodeVariableDeclarator ("_data%d_".printf (parent_block_id)));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_data%d_".printf (parent_block_id)), parent_data));
ccode.add_assignment (new CCodeIdentifier ("_data%d_".printf (parent_block_id)), parent_data);
closure_block = parent_closure_block;
block_id = parent_block_id;
......@@ -402,7 +402,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
if (m.binding == MemberBinding.INSTANCE) {
var cself = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "self");
ccode.add_declaration ("%s *".printf (current_class.get_cname ()), new CCodeVariableDeclarator ("self"));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("self"), cself));
ccode.add_assignment (new CCodeIdentifier ("self"), cself);
}
// allow capturing generic type parameters
......@@ -411,15 +411,15 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
func_name = "%s_type".printf (type_param.name.down ());
ccode.add_declaration ("GType", new CCodeVariableDeclarator (func_name));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name)));
ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name));
func_name = "%s_dup_func".printf (type_param.name.down ());
ccode.add_declaration ("GBoxedCopyFunc", new CCodeVariableDeclarator (func_name));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name)));
ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name));
func_name = "%s_destroy_func".printf (type_param.name.down ());
ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (func_name));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name)));
ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name));
}
} else if (m.parent_symbol is Class && !m.coroutine) {
var cl = (Class) m.parent_symbol;
......@@ -437,7 +437,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
CCodeExpression cself = transform_expression (new CCodeIdentifier ("base"), base_expression_type, self_target_type);
ccode.add_declaration ("%s *".printf (cl.get_cname ()), new CCodeVariableDeclarator ("self"));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("self"), cself));
ccode.add_assignment (new CCodeIdentifier ("self"), cself);
} else if (m.binding == MemberBinding.INSTANCE
&& !(m is CreationMethod)) {
create_method_type_check_statement (m, creturn_type, cl, true, "self");
......@@ -502,7 +502,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
if (cl.is_fundamental ()) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_create_instance"));
ccall.add_argument (new CCodeIdentifier ("object_type"));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("self"), new CCodeCastExpression (ccall, cl.get_cname () + "*")));
ccode.add_assignment (new CCodeIdentifier ("self"), new CCodeCastExpression (ccall, cl.get_cname () + "*"));
/* type, dup func, and destroy func fields for generic types */
foreach (TypeParameter type_param in current_class.get_type_parameters ()) {
......@@ -532,7 +532,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
// TODO implicitly chain up to base class as in add_object_creation
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
ccall.add_argument (new CCodeIdentifier (cl.get_cname ()));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("self"), ccall));
ccode.add_assignment (new CCodeIdentifier ("self"), ccall);
}
if (cl.base_class == null) {
......@@ -945,7 +945,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
} else {
/* store method return value for postconditions */
ccode.add_declaration (get_creturn_type (m, return_type.get_cname ()), new CCodeVariableDeclarator ("result"));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("result"), vcall));
ccode.add_assignment (new CCodeIdentifier ("result"), vcall);
}
if (m.get_postconditions ().size > 0) {
......
......@@ -291,13 +291,13 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
array_copy_call.add_argument (size);
ccode.add_expression (array_copy_call);
} else {
ccode.add_expression (new CCodeAssignment (dest, copy));
ccode.add_assignment (dest, copy);
if (array_type != null) {
for (int dim = 1; dim <= array_type.rank; dim++) {
var len_src = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), get_array_length_cname (f.name, dim));
var len_dest = new CCodeMemberAccess.pointer (new CCodeIdentifier ("dest"), get_array_length_cname (f.name, dim));
ccode.add_expression (new CCodeAssignment (len_dest, len_src));
ccode.add_assignment (len_dest, len_src);
}
}
}
......
......@@ -23,7 +23,7 @@
public class Vala.DovaArrayModule : DovaMethodCallModule {
void append_initializer_list (CCodeExpression name_cnode, InitializerList initializer_list, ref int i) {
foreach (Expression e in initializer_list.get_initializers ()) {
ccode.add_expression (new CCodeAssignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), get_cvalue (e)));
ccode.add_assignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), get_cvalue (e));
i++;
}
}
......@@ -59,7 +59,7 @@ public class Vala.DovaArrayModule : DovaMethodCallModule {
emit_temp_var (temp_var);
ccode.add_expression (new CCodeAssignment (name_cnode, array_new));
ccode.add_assignment (name_cnode, array_new);
set_cvalue (expr, name_cnode);
}
......
......@@ -37,13 +37,13 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
string lhs_temp_name = "_tmp%d_".printf (next_temp_var_id++);
var lhs_temp = new LocalVariable (lhs_value_type, "*" + lhs_temp_name);
emit_temp_var (lhs_temp);
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs)));
ccode.add_assignment (get_variable_cexpression (lhs_temp_name), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs));
lhs = new CCodeParenthesizedExpression (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (lhs_temp_name)));
}
var temp_decl = get_temp_variable (assignment.left.value_type);
emit_temp_var (temp_decl);
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), rhs));
ccode.add_assignment (get_variable_cexpression (temp_decl.name), rhs);
if (unref_old) {
/* unref old value */
ccode.add_expression (get_unref_expression (lhs, assignment.left.value_type, assignment.left));
......@@ -138,7 +138,7 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
ccode.add_expression (destroy_value (lvalue));
}
ccode.add_expression (new CCodeAssignment (get_cvalue_ (lvalue), get_cvalue_ (value)));
ccode.add_assignment (get_cvalue_ (lvalue), get_cvalue_ (value));
}
public override void store_local (LocalVariable local, TargetValue value) {
......
......@@ -625,7 +625,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
param.captured = true;
}
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), get_variable_cname (param.name)), cparam));
ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), get_variable_cname (param.name)), cparam);
if (requires_destroy (param_type)) {
var ma = new MemberAccess.simple (param.name);
......@@ -864,7 +864,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
if (local.captured) {
if (local.initializer != null) {
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id ((Block) local.parent_symbol))), get_variable_cname (local.name)), rhs));
ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id ((Block) local.parent_symbol))), get_variable_cname (local.name)), rhs);
}
} else {
var cvar = new CCodeVariableDeclarator (get_variable_cname (local.name), rhs, local.variable_type.get_cdeclarator_suffix ());
......@@ -1356,7 +1356,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
// assign current value to temp variable
var temp_decl = get_temp_variable (prop.property_type, true, expr);
emit_temp_var (temp_decl);
ccode.add_expression (new CCodeAssignment (get_variable_cexpression (temp_decl.name), get_cvalue (expr.inner)));
ccode.add_assignment (get_variable_cexpression (temp_decl.name), get_cvalue (expr.inner));
// increment/decrement property
var op = expr.increment ? CCodeBinaryOperator.PLUS : CCodeBinaryOperator.MINUS;
......@@ -1661,7 +1661,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
if (expr.type_reference.data_type is Struct) {
ccode.add_expression (creation_expr);
} else {
ccode.add_expression (new CCodeAssignment (instance, creation_expr));
ccode.add_assignment (instance, creation_expr);
}
foreach (MemberInitializer init in expr.get_object_initializer ()) {
......@@ -1675,7 +1675,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
} else {
lhs = new CCodeMemberAccess.pointer (typed_inst, f.get_cname ());
}
ccode.add_expression (new CCodeAssignment (lhs, get_cvalue (init.initializer)));
ccode.add_assignment (lhs, get_cvalue (init.initializer));
} else if (init.symbol_reference is Property) {
var inst_ma = new MemberAccess.simple ("new");
inst_ma.value_type = expr.type_reference;
......@@ -1693,7 +1693,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
emit_temp_var (temp_var);
ccode.add_expression (new CCodeAssignment (temp_ref, creation_expr));
ccode.add_assignment (temp_ref, creation_expr);
set_cvalue (expr, temp_ref);
}
}
......
......@@ -27,7 +27,7 @@ public class Vala.DovaErrorModule : DovaDelegateModule {
private bool is_in_catch = false;
public override void visit_throw_statement (ThrowStatement stmt) {
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("dova_error"), get_cvalue (stmt.error_expression)));
ccode.add_assignment (new CCodeIdentifier ("dova_error"), get_cvalue (stmt.error_expression));
add_simple_check (stmt, true);
}
......
......@@ -226,7 +226,7 @@ public class Vala.DovaMethodCallModule : DovaAssignmentModule {
emit_temp_var (temp_var);
ccode.add_expression (new CCodeAssignment (temp_ref, ccall_expr));
ccode.add_assignment (temp_ref, ccall_expr);
set_cvalue (expr, temp_ref);
}
}
......
......@@ -1245,7 +1245,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
vcast = get_type_private_from_type ((ObjectTypeSymbol) prop.parent_symbol, new CCodeIdentifier ("type"));
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (vcast, "%s_%s".printf (acc.readable ? "get" : "set", prop.name)), new CCodeIdentifier ("function")));
ccode.add_assignment (new CCodeMemberAccess.pointer (vcast, "%s_%s".printf (acc.readable ? "get" : "set", prop.name)), new CCodeIdentifier ("function"));
pop_function ();
......@@ -1982,7 +1982,7 @@ public class Vala.DovaObjectModule : DovaArrayModule {
var lhs = new CCodeIdentifier (field.get_cname ());
var rhs = get_cvalue (field.initializer);
ccode.add_expression (new CCodeAssignment (lhs, rhs));
ccode.add_assignment (lhs, rhs);
}
}
}
......@@ -184,7 +184,7 @@ public class Vala.GAsyncModule : GSignalModule {
var self_target_type = new ObjectType (type_symbol);
var cself = transform_expression (new CCodeIdentifier ("base"), base_expression_type, self_target_type);
ccode.add_declaration ("%s *".printf (type_symbol.get_cname ()), new CCodeVariableDeclarator ("self"));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("self"), cself));
ccode.add_assignment (new CCodeIdentifier ("self"), cself);
}
var dataalloc = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
......@@ -193,7 +193,7 @@ public class Vala.GAsyncModule : GSignalModule {
var data_var = new CCodeIdentifier ("_data_");
ccode.add_declaration (dataname + "*", new CCodeVariableDeclarator ("_data_"));
ccode.add_expression (new CCodeAssignment (data_var, dataalloc));
ccode.add_assignment (data_var, dataalloc);
var create_result = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_new"));
......@@ -221,7 +221,7 @@ public class Vala.GAsyncModule : GSignalModule {
create_result.add_argument (new CCodeIdentifier ("_user_data_"));
create_result.add_argument (new CCodeIdentifier (m.get_real_cname ()));
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, "_async_result"), create_result));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "_async_result"), create_result);
var set_op_res_call = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_set_op_res_gpointer"));
set_op_res_call.add_argument (new CCodeMemberAccess.pointer (data_var, "_async_result"));
......@@ -246,7 +246,7 @@ public class Vala.GAsyncModule : GSignalModule {
cself = get_ref_cexpression (m.this_parameter.variable_type, cself, ma, m.this_parameter);
}
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, "self"), cself));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "self"), cself);
}
foreach (Parameter param in m.get_parameters ()) {
......@@ -267,20 +267,20 @@ public class Vala.GAsyncModule : GSignalModule {
cparam = get_ref_cexpression (param.variable_type, cparam, ma, param);
}
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), cparam));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), cparam);
if (param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
if (!param.no_array_length) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, get_parameter_array_length_cname (param, dim)), new CCodeIdentifier (get_parameter_array_length_cname (param, dim))));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_parameter_array_length_cname (param, dim)), new CCodeIdentifier (get_parameter_array_length_cname (param, dim)));
}
}
} else if (param.variable_type is DelegateType) {
var deleg_type = (DelegateType) param.variable_type;
if (deleg_type.delegate_symbol.has_target) {
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, get_delegate_target_cname (get_variable_cname (param.name))), new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (param.name)))));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_delegate_target_cname (get_variable_cname (param.name))), new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (param.name))));
if (deleg_type.value_owned) {
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, get_delegate_target_destroy_notify_cname (get_variable_cname (param.name))), new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)))));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_delegate_target_destroy_notify_cname (get_variable_cname (param.name))), new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name))));
}
}
}
......@@ -437,13 +437,13 @@ public class Vala.GAsyncModule : GSignalModule {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_get_op_res_gpointer"));
ccall.add_argument (simple_async_result_cast);
ccode.add_expression (new CCodeAssignment (data_var, ccall));
ccode.add_assignment (data_var, ccall);
foreach (Parameter param in m.get_parameters ()) {
if (param.direction != ParameterDirection.IN) {
ccode.add_expression (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name))));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)));
if (!(param.variable_type is ValueType) || param.variable_type.nullable) {
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), new CCodeConstant ("NULL")));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), new CCodeConstant ("NULL"));
}
}
}
......@@ -454,21 +454,21 @@ public class Vala.GAsyncModule : GSignalModule {
if (requires_copy (return_type)) {
cexpr = get_ref_cexpression (return_type, cexpr, null, return_type);
}
ccode.add_expression (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), cexpr));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), cexpr);
} else if (!(return_type is VoidType)) {
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("result"), new CCodeMemberAccess.pointer (data_var, "result")));
ccode.add_assignment (new CCodeIdentifier ("result"), new CCodeMemberAccess.pointer (data_var, "result"));
if (return_type is ArrayType) {
var array_type = (ArrayType) return_type;
if (!m.no_array_length) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.add_expression (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_array_length_cname ("result", dim))), new CCodeMemberAccess.pointer (data_var, get_array_length_cname ("result", dim))));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_array_length_cname ("result", dim))), new CCodeMemberAccess.pointer (data_var, get_array_length_cname ("result", dim)));
}
}
} else if (return_type is DelegateType && ((DelegateType) return_type).delegate_symbol.has_target) {
ccode.add_expression (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_delegate_target_cname ("result"))), new CCodeMemberAccess.pointer (data_var, get_delegate_target_cname ("result"))));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_delegate_target_cname ("result"))), new CCodeMemberAccess.pointer (data_var, get_delegate_target_cname ("result")));
}
if (!(return_type is ValueType) || return_type.nullable) {
ccode.add_expression (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, "result"), new CCodeConstant ("NULL")));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "result"), new CCodeConstant ("NULL"));
}
ccode.add_return (new CCodeIdentifier ("result"));
}
......@@ -563,7 +563,7 @@ public class Vala.GAsyncModule : GSignalModule {
if (stmt.yield_expression == null) {
int state = next_coroutine_state++;