Commit 9a9a65b0 authored by Luca Bruno's avatar Luca Bruno

ccodegen: Port the remaining code to use the ccode builder

parent f93687de
......@@ -1824,19 +1824,22 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var ref_fun = new CCodeFunction ("block%d_data_ref".printf (block_id), struct_name + "*");
ref_fun.add_parameter (new CCodeParameter ("_data%d_".printf (block_id), struct_name + "*"));
ref_fun.modifiers = CCodeModifiers.STATIC;
cfile.add_function_declaration (ref_fun);
ref_fun.block = new CCodeBlock ();
push_function (ref_fun);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_atomic_int_inc"));
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data%d_".printf (block_id)), "_ref_count_")));
ref_fun.block.add_statement (new CCodeExpressionStatement (ccall));
ref_fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("_data%d_".printf (block_id))));
ccode.add_expression (ccall);
ccode.add_return (new CCodeIdentifier ("_data%d_".printf (block_id)));
pop_function ();
cfile.add_function_declaration (ref_fun);
cfile.add_function (ref_fun);
var unref_fun = new CCodeFunction ("block%d_data_unref".printf (block_id), "void");
unref_fun.add_parameter (new CCodeParameter ("_data%d_".printf (block_id), struct_name + "*"));
unref_fun.modifiers = CCodeModifiers.STATIC;
cfile.add_function_declaration (unref_fun);
push_function (unref_fun);
......@@ -1929,6 +1932,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
pop_function ();
cfile.add_function_declaration (unref_fun);
cfile.add_function (unref_fun);
}
......@@ -2748,13 +2752,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
wrapper.modifiers = CCodeModifiers.STATIC;
wrapper.add_parameter (new CCodeParameter ("node", collection_type.get_cname ()));
wrapper.add_parameter (new CCodeParameter ("unused", "gpointer"));
var wrapper_block = new CCodeBlock ();
push_function (wrapper);
var free_call = new CCodeFunctionCall (element_destroy_func_expression);
free_call.add_argument (new CCodeMemberAccess.pointer(new CCodeIdentifier("node"), "data"));
wrapper_block.add_statement (new CCodeExpressionStatement (free_call));
wrapper_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
ccode.add_expression (free_call);
ccode.add_return (new CCodeConstant ("FALSE"));
pop_function ();
cfile.add_function_declaration (function);
wrapper.block = wrapper_block;
cfile.add_function (wrapper);
/* Now the code to call g_traverse with the above */
......
......@@ -205,6 +205,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var function = new CCodeFunction (wrapper_name, return_type_cname);
function.modifiers = CCodeModifiers.STATIC;
push_function (function);
var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
if (d.has_target) {
......@@ -400,13 +402,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
ccall.add_argument (new CCodeConstant ("NULL"));
ccall.add_argument (new CCodeConstant ("NULL"));
}
var block = new CCodeBlock ();
if (m.return_type is VoidType || m.return_type.is_real_non_null_struct_type ()) {
block.add_statement (new CCodeExpressionStatement (ccall));
ccode.add_expression (ccall);
} else {
var cdecl = new CCodeDeclaration (return_type_cname);
cdecl.add_declarator (new CCodeVariableDeclarator ("result", ccall));
block.add_statement (cdecl);
ccode.add_declaration (return_type_cname, new CCodeVariableDeclarator ("result", ccall));
}
if (d.has_target && !dt.value_owned && dt.is_called_once && expr != null) {
......@@ -434,19 +433,18 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (destroy_notify != null) {
var unref_call = new CCodeFunctionCall (destroy_notify);
unref_call.add_argument (new CCodeIdentifier ("self"));
block.add_statement (new CCodeExpressionStatement (unref_call));
ccode.add_expression (unref_call);
}
}
if (!(m.return_type is VoidType || m.return_type.is_real_non_null_struct_type ())) {
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
ccode.add_return (new CCodeIdentifier ("result"));
}
// append to file
pop_function ();
// append to file
cfile.add_function_declaration (function);
function.block = block;
cfile.add_function (function);
return wrapper_name;
......
......@@ -614,12 +614,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
&& current_class.get_type_parameters ().size > 0
&& !((CreationMethod) m).chain_up) {
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"))));
ccode.open_while (ccond);
ccode.add_expression (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));
ccode.add_statement (new CCodeWhileStatement (ccond, cdofreeparam));
ccode.add_expression (cunsetcall);
ccode.close ();
var cfreeparams = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
cfreeparams.add_argument (new CCodeIdentifier ("__params"));
......@@ -692,26 +692,24 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
cmain.line = function.line;
cmain.add_parameter (new CCodeParameter ("argc", "int"));
cmain.add_parameter (new CCodeParameter ("argv", "char **"));
var main_block = new CCodeBlock ();
push_function (cmain);
if (context.profile == Profile.GOBJECT) {
if (context.mem_profiler) {
var mem_profiler_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_mem_set_vtable"));
mem_profiler_init_call.line = cmain.line;
mem_profiler_init_call.add_argument (new CCodeConstant ("glib_mem_profiler_table"));
main_block.add_statement (new CCodeExpressionStatement (mem_profiler_init_call));
ccode.add_expression (mem_profiler_init_call);
}
if (context.thread) {
var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init"));
thread_init_call.line = cmain.line;
thread_init_call.add_argument (new CCodeConstant ("NULL"));
main_block.add_statement (new CCodeExpressionStatement (thread_init_call));
ccode.add_expression (thread_init_call);
}
var type_init_call = new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
type_init_call.line = cmain.line;
main_block.add_statement (type_init_call);
ccode.add_expression (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
}
var main_call = new CCodeFunctionCall (new CCodeIdentifier (function.name));
......@@ -721,18 +719,12 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
if (m.return_type is VoidType) {
// method returns void, always use 0 as exit code
var main_stmt = new CCodeExpressionStatement (main_call);
main_stmt.line = cmain.line;
main_block.add_statement (main_stmt);
var ret_stmt = new CCodeReturnStatement (new CCodeConstant ("0"));
ret_stmt.line = cmain.line;
main_block.add_statement (ret_stmt);
ccode.add_expression (main_call);
ccode.add_return (new CCodeConstant ("0"));
} else {
var main_stmt = new CCodeReturnStatement (main_call);
main_stmt.line = cmain.line;
main_block.add_statement (main_stmt);
ccode.add_return (main_call);
}
cmain.block = main_block;
pop_function ();
cfile.add_function (cmain);
}
}
......@@ -1028,21 +1020,19 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
var vblock = new CCodeBlock ();
push_function (vfunc);
var vcall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname ()));
vcall.add_argument (new CCodeIdentifier (current_class.get_type_id ()));
generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall);
CCodeStatement cstmt = new CCodeReturnStatement (vcall);
cstmt.line = vfunc.line;
vblock.add_statement (cstmt);
ccode.add_return (vcall);
if (!visible) {
vfunc.modifiers |= CCodeModifiers.STATIC;
}
vfunc.block = vblock;
pop_function ();
cfile.add_function (vfunc);
}
......
......@@ -185,22 +185,20 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
function.add_parameter (new CCodeParameter ("self", "const " + st.get_cname () + "*"));
var cblock = new CCodeBlock ();
push_function (function);
var cdecl = new CCodeDeclaration (st.get_cname () + "*");
cdecl.add_declarator (new CCodeVariableDeclarator ("dup"));
cblock.add_statement (cdecl);
ccode.add_declaration (st.get_cname () + "*", new CCodeVariableDeclarator ("dup"));
var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
creation_call.add_argument (new CCodeConstant (st.get_cname ()));
creation_call.add_argument (new CCodeConstant ("1"));
cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("dup"), creation_call)));
ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
if (st.is_disposable ()) {
var copy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_copy_function ()));
copy_call.add_argument (new CCodeIdentifier ("self"));
copy_call.add_argument (new CCodeIdentifier ("dup"));
cblock.add_statement (new CCodeExpressionStatement (copy_call));
ccode.add_expression (copy_call);
} else {
cfile.add_include ("string.h");
......@@ -211,12 +209,12 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
copy_call.add_argument (new CCodeIdentifier ("dup"));
copy_call.add_argument (new CCodeIdentifier ("self"));
copy_call.add_argument (sizeof_call);
cblock.add_statement (new CCodeExpressionStatement (copy_call));
ccode.add_expression (copy_call);
}
cblock.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("dup")));
ccode.add_return (new CCodeIdentifier ("dup"));
function.block = cblock;
pop_function ();
cfile.add_function (function);
}
......@@ -229,19 +227,19 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
function.add_parameter (new CCodeParameter ("self", st.get_cname () + "*"));
var cblock = new CCodeBlock ();
push_function (function);
if (st.is_disposable ()) {
var destroy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_destroy_function ()));
destroy_call.add_argument (new CCodeIdentifier ("self"));
cblock.add_statement (new CCodeExpressionStatement (destroy_call));
ccode.add_expression (destroy_call);
}
var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
free_call.add_argument (new CCodeIdentifier ("self"));
cblock.add_statement (new CCodeExpressionStatement (free_call));
ccode.add_expression (free_call);
function.block = cblock;
pop_function ();
cfile.add_function (function);
}
......
......@@ -488,22 +488,20 @@ public class Vala.GAsyncModule : GSignalModule {
readyfunc.add_parameter (new CCodeParameter ("_res_", "GAsyncResult*"));
readyfunc.add_parameter (new CCodeParameter ("_user_data_", "gpointer"));
var readyblock = new CCodeBlock ();
push_function (readyfunc);
var datadecl = new CCodeDeclaration (dataname + "*");
datadecl.add_declarator (new CCodeVariableDeclarator ("data"));
readyblock.add_statement (datadecl);
readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("data"), new CCodeIdentifier ("_user_data_"))));
readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_source_object_"), new CCodeIdentifier ("source_object"))));
readyblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_res_"), new CCodeIdentifier ("_res_"))));
ccode.add_declaration (dataname + "*", new CCodeVariableDeclarator ("data"));
ccode.add_assignment (new CCodeIdentifier ("data"), new CCodeIdentifier ("_user_data_"));
ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_source_object_"), new CCodeIdentifier ("source_object"));
ccode.add_assignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "_res_"), new CCodeIdentifier ("_res_"));
var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_real_cname () + "_co"));
ccall.add_argument (new CCodeIdentifier ("data"));
readyblock.add_statement (new CCodeExpressionStatement (ccall));
ccode.add_expression (ccall);
readyfunc.modifiers |= CCodeModifiers.STATIC;
readyfunc.block = readyblock;
pop_function ();
cfile.add_function_declaration (readyfunc);
cfile.add_function (readyfunc);
......
......@@ -79,7 +79,7 @@ public class Vala.GDBusClientModule : GDBusModule {
var proxy_iface_init = new CCodeFunction (lower_cname + "_" + iface.get_lower_case_cprefix () + "interface_init", "void");
proxy_iface_init.add_parameter (new CCodeParameter ("iface", iface.get_cname () + "Iface*"));
var iface_block = new CCodeBlock ();
push_function (proxy_iface_init);
foreach (Method m in iface.get_methods ()) {
if (!m.is_abstract) {
......@@ -88,11 +88,11 @@ public class Vala.GDBusClientModule : GDBusModule {
var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), m.vfunc_name);
if (!m.coroutine) {
iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_method (main_iface, iface, m)))));
ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_method (main_iface, iface, m)));
} else {
iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_async_dbus_proxy_method (main_iface, iface, m)))));
ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_async_dbus_proxy_method (main_iface, iface, m)));
vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), m.get_finish_vfunc_name ());
iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_finish_dbus_proxy_method (main_iface, iface, m)))));
ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_finish_dbus_proxy_method (main_iface, iface, m)));
}
}
......@@ -103,17 +103,17 @@ public class Vala.GDBusClientModule : GDBusModule {
if (prop.get_accessor != null) {
var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), "get_" + prop.name);
iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_get (main_iface, iface, prop)))));
ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_get (main_iface, iface, prop)));
}
if (prop.set_accessor != null) {
var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), "set_" + prop.name);
iface_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_set (main_iface, iface, prop)))));
ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_set (main_iface, iface, prop)));
}
}
proxy_iface_init.modifiers = CCodeModifiers.STATIC;
pop_function ();
cfile.add_function_declaration (proxy_iface_init);
proxy_iface_init.block = iface_block;
cfile.add_function (proxy_iface_init);
}
......@@ -187,10 +187,11 @@ public class Vala.GDBusClientModule : GDBusModule {
var proxy_class_init = new CCodeFunction (lower_cname + "_class_init", "void");
proxy_class_init.add_parameter (new CCodeParameter ("klass", cname + "Class*"));
proxy_class_init.modifiers = CCodeModifiers.STATIC;
proxy_class_init.block = new CCodeBlock ();
push_function (proxy_class_init);
var proxy_class = new CCodeFunctionCall (new CCodeIdentifier ("G_DBUS_PROXY_CLASS"));
proxy_class.add_argument (new CCodeIdentifier ("klass"));
proxy_class_init.block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (proxy_class, "g_signal"), new CCodeIdentifier (lower_cname + "_g_signal"))));
ccode.add_assignment (new CCodeMemberAccess.pointer (proxy_class, "g_signal"), new CCodeIdentifier (lower_cname + "_g_signal"));
pop_function ();
cfile.add_function (proxy_class_init);
generate_signal_handler_function (iface);
......@@ -198,7 +199,6 @@ public class Vala.GDBusClientModule : GDBusModule {
var proxy_instance_init = new CCodeFunction (lower_cname + "_init", "void");
proxy_instance_init.add_parameter (new CCodeParameter ("self", cname + "*"));
proxy_instance_init.modifiers = CCodeModifiers.STATIC;
proxy_instance_init.block = new CCodeBlock ();
cfile.add_function (proxy_instance_init);
generate_proxy_interface_init (iface, iface);
......@@ -427,10 +427,9 @@ public class Vala.GDBusClientModule : GDBusModule {
cfile.add_function_declaration (cfunc);
var block = new CCodeBlock ();
cfunc.block = block;
push_function (cfunc);
CCodeIfStatement clastif = null;
bool firstif = true;
foreach (Signal sig in sym.get_signals ()) {
if (sig.access != SymbolAccessibility.PUBLIC) {
......@@ -443,24 +442,24 @@ public class Vala.GDBusClientModule : GDBusModule {
ccheck.add_argument (new CCodeIdentifier ("signal_name"));
ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (sig))));
var callblock = new CCodeBlock ();
if (!firstif) {
ccode.add_else ();
}
ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
firstif = false;
var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_signal_handler (sig, sym)));
ccall.add_argument (new CCodeCastExpression (new CCodeIdentifier ("proxy"), sym.get_cname () + "*"));
ccall.add_argument (new CCodeIdentifier ("parameters"));
callblock.add_statement (new CCodeExpressionStatement (ccall));
var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
if (clastif == null) {
block.add_statement (cif);
} else {
clastif.false_statement = cif;
}
clastif = cif;
ccode.add_expression (ccall);
}
if (!firstif) {
ccode.close ();
}
pop_function ();
cfile.add_function (cfunc);
}
......
......@@ -87,14 +87,11 @@ public class Vala.GDBusModule : GVariantModule {
string quark_fun_name = edomain.get_lower_case_cprefix () + "quark";
var cquark_fun = new CCodeFunction (quark_fun_name, gquark_type.data_type.get_cname ());
var cquark_block = new CCodeBlock ();
push_function (cquark_fun);
string quark_name = "%squark_volatile".printf (edomain.get_lower_case_cprefix ());
cdecl = new CCodeDeclaration ("gsize");
cdecl.add_declarator (new CCodeVariableDeclarator (quark_name, new CCodeConstant ("0")));
cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
cquark_block.add_statement (cdecl);
ccode.add_declaration ("gsize", new CCodeVariableDeclarator (quark_name, new CCodeConstant ("0")), CCodeModifiers.STATIC | CCodeModifiers.VOLATILE);
var register_call = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_error_register_error_domain"));
register_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
......@@ -103,11 +100,11 @@ public class Vala.GDBusModule : GVariantModule {
var nentries = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
nentries.add_argument (new CCodeIdentifier (edomain.get_lower_case_cname () + "_entries"));
register_call.add_argument (nentries);
cquark_block.add_statement (new CCodeExpressionStatement (register_call));
ccode.add_expression (register_call);
cquark_block.add_statement (new CCodeReturnStatement (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark")));
ccode.add_return (new CCodeCastExpression (new CCodeIdentifier (quark_name), "GQuark"));
cquark_fun.block = cquark_block;
pop_function ();
cfile.add_function (cquark_fun);
}
......
......@@ -589,7 +589,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
return wrapper_name;
}
void handle_signals (ObjectTypeSymbol sym, CCodeBlock block) {
void handle_signals (ObjectTypeSymbol sym) {
string dbus_iface_name = get_dbus_name (sym);
if (dbus_iface_name == null) {
return;
......@@ -608,7 +608,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
connect.add_argument (sig.get_canonical_cconstant ());
connect.add_argument (new CCodeCastExpression (new CCodeIdentifier (generate_dbus_signal_wrapper (sig, sym, dbus_iface_name)), "GCallback"));
connect.add_argument (new CCodeIdentifier ("data"));
block.add_statement (new CCodeExpressionStatement (connect));
ccode.add_expression (connect);
}
}
......@@ -693,18 +693,13 @@ public class Vala.GDBusServerModule : GDBusClientModule {
cfile.add_function_declaration (cfunc);
var block = new CCodeBlock ();
cfunc.block = block;
push_function (cfunc);
var cdecl = new CCodeDeclaration ("gpointer*");
cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
block.add_statement (cdecl);
ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
cdecl = new CCodeDeclaration ("gpointer");
cdecl.add_declarator (new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
block.add_statement (cdecl);
ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
CCodeIfStatement clastif = null;
bool firstif = true;
foreach (Property prop in sym.get_properties ()) {
if (prop.binding != MemberBinding.INSTANCE
......@@ -724,25 +719,24 @@ public class Vala.GDBusServerModule : GDBusClientModule {
ccheck.add_argument (new CCodeIdentifier ("property_name"));
ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (prop))));
var callblock = new CCodeBlock ();
if (!firstif) {
ccode.add_else ();
}
ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
firstif = false;
var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_property_get_wrapper (prop, sym)));
ccall.add_argument (new CCodeIdentifier ("object"));
callblock.add_statement (new CCodeReturnStatement (ccall));
var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
if (clastif == null) {
block.add_statement (cif);
} else {
clastif.false_statement = cif;
}
clastif = cif;
ccode.add_return (ccall);
}
if (!firstif) {
ccode.close ();
}
block.add_statement (new CCodeReturnStatement (new CCodeConstant ("NULL")));
ccode.add_return (new CCodeConstant ("NULL"));
pop_function ();
cfile.add_function (cfunc);
}
......@@ -761,18 +755,13 @@ public class Vala.GDBusServerModule : GDBusClientModule {
cfile.add_function_declaration (cfunc);
var block = new CCodeBlock ();
cfunc.block = block;
push_function (cfunc);
var cdecl = new CCodeDeclaration ("gpointer*");
cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
block.add_statement (cdecl);
ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
cdecl = new CCodeDeclaration ("gpointer");
cdecl.add_declarator (new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
block.add_statement (cdecl);
ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("object", new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0"))));
CCodeIfStatement clastif = null;
bool firstif = true;
foreach (Property prop in sym.get_properties ()) {
if (prop.binding != MemberBinding.INSTANCE
......@@ -792,27 +781,25 @@ public class Vala.GDBusServerModule : GDBusClientModule {
ccheck.add_argument (new CCodeIdentifier ("property_name"));
ccheck.add_argument (new CCodeConstant ("\"%s\"".printf (get_dbus_name_for_member (prop))));
var callblock = new CCodeBlock ();
if (!firstif) {
ccode.add_else ();
}
ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")));
firstif = false;
var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_dbus_property_set_wrapper (prop, sym)));
ccall.add_argument (new CCodeIdentifier ("object"));
ccall.add_argument (new CCodeIdentifier ("value"));
callblock.add_statement (new CCodeExpressionStatement (ccall));
callblock.add_statement (new CCodeReturnStatement (new CCodeConstant ("TRUE")));
var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccheck, new CCodeConstant ("0")), callblock);
if (clastif == null) {
block.add_statement (cif);
} else {
clastif.false_statement = cif;
}
clastif = cif;
ccode.add_expression (ccall);
ccode.add_return (new CCodeConstant ("TRUE"));
}
if (!firstif) {
ccode.close ();
}
ccode.add_return (new CCodeConstant ("FALSE"));
block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
pop_function ();
cfile.add_function (cfunc);
}
......@@ -1221,35 +1208,30 @@ public class Vala.GDBusServerModule : GDBusClientModule {
cfunc.modifiers |= CCodeModifiers.STATIC;
}
var block = new CCodeBlock ();
cfunc.block = block;
push_function (cfunc);
var cdecl = new CCodeDeclaration ("guint");
cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
block.add_statement (cdecl);
ccode.add_declaration ("guint", new CCodeVariableDeclarator ("result"));
// data consists of 3 pointers: object, connection, path
cdecl = new CCodeDeclaration ("gpointer");
cdecl.add_declarator (new CCodeVariableDeclarator ("*data"));
block.add_statement (cdecl);
ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("*data"));
var alloc_data = new CCodeFunctionCall (new CCodeIdentifier ("g_new"));
alloc_data.add_argument (new CCodeIdentifier ("gpointer"));
alloc_data.add_argument (new CCodeConstant ("3"));
block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("data"), alloc_data)));
ccode.add_assignment (new CCodeIdentifier ("data"), alloc_data);
var ref_object = new CCodeFunctionCall (new CCodeIdentifier (sym.get_ref_function ()));
ref_object.add_argument (new CCodeIdentifier ("object"));
block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")), ref_object)));
ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")), ref_object);
ref_object = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
ref_object.add_argument (new CCodeIdentifier ("connection"));
block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("1")), ref_object)));
ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("1")), ref_object);
var dup_path = new CCodeFunctionCall (new CCodeIdentifier ("g_strdup"));
dup_path.add_argument (new CCodeIdentifier ("path"));
block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("2")), dup_path)));
ccode.add_assignment (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("2")), dup_path);
var cregister = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_connection_register_object"));
......@@ -1263,47 +1245,46 @@ public class Vala.GDBusServerModule : GDBusClientModule {
cregister.add_argument (new CCodeIdentifier ("_" + sym.get_lower_case_cprefix () + "unregister_object"));
cregister.add_argument (new CCodeIdentifier ("error"));
block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("result"), cregister)));
ccode.add_assignment (new CCodeIdentifier ("result"), cregister);
var error_block = new CCodeBlock ();
error_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("0")));
block.add_statement (new CCodeIfStatement (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("result")), error_block));
ccode.open_if (new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, new CCodeIdentifier ("result")));
ccode.add_return (new CCodeConstant ("0"));
ccode.close ();
handle_signals (sym, block);
handle_signals (sym);
block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
ccode.add_return (new CCodeIdentifier ("result"));
pop_function ();
cfile.add_function (cfunc);
cfunc = new CCodeFunction ("_" + sym.get_lower_case_cprefix () + "unregister_object");
cfunc.add_parameter (new CCodeParameter ("user_data", "gpointer"));
cfunc.modifiers |= CCodeModifiers.STATIC;
cfile.add_function_declaration (cfunc);
block = new CCodeBlock ();
cfunc.block = block;
push_function (cfunc);
cdecl = new CCodeDeclaration ("gpointer*");
cdecl.add_declarator (new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
block.add_statement (cdecl);
ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
var unref_object = new CCodeFunctionCall (new CCodeIdentifier (sym.get_unref_function ()));
unref_object.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")));
block.add_statement (new CCodeExpressionStatement (unref_object));
ccode.add_expression (unref_object);
unref_object = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
unref_object.add_argument (new CCode