Commit 383c3096 authored by Luca Bruno's avatar Luca Bruno

codegen: Add support for delegate_target_cname in CCode

parent 908e5230
......@@ -454,6 +454,20 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
public string delegate_target_name {
get {
if (_delegate_target_name == null) {
if (ccode != null) {
_delegate_target_name = ccode.get_string ("delegate_target_cname");
}
if (_delegate_target_name == null) {
_delegate_target_name = "%s_target".printf (sym.name);
}
}
return _delegate_target_name;
}
}
public bool array_length { get; private set; }
public string? array_length_type { get; private set; }
public bool array_null_terminated { get; private set; }
......@@ -496,6 +510,7 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _finish_vfunc_name;
private string _finish_real_name;
private string _real_name;
private string _delegate_target_name;
private static int dynamic_method_id;
......
......@@ -976,7 +976,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// create field to store delegate target
cdecl = new CCodeDeclaration ("gpointer");
cdecl.add_declarator (new CCodeVariableDeclarator (get_delegate_target_cname (get_ccode_name (f))));
cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_delegate_target_name (f)));
if (f.is_private_symbol ()) {
cdecl.modifiers = CCodeModifiers.STATIC;
} else {
......@@ -1168,7 +1168,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
// create field to store delegate target
var target_def = new CCodeDeclaration ("gpointer");
target_def.add_declarator (new CCodeVariableDeclarator (get_delegate_target_cname (get_ccode_name (f)), new CCodeConstant ("NULL")));
target_def.add_declarator (new CCodeVariableDeclarator (get_ccode_delegate_target_name (f), new CCodeConstant ("NULL")));
if (!f.is_private_symbol ()) {
target_def.modifiers = CCodeModifiers.EXTERN;
} else {
......@@ -1742,7 +1742,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
data.add_field ("gint", get_parameter_array_length_cname (param, dim));
}
} else if (deleg_type != null && deleg_type.delegate_symbol.has_target) {
data.add_field ("gpointer", get_delegate_target_cname (get_variable_cname (param.name)));
data.add_field ("gpointer", get_ccode_delegate_target_name (param));
if (param.variable_type.value_owned) {
data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
// reference transfer for delegates
......@@ -3370,7 +3370,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (param.name)), get_cvalue_ (value));
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_delegate_target_cname (param.name))), get_delegate_target_cvalue (value));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_ccode_delegate_target_name (param))), get_delegate_target_cvalue (value));
if (delegate_type.value_owned) {
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_delegate_target_destroy_notify_cname (param.name))), get_delegate_target_destroy_notify_cvalue (get_parameter_cvalue (param)));
}
......@@ -5911,6 +5911,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_ccode_attribute(node).delegate_target;
}
public static string get_ccode_delegate_target_name (Variable variable) {
return get_ccode_attribute(variable).delegate_target_name;
}
public static double get_ccode_pos (Parameter param) {
return get_ccode_attribute(param).pos;
}
......
......@@ -339,7 +339,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var deleg_type = (DelegateType) param.variable_type;
if (deleg_type.delegate_symbol.has_target) {
var ctarget = new CCodeIdentifier (get_delegate_target_cname (d_params.get (i).name));
var ctarget = new CCodeIdentifier (get_ccode_delegate_target_name (d_params.get (i)));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), ctarget);
if (deleg_type.value_owned) {
var ctarget_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (d_params.get (i).name));
......@@ -473,7 +473,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
generate_delegate_declaration (d, decl_space);
if (d.has_target) {
var cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
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) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
......@@ -487,7 +487,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
}
} else if (param.variable_type is MethodType) {
var cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
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) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
......
......@@ -421,7 +421,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
result.append_array_length_cvalue (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_parameter_array_length_cname (param, dim)));
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (param.name)));
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_ccode_delegate_target_name (param));
if (result.value_type.value_owned) {
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
}
......@@ -430,7 +430,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
// use closure
result.cvalue = get_variable_cexpression (param.name);
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_cname (get_variable_cname (param.name)));
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_ccode_delegate_target_name (param));
if (delegate_type.value_owned) {
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
}
......@@ -460,7 +460,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
}
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (name)));
var target_cname = get_ccode_delegate_target_name (param);
if (param.direction == ParameterDirection.OUT) {
target_cname = "_vala_" + target_cname;
}
CCodeExpression target_expr = new CCodeIdentifier (target_cname);
CCodeExpression delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (name)));
if (param.direction == ParameterDirection.REF) {
// accessing argument of ref param
......@@ -565,7 +569,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target && get_ccode_delegate_target (field)) {
string target_cname = get_delegate_target_cname (get_ccode_name (field));
string target_cname = get_ccode_delegate_target_name (field);
string target_destroy_notify_cname = get_delegate_target_destroy_notify_cname (get_ccode_name (field));
if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
......@@ -631,7 +635,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
set_array_size_cvalue (result, new CCodeIdentifier (get_array_size_cname (get_ccode_name (field))));
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target && get_ccode_delegate_target (field)) {
result.delegate_target_cvalue = new CCodeIdentifier (get_delegate_target_cname (get_ccode_name (field)));
result.delegate_target_cvalue = new CCodeIdentifier (get_ccode_delegate_target_name (field));
if (result.value_type.value_owned) {
result.delegate_target_destroy_notify_cvalue = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_ccode_name (field)));
}
......
......@@ -469,7 +469,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
var d = deleg_type.delegate_symbol;
if (d.has_target) {
// create variable to store delegate target
vardecl = new CCodeVariableDeclarator.zero (get_delegate_target_cname (get_variable_cname ("_vala_" + param.name)), new CCodeConstant ("NULL"));
vardecl = new CCodeVariableDeclarator.zero ("_vala_" + get_ccode_delegate_target_name (param), new CCodeConstant ("NULL"));
ccode.add_declaration ("void *", vardecl);
if (deleg_type.value_owned) {
......
......@@ -90,7 +90,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
var delegate_type = (DelegateType) f.variable_type;
if (delegate_type.delegate_symbol.has_target) {
// create field to store delegate target
instance_struct.add_field ("gpointer", get_delegate_target_cname (f.name));
instance_struct.add_field ("gpointer", get_ccode_delegate_target_name (f));
if (delegate_type.value_owned) {
instance_struct.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (f.name));
}
......
......@@ -58,7 +58,7 @@ public class Vala.GAsyncModule : GSignalModule {
} else if (param.variable_type is DelegateType) {
var deleg_type = (DelegateType) param.variable_type;
if (deleg_type.delegate_symbol.has_target) {
data.add_field ("gpointer", get_delegate_target_cname (get_variable_cname (param.name)));
data.add_field ("gpointer", get_ccode_delegate_target_name (param));
if (!is_unowned_delegate) {
data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
}
......
......@@ -338,7 +338,7 @@ public class Vala.GTypeModule : GErrorModule {
var delegate_type = (DelegateType) f.variable_type;
if (delegate_type.delegate_symbol.has_target) {
// create field to store delegate target
instance_struct.add_field ("gpointer", get_delegate_target_cname (f.name));
instance_struct.add_field ("gpointer", get_ccode_delegate_target_name (f));
if (delegate_type.value_owned) {
instance_struct.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (f.name));
}
......@@ -444,7 +444,7 @@ public class Vala.GTypeModule : GErrorModule {
var delegate_type = (DelegateType) f.variable_type;
if (delegate_type.delegate_symbol.has_target) {
// create field to store delegate target
instance_priv_struct.add_field ("gpointer", get_delegate_target_cname (f.name));
instance_priv_struct.add_field ("gpointer", get_ccode_delegate_target_name (f));
if (delegate_type.value_owned) {
instance_priv_struct.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (f.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