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);
pop_function ();
+ cfile.add_function_declaration (unref_fun);
cfile.add_function (unref_fun);
}
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 */
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) {
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) {
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;
&& 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"));
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));
}
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);
}
}
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);
}
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");
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);
}
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);
}
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);
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) {
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)));
}
}
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);
}
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);
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);
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) {
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);
}
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\""));
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);
}
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;
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);
}
}
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
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);
}
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
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);
}
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"));
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 CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("1")));
- block.add_statement (new CCodeExpressionStatement (unref_object));
+ ccode.add_expression (unref_object);
var free_path = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
free_path.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("2")));
- block.add_statement (new CCodeExpressionStatement (free_path));
+ ccode.add_expression (free_path);
var free_data = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
free_data.add_argument (new CCodeIdentifier ("data"));
- block.add_statement (new CCodeExpressionStatement (free_data));
+ ccode.add_expression (free_data);
+ pop_function ();
+ cfile.add_function_declaration (cfunc);
cfile.add_function (cfunc);
}
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);
var cquark_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
cquark_call.add_argument (new CCodeConstant ("\"" + edomain.get_lower_case_cname () + "-quark\""));
- cquark_block.add_statement (new CCodeReturnStatement (cquark_call));
+ ccode.add_return (cquark_call);
- cquark_fun.block = cquark_block;
+ pop_function ();
cfile.add_function (cquark_fun);
}
ccode.add_break ();
}
ccode.add_default ();
- ccode.add_statement (get_invalid_property_id_warn_statement ());
+ emit_invalid_property_id_warn ();
ccode.add_break ();
ccode.close ();
set_prop.add_parameter (new CCodeParameter ("property_id", "guint"));
set_prop.add_parameter (new CCodeParameter ("value", "const GValue *"));
set_prop.add_parameter (new CCodeParameter ("pspec", "GParamSpec *"));
-
- var block = new CCodeBlock ();
+
+ push_function (set_prop);
CCodeFunctionCall ccall = generate_instance_cast (new CCodeIdentifier ("object"), cl);
- var cdecl = new CCodeDeclaration ("%s *".printf (cl.get_cname ()));
- cdecl.add_declarator (new CCodeVariableDeclarator ("self", ccall));
- block.add_statement (cdecl);
-
- var boxed_declared = false;
+ ccode.add_declaration ("%s *".printf (cl.get_cname ()), new CCodeVariableDeclarator ("self", ccall));
- var cswitch = new CCodeSwitchStatement (new CCodeIdentifier ("property_id"));
+ ccode.open_switch (new CCodeIdentifier ("property_id"));
var props = cl.get_properties ();
foreach (Property prop in props) {
if (prop.set_accessor == null || prop.is_abstract) {
generate_property_accessor_declaration (prop.base_interface_property.set_accessor, cfile);
}
- cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (prop.get_upper_case_cname ())));
+ ccode.add_case (new CCodeIdentifier (prop.get_upper_case_cname ()));
ccall = new CCodeFunctionCall (new CCodeIdentifier (base_prop.set_accessor.get_cname ()));
ccall.add_argument (cself);
if (prop.property_type is ArrayType && ((ArrayType)prop.property_type).element_type.data_type == string_type.data_type) {
- if (!boxed_declared) {
- cdecl = new CCodeDeclaration ("gpointer");
- cdecl.add_declarator (new CCodeVariableDeclarator ("boxed"));
- block.add_statement (cdecl);
- boxed_declared = true;
- }
+ ccode.open_block ();
+ ccode.add_declaration ("gpointer", new CCodeVariableDeclarator ("boxed"));
+
var cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_boxed"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("boxed"), cgetcall)));
+ ccode.add_assignment (new CCodeIdentifier ("boxed"), cgetcall);
ccall.add_argument (new CCodeIdentifier ("boxed"));
var cstrvlen = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
cstrvlen.add_argument (new CCodeIdentifier ("boxed"));
ccall.add_argument (cstrvlen);
+ ccode.add_expression (ccall);
+ ccode.close ();
} else {
var cgetcall = new CCodeFunctionCall ();
if (prop.property_type.data_type != null) {
}
cgetcall.add_argument (new CCodeIdentifier ("value"));
ccall.add_argument (cgetcall);
+ ccode.add_expression (ccall);
}
- cswitch.add_statement (new CCodeExpressionStatement (ccall));
- cswitch.add_statement (new CCodeBreakStatement ());
+ ccode.add_break ();
}
- cswitch.add_statement (new CCodeLabel ("default"));
- cswitch.add_statement (get_invalid_property_id_warn_statement ());
- cswitch.add_statement (new CCodeBreakStatement ());
-
- block.add_statement (cswitch);
/* type, dup func, and destroy func properties for generic types */
foreach (TypeParameter type_param in cl.get_type_parameters ()) {
func_name = "%s_type".printf (type_param.name.down ());
enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
- cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
+ ccode.add_case (new CCodeIdentifier (enum_value));
cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_gtype"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
- cswitch.add_statement (new CCodeBreakStatement ());
+ ccode.add_assignment (cfield, cgetcall);
+ ccode.add_break ();
func_name = "%s_dup_func".printf (type_param.name.down ());
enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
- cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
+ ccode.add_case (new CCodeIdentifier (enum_value));
cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
- cswitch.add_statement (new CCodeBreakStatement ());
+ ccode.add_assignment (cfield, cgetcall);
+ ccode.add_break ();
func_name = "%s_destroy_func".printf (type_param.name.down ());
enum_value = "%s_%s".printf (cl.get_lower_case_cname (null), func_name).up ();
- cswitch.add_statement (new CCodeCaseStatement (new CCodeIdentifier (enum_value)));
+ ccode.add_case (new CCodeIdentifier (enum_value));
cfield = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), func_name);
cgetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
cgetcall.add_argument (new CCodeIdentifier ("value"));
- cswitch.add_statement (new CCodeExpressionStatement (new CCodeAssignment (cfield, cgetcall)));
- cswitch.add_statement (new CCodeBreakStatement ());
+ ccode.add_assignment (cfield, cgetcall);
+ ccode.add_break ();
}
+ ccode.add_default ();
+ emit_invalid_property_id_warn ();
+ ccode.add_break ();
- cfile.add_function_declaration (set_prop);
+ ccode.close ();
- set_prop.block = block;
-
+ pop_function ();
+
+ cfile.add_function_declaration (set_prop);
cfile.add_function (set_prop);
}
- private CCodeStatement get_invalid_property_id_warn_statement () {
+ private void emit_invalid_property_id_warn () {
// warn on invalid property id
var cwarn = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT_WARN_INVALID_PROPERTY_ID"));
cwarn.add_argument (new CCodeIdentifier ("object"));
cwarn.add_argument (new CCodeIdentifier ("property_id"));
cwarn.add_argument (new CCodeIdentifier ("pspec"));
- return new CCodeExpressionStatement (cwarn);
+ ccode.add_expression (cwarn);
}
public override void visit_constructor (Constructor c) {
func.add_parameter (new CCodeParameter ("obj", prop.dynamic_type.get_cname ()));
- var block = new CCodeBlock ();
- generate_gobject_property_getter_wrapper (prop, block);
+ push_function (func);
+
+ ccode.add_declaration (prop.property_type.get_cname (), new CCodeVariableDeclarator ("result"));
+
+ var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_get"));
+ call.add_argument (new CCodeIdentifier ("obj"));
+ call.add_argument (prop.get_canonical_cconstant ());
+ call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result")));
+ call.add_argument (new CCodeConstant ("NULL"));
+
+ ccode.add_expression (call);
+
+ ccode.add_return (new CCodeIdentifier ("result"));
+
+ pop_function ();
// append to C source file
cfile.add_function_declaration (func);
-
- func.block = block;
cfile.add_function (func);
return getter_cname;
var func = new CCodeFunction (setter_cname, "void");
func.modifiers |= CCodeModifiers.STATIC | CCodeModifiers.INLINE;
-
func.add_parameter (new CCodeParameter ("obj", prop.dynamic_type.get_cname ()));
func.add_parameter (new CCodeParameter ("value", prop.property_type.get_cname ()));
- var block = new CCodeBlock ();
- generate_gobject_property_setter_wrapper (prop, block);
+ push_function (func);
- // append to C source file
- cfile.add_function_declaration (func);
-
- func.block = block;
- cfile.add_function (func);
-
- return setter_cname;
- }
-
- void generate_gobject_property_getter_wrapper (DynamicProperty node, CCodeBlock block) {
- var cdecl = new CCodeDeclaration (node.property_type.get_cname ());
- cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
- block.add_statement (cdecl);
-
- var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_get"));
+ var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_set"));
call.add_argument (new CCodeIdentifier ("obj"));
- call.add_argument (node.get_canonical_cconstant ());
- call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("result")));
+ call.add_argument (prop.get_canonical_cconstant ());
+ call.add_argument (new CCodeIdentifier ("value"));
call.add_argument (new CCodeConstant ("NULL"));
- block.add_statement (new CCodeExpressionStatement (call));
+ ccode.add_expression (call);
- block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
- }
+ pop_function ();
- void generate_gobject_property_setter_wrapper (DynamicProperty node, CCodeBlock block) {
- var call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_set"));
- call.add_argument (new CCodeIdentifier ("obj"));
- call.add_argument (node.get_canonical_cconstant ());
- call.add_argument (new CCodeIdentifier ("value"));
- call.add_argument (new CCodeConstant ("NULL"));
+ // append to C source file
+ cfile.add_function_declaration (func);
+ cfile.add_function (func);
- block.add_statement (new CCodeExpressionStatement (call));
+ return setter_cname;
}
public override string get_dynamic_signal_cname (DynamicSignal node) {
func.add_parameter (new CCodeParameter ("signal_name", "const char *"));
func.add_parameter (new CCodeParameter ("handler", "GCallback"));
func.add_parameter (new CCodeParameter ("data", "gpointer"));
- var block = new CCodeBlock ();
- generate_gobject_connect_wrapper (sig, block, false);
+ push_function (func);
+ generate_gobject_connect_wrapper (sig, false);
+ pop_function ();
// append to C source file
cfile.add_function_declaration (func);
-
- func.block = block;
cfile.add_function (func);
return connect_wrapper_name;
func.add_parameter (new CCodeParameter ("signal_name", "const char *"));
func.add_parameter (new CCodeParameter ("handler", "GCallback"));
func.add_parameter (new CCodeParameter ("data", "gpointer"));
- var block = new CCodeBlock ();
- generate_gobject_connect_wrapper (sig, block, true);
+ push_function (func);
+ generate_gobject_connect_wrapper (sig, true);
+ pop_function ();
// append to C source file
cfile.add_function_declaration (func);
-
- func.block = block;
cfile.add_function (func);
return connect_wrapper_name;
}
- void generate_gobject_connect_wrapper (DynamicSignal sig, CCodeBlock block, bool after) {
+ void generate_gobject_connect_wrapper (DynamicSignal sig, bool after) {
var m = (Method) sig.handler.symbol_reference;
sig.accept (this);
call.add_argument (new CCodeIdentifier ("data"));
if (m.binding == MemberBinding.INSTANCE) {
- if (!after)
+ if (!after) {
call.add_argument (new CCodeConstant ("0"));
- else
+ } else {
call.add_argument (new CCodeConstant ("G_CONNECT_AFTER"));
+ }
}
- block.add_statement (new CCodeExpressionStatement (call));
+ ccode.add_expression (call);
}
public override void visit_property (Property prop) {