cfile.add_function (fun);
}
- public override CCodeExpression? copy_value (TargetValue value, Expression? expr, CodeNode node) {
+ public override TargetValue? copy_value (TargetValue value, Expression? expr, CodeNode node) {
var type = value.value_type;
var cexpr = get_cvalue_ (value);
ccomma.append_expression (copy_call);
ccomma.append_expression (ctemp);
- return ccomma;
+ return new GLibValue (type, ccomma);
} else {
return base.copy_value (value, expr, node);
}
new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")),
new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
- ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), copy_value (new GLibValue (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_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), null, array_type)));
ccode.close ();
ccode.add_return (new CCodeIdentifier ("result"));
new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
- ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), copy_value (new GLibValue (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_cvalue_ (copy_value (new GLibValue (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i"))), null, array_type)));
} else {
cfile.add_include ("string.h");
value.delegate_target_cvalue = get_delegate_target_cvalue (expr.target_value);
value.delegate_target_destroy_notify_cvalue = get_delegate_target_destroy_notify_cvalue (expr.target_value);
}
- return copy_value (value, expr, node);
+ var result = copy_value (value, expr, node);
+ return get_cvalue_ (result);
}
- public virtual CCodeExpression? copy_value (TargetValue value, Expression? expr, CodeNode node) {
+ public virtual TargetValue? copy_value (TargetValue value, Expression? expr, CodeNode node) {
var type = value.value_type;
var cexpr = get_cvalue_ (value);
if (type is DelegateType) {
- return cexpr;
+ var result = ((GLibValue) value).copy ();
+ result.delegate_target_destroy_notify_cvalue = new CCodeConstant ("NULL");
+ return result;
}
if (type is ValueType && !type.nullable) {
ccode.add_else ();
// g_value_init/copy must not be called for uninitialized values
- ccode.add_assignment (ctemp, cexpr);
+ store_local (decl, value, true);
ccode.close ();
} else {
ccode.add_expression (copy_call);
}
- return ctemp;
+ return get_local_cvalue (decl);
}
/* (temp = expr, temp == NULL ? NULL : ref (temp))
var ccall = new CCodeFunctionCall (new CCodeIdentifier (dup0_func));
ccall.add_argument (cexpr);
- return ccall;
+ return new GLibValue (type, ccall);
}
var ccall = new CCodeFunctionCall (dupexpr);
// expression is non-null
ccall.add_argument (get_cvalue (expr));
- return ccall;
+ return new GLibValue (type, ccall);
} else {
var decl = get_temp_variable (type, false, node, false);
emit_temp_var (decl);
ccomma.append_expression (ctemp);
}
- return ccomma;
+ return new GLibValue (type, ccomma);
}
}
CCodeExpression element_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_item);
if (stmt.type_reference.value_owned) {
- element_expr = copy_value (new GLibValue (stmt.type_reference, element_expr), null, new StructValueType (gvalue_type));
+ element_expr = get_cvalue_ (copy_value (new GLibValue (stmt.type_reference, element_expr), null, new StructValueType (gvalue_type)));
}
visit_local_variable (stmt.element_variable);
// structs are returned via out parameter
CCodeExpression cexpr = new CCodeMemberAccess.pointer (data_var, "result");
if (requires_copy (return_type)) {
- cexpr = copy_value (new GLibValue (return_type, cexpr), null, return_type);
+ cexpr = get_cvalue_ (copy_value (new GLibValue (return_type, cexpr), null, return_type));
}
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("result")), cexpr);
} else if (!(return_type is VoidType)) {