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

free construction parameters in creation methods

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

	* gobject/valacodegenerator.vala, gobject/valacodegeneratormethod.vala:
	  free construction parameters in creation methods

svn path=/trunk/; revision=399
parent 18eadfcb
2007-07-27 Jürg Billeter <j@bitron.ch>
* gobject/valacodegenerator.vala, gobject/valacodegeneratormethod.vala:
free construction parameters in creation methods
2007-07-27 Jürg Billeter <j@bitron.ch>
* vala/valadostatement.vala, vala/valaforeachstatement.vala,
......
......@@ -678,28 +678,6 @@ public class Vala.CodeGenerator : CodeVisitor {
current_symbol = b;
}
private void add_object_creation (CCodeBlock! b, bool has_params) {
var cl = (Class) current_type_symbol;
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
ccall.add_argument (new CCodeConstant (cl.get_type_id ()));
if (has_params) {
ccall.add_argument (new CCodeConstant ("__params_it - __params"));
ccall.add_argument (new CCodeConstant ("__params"));
} else {
ccall.add_argument (new CCodeConstant ("0"));
ccall.add_argument (new CCodeConstant ("NULL"));
}
var cdecl = new CCodeVariableDeclarator ("self");
cdecl.initializer = ccall;
var cdeclaration = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
cdeclaration.add_declarator (cdecl);
b.add_statement (cdeclaration);
}
public override void visit_end_block (Block! b) {
var local_vars = b.get_local_variables ();
foreach (VariableDeclarator decl in local_vars) {
......
......@@ -360,6 +360,20 @@ public class Vala.CodeGenerator {
}
if (m is CreationMethod) {
if (((CreationMethod) m).n_construction_params > 0) {
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN, new CCodeIdentifier ("__params_it"), new CCodeIdentifier ("__params"));
var cdofreeparam = new CCodeBlock ();
cdofreeparam.add_statement (new CCodeExpressionStatement (new CCodeUnaryExpression (CCodeUnaryOperator.PREFIX_DECREMENT, new CCodeIdentifier ("__params_it"))));
var cunsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_unset"));
cunsetcall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("__params_it"), "value")));
cdofreeparam.add_statement (new CCodeExpressionStatement (cunsetcall));
function.block.add_statement (new CCodeWhileStatement (ccond, cdofreeparam));
var cfreeparams = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
cfreeparams.add_argument (new CCodeIdentifier ("__params"));
function.block.add_statement (new CCodeExpressionStatement (cfreeparams));
}
var creturn = new CCodeReturnStatement ();
creturn.return_expression = new CCodeIdentifier ("self");
function.block.add_statement (creturn);
......@@ -529,5 +543,27 @@ public class Vala.CodeGenerator {
args_parameter = true;
return true;
}
private void add_object_creation (CCodeBlock! b, bool has_params) {
var cl = (Class) current_type_symbol;
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
ccall.add_argument (new CCodeConstant (cl.get_type_id ()));
if (has_params) {
ccall.add_argument (new CCodeConstant ("__params_it - __params"));
ccall.add_argument (new CCodeConstant ("__params"));
} else {
ccall.add_argument (new CCodeConstant ("0"));
ccall.add_argument (new CCodeConstant ("NULL"));
}
var cdecl = new CCodeVariableDeclarator ("self");
cdecl.initializer = ccall;
var cdeclaration = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
cdeclaration.add_declarator (cdecl);
b.add_statement (cdeclaration);
}
}
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