[vala/staging] codegen: Add support for delegate_target_cname in CCode
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Add support for delegate_target_cname in CCode
- Date: Mon, 6 Feb 2012 20:22:00 +0000 (UTC)
commit 383c309685ca888edb7dcfe7774f7ed108e77ad8
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Feb 6 21:19:36 2012 +0100
codegen: Add support for delegate_target_cname in CCode
codegen/valaccodeattribute.vala | 15 +++++++++++++++
codegen/valaccodebasemodule.vala | 12 ++++++++----
codegen/valaccodedelegatemodule.vala | 6 +++---
codegen/valaccodememberaccessmodule.vala | 14 +++++++++-----
codegen/valaccodemethodmodule.vala | 2 +-
codegen/valaccodestructmodule.vala | 2 +-
codegen/valagasyncmodule.vala | 2 +-
codegen/valagtypemodule.vala | 4 ++--
8 files changed, 40 insertions(+), 17 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index e8042b1..f076a65 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -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;
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index bdc4dd7..54238d7 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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;
}
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 0c2242d..2391028 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -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));
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 1b9d0de..09b8ad7 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -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)));
}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 213a08e..be69a1c 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -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) {
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index affb48e..ec258d5 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -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));
}
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index c9da729..bee5ceb 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -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)));
}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 753d761..eca78af 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -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));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]