Commit 1d706755 authored by Rico Tzschichholz's avatar Rico Tzschichholz

codegen: Unify some delegate-type check patterns

parent 270f8efb
......@@ -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);
......
......@@ -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) {
......
......@@ -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)));
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)));
}
}
......
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