From: Rico Tzschichholz Date: Wed, 6 Jun 2018 11:22:53 +0000 (+0200) Subject: codegen: Unify some delegate-type check patterns X-Git-Tag: 0.41.90~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d706755a81fb54c1652d554bafab0794f618d05;p=thirdparty%2Fvala.git codegen: Unify some delegate-type check patterns --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 9147a5fa0..71d5d5ae6 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -1100,7 +1100,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } decl_space.add_type_member_declaration (cdecl); - if (delegate_type.value_owned && !delegate_type.is_called_once) { + if (delegate_type.is_disposable ()) { cdecl = new CCodeDeclaration ("GDestroyNotify"); cdecl.add_declarator (new CCodeVariableDeclarator (get_delegate_target_destroy_notify_cname (get_ccode_name (f)))); if (f.is_private_symbol ()) { @@ -2006,7 +2006,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { data.add_field ("gint", get_array_size_cname (get_local_cname (local))); } else if (local.variable_type is DelegateType && ((DelegateType) local.variable_type).delegate_symbol.has_target) { data.add_field ("gpointer", get_delegate_target_cname (get_local_cname (local))); - if (local.variable_type.value_owned) { + if (local.variable_type.is_disposable ()) { data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_local_cname (local))); } } @@ -2444,13 +2444,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } else if (local.variable_type is DelegateType) { var deleg_type = (DelegateType) local.variable_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { // create variable to store delegate target var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (get_local_cname (local))); target_var.init = local.initializer == null; emit_temp_var (target_var); - if (deleg_type.value_owned) { + if (deleg_type.is_disposable ()) { var target_destroy_notify_var = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (get_local_cname (local))); target_destroy_notify_var.init = local.initializer == null; emit_temp_var (target_destroy_notify_var); @@ -2498,7 +2497,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (local.name), null, node_reference.source_reference); target_var.init = init; emit_temp_var (target_var); - if (deleg_type.value_owned) { + if (deleg_type.is_disposable ()) { var target_destroy_notify_var = new LocalVariable (gdestroynotify_type.copy (), get_delegate_target_destroy_notify_cname (local.name), null, node_reference.source_reference); target_destroy_notify_var.init = init; emit_temp_var (target_destroy_notify_var); diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala index 82202c97a..e3ab92ce7 100644 --- a/codegen/valaccodedelegatemodule.vala +++ b/codegen/valaccodedelegatemodule.vala @@ -489,11 +489,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { if (param.variable_type is DelegateType) { var deleg_type = (DelegateType) param.variable_type; - var d = deleg_type.delegate_symbol; - generate_delegate_declaration (d, decl_space); + generate_delegate_declaration (deleg_type.delegate_symbol, decl_space); - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { var cparam = new CCodeParameter (get_ccode_delegate_target_name (param), target_ctypename); cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam); if (carg_map != null) { diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala index 71702a9c1..30aec9499 100644 --- a/codegen/valaccodememberaccessmodule.vala +++ b/codegen/valaccodememberaccessmodule.vala @@ -402,12 +402,12 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { } else if (delegate_type != null && delegate_type.delegate_symbol.has_target) { if (is_in_coroutine ()) { result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_cname (get_local_cname (local))); - if (local.variable_type.value_owned) { + if (local.variable_type.is_disposable ()) { result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_destroy_notify_cname (get_local_cname (local))); } } else { result.delegate_target_cvalue = new CCodeIdentifier (get_delegate_target_cname (get_local_cname (local))); - if (local.variable_type.value_owned) { + if (local.variable_type.is_disposable ()) { result.delegate_target_destroy_notify_cvalue = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_local_cname (local))); } } diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 6659442d1..efa067a9a 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -377,8 +377,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } } else if (param.variable_type is DelegateType) { var deleg_type = (DelegateType) param.variable_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { CCodeExpression delegate_target_destroy_notify; var delegate_target = get_delegate_target_cexpression (arg, out delegate_target_destroy_notify); assert (delegate_target != null); @@ -441,8 +440,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } } else if (param.variable_type is DelegateType) { var deleg_type = (DelegateType) param.variable_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { temp_var = get_temp_variable (new PointerType (new VoidType ()), true, null, true); emit_temp_var (temp_var); set_delegate_target (arg, get_variable_cexpression (temp_var.name)); @@ -532,8 +530,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } } else if (m != null && m.return_type is DelegateType && async_call != ccall) { var deleg_type = (DelegateType) m.return_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { var temp_var = get_temp_variable (new PointerType (new VoidType ())); var temp_ref = get_variable_cexpression (temp_var.name); @@ -594,8 +591,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } } else if (deleg != null && deleg.return_type is DelegateType) { var deleg_type = (DelegateType) deleg.return_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { var temp_var = get_temp_variable (new PointerType (new VoidType ())); var temp_ref = get_variable_cexpression (temp_var.name); diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index 66e3ad1a7..224f2d53a 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -93,8 +93,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } else if (m.return_type is DelegateType) { // return delegate target if appropriate var deleg_type = (DelegateType) m.return_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "void**"); cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), cparam); if (carg_map != null) { @@ -586,8 +585,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } } else if (param.variable_type is DelegateType) { var deleg_type = (DelegateType) param.variable_type; - var d = deleg_type.delegate_symbol; - if (d.has_target) { + if (deleg_type.delegate_symbol.has_target) { // create variable to store delegate target vardecl = new CCodeVariableDeclarator.zero ("_vala_%s".printf (get_ccode_delegate_target_name (param)), new CCodeConstant ("NULL")); ccode.add_declaration ("void *", vardecl); diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala index 715c35f56..9d63ab7ad 100644 --- a/codegen/valagasyncmodule.vala +++ b/codegen/valagasyncmodule.vala @@ -51,8 +51,6 @@ public class Vala.GAsyncModule : GtkModule { } foreach (Parameter param in m.get_parameters ()) { - bool is_unowned_delegate = param.variable_type is DelegateType && !param.variable_type.value_owned; - var param_type = param.variable_type.copy (); param_type.value_owned = true; data.add_field (get_ccode_name (param_type), get_variable_cname (param.name)); @@ -68,7 +66,7 @@ public class Vala.GAsyncModule : GtkModule { var deleg_type = (DelegateType) param.variable_type; if (deleg_type.delegate_symbol.has_target) { data.add_field ("gpointer", get_ccode_delegate_target_name (param)); - if (!is_unowned_delegate) { + if (deleg_type.is_disposable ()) { data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_variable_cname (param.name))); } }