summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2018-11-21 10:25:32 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2018-11-21 11:03:54 +0100
commit257297a1b33f2df4ec2641545675b7f92ece93f8 (patch)
tree412d1f8215ef7e7a342b4965cda9598786404d09
parentc9604b47adf545c431be866d833bb7167a3b6f1e (diff)
downloadvala-257297a1b33f2df4ec2641545675b7f92ece93f8.tar.gz
codegen: Add profile specific delegate target/destroy types
Make sure to use them in all delegate related contexts. This improves the support of POSIX profile.
-rw-r--r--codegen/valaccodebasemodule.vala49
-rw-r--r--codegen/valaccodedelegatemodule.vala20
-rw-r--r--codegen/valaccodemethodmodule.vala8
-rw-r--r--codegen/valaccodestructmodule.vala4
-rw-r--r--codegen/valagasyncmodule.vala8
-rw-r--r--codegen/valagtypemodule.vala8
6 files changed, 55 insertions, 42 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index bdb93709a..a0b4b0575 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -322,6 +322,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public TypeSymbol type_module_type;
public TypeSymbol dbus_proxy_type;
public Class gtk_widget_type;
+ public DataType delegate_target_type;
+ public DelegateType delegate_target_destroy_type;
+ Delegate destroy_notify;
public bool in_plugin = false;
public string module_init_param_name;
@@ -500,6 +503,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
dbus_proxy_type = (TypeSymbol) glib_ns.scope.lookup ("DBusProxy");
+
+ delegate_target_type = new CType ("gpointer");
+ destroy_notify = (Delegate) glib_ns.scope.lookup ("DestroyNotify");
+ delegate_target_destroy_type = new DelegateType (destroy_notify);
+ } else {
+ delegate_target_type = new PointerType (new VoidType ());
+ destroy_notify = new Delegate ("ValaDestroyNotify", new VoidType ());
+ destroy_notify.add_parameter (new Parameter ("data", new PointerType (new VoidType ())));
+ destroy_notify.has_target = false;
+ delegate_target_destroy_type = new DelegateType (destroy_notify);
}
var gtk_ns = root_symbol.scope.lookup ("Gtk");
@@ -1088,7 +1101,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (delegate_type.delegate_symbol.has_target) {
// create field to store delegate target
- cdecl = new CCodeDeclaration ("gpointer");
+ cdecl = new CCodeDeclaration (get_ccode_name (delegate_target_type));
cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_delegate_target_name (f)));
if (f.is_private_symbol ()) {
cdecl.modifiers = CCodeModifiers.STATIC;
@@ -1100,7 +1113,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
decl_space.add_type_member_declaration (cdecl);
if (delegate_type.is_disposable ()) {
- cdecl = new CCodeDeclaration ("GDestroyNotify");
+ cdecl = new CCodeDeclaration (get_ccode_name (delegate_target_destroy_type));
cdecl.add_declarator (new CCodeVariableDeclarator (get_delegate_target_destroy_notify_cname (get_ccode_name (f))));
if (f.is_private_symbol ()) {
cdecl.modifiers = CCodeModifiers.STATIC;
@@ -1300,7 +1313,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (delegate_type.delegate_symbol.has_target) {
// create field to store delegate target
- var target_def = new CCodeDeclaration ("gpointer");
+ var target_def = new CCodeDeclaration (get_ccode_name (delegate_target_type));
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;
@@ -1310,7 +1323,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
cfile.add_type_member_declaration (target_def);
if (delegate_type.is_disposable ()) {
- var target_destroy_notify_def = new CCodeDeclaration ("GDestroyNotify");
+ var target_destroy_notify_def = new CCodeDeclaration (get_ccode_name (delegate_target_destroy_type));
target_destroy_notify_def.add_declarator (new CCodeVariableDeclarator (get_delegate_target_destroy_notify_cname (get_ccode_name (f)), new CCodeConstant ("NULL")));
if (!f.is_private_symbol ()) {
target_destroy_notify_def.modifiers = CCodeModifiers.EXTERN;
@@ -1559,9 +1572,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
function.add_parameter (new CCodeParameter (get_array_length_cname (acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*" : length_ctype));
}
} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
- function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
+ function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? get_ccode_name (delegate_target_type) + "*" : get_ccode_name (delegate_target_type)));
if (!acc.readable && acc.value_type.value_owned) {
- function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), "GDestroyNotify"));
+ function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), get_ccode_name (delegate_target_destroy_type)));
}
}
@@ -1662,9 +1675,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
function.add_parameter (new CCodeParameter (get_array_length_cname (acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*": length_ctype));
}
} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
- function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
+ function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? get_ccode_name (delegate_target_type) + "*" : get_ccode_name (delegate_target_type)));
if (!acc.readable && acc.value_type.value_owned) {
- function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), "GDestroyNotify"));
+ function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), get_ccode_name (delegate_target_destroy_type)));
}
}
@@ -1786,9 +1799,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
function.add_parameter (new CCodeParameter (get_array_length_cname (acc.readable ? "result" : "value", dim), acc.readable ? length_ctype + "*" : length_ctype));
}
} else if ((acc.value_type is DelegateType) && ((DelegateType) acc.value_type).delegate_symbol.has_target) {
- function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? "gpointer*" : "gpointer"));
+ function.add_parameter (new CCodeParameter (get_delegate_target_cname (acc.readable ? "result" : "value"), acc.readable ? get_ccode_name (delegate_target_type) + "*" : get_ccode_name (delegate_target_type)));
if (!acc.readable && acc.value_type.value_owned) {
- function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), "GDestroyNotify"));
+ function.add_parameter (new CCodeParameter (get_delegate_target_destroy_notify_cname ("value"), get_ccode_name (delegate_target_destroy_type)));
}
}
@@ -1932,9 +1945,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
data.add_field (length_ctype, get_parameter_array_length_cname (param, dim));
}
} else if (deleg_type != null && deleg_type.delegate_symbol.has_target) {
- data.add_field ("gpointer", get_ccode_delegate_target_name (param));
+ data.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (param));
if (param.variable_type.is_disposable ()) {
- data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
+ data.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
// reference transfer for delegates
var lvalue = get_parameter_cvalue (param);
((GLibValue) value).delegate_target_destroy_notify_cvalue = get_delegate_target_destroy_notify_cvalue (lvalue);
@@ -2001,9 +2014,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
data.add_field (length_ctype, 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)));
+ data.add_field (get_ccode_name (delegate_target_type), get_delegate_target_cname (get_local_cname (local)));
if (local.variable_type.is_disposable ()) {
- data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_local_cname (local)));
+ data.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_local_cname (local)));
}
}
}
@@ -2459,11 +2472,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var deleg_type = (DelegateType) local.variable_type;
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)));
+ var target_var = new LocalVariable (delegate_target_type.copy (), get_delegate_target_cname (get_local_cname (local)));
target_var.init = local.initializer == null;
emit_temp_var (target_var);
if (deleg_type.is_disposable ()) {
- var target_destroy_notify_var = new LocalVariable (gdestroynotify_type, get_delegate_target_destroy_notify_cname (get_local_cname (local)));
+ var target_destroy_notify_var = new LocalVariable (delegate_target_destroy_type.copy (), 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);
}
@@ -2507,11 +2520,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
emit_temp_var (len_var);
}
} else if (deleg_type != null && deleg_type.delegate_symbol.has_target) {
- var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (local.name), null, node_reference.source_reference);
+ var target_var = new LocalVariable (delegate_target_type.copy (), get_delegate_target_cname (local.name), null, node_reference.source_reference);
target_var.init = init;
emit_temp_var (target_var);
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);
+ var target_destroy_notify_var = new LocalVariable (delegate_target_destroy_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 ed6357c0a..a3170b835 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -76,10 +76,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var deleg_type = (DelegateType) param.variable_type;
var param_d = deleg_type.delegate_symbol;
if (param_d.has_target) {
- cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), "gpointer");
+ cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), get_ccode_name (delegate_target_type));
cfundecl.add_parameter (cparam);
if (deleg_type.is_disposable ()) {
- cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), "GDestroyNotify");
+ cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), get_ccode_name (delegate_target_destroy_type));
cfundecl.add_parameter (cparam);
}
}
@@ -99,10 +99,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var deleg_type = (DelegateType) d.return_type;
var result_d = deleg_type.delegate_symbol;
if (result_d.has_target) {
- var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "gpointer*");
+ var cparam = new CCodeParameter (get_delegate_target_cname ("result"), get_ccode_name (delegate_target_type) + "*");
cfundecl.add_parameter (cparam);
if (deleg_type.is_disposable ()) {
- cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), "GDestroyNotify*");
+ cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), get_ccode_name (delegate_target_destroy_type) + "*");
cfundecl.add_parameter (cparam);
}
}
@@ -111,7 +111,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
cfundecl.add_parameter (cparam);
}
if (d.has_target) {
- var cparam = new CCodeParameter ("user_data", "gpointer");
+ var cparam = new CCodeParameter ("user_data", get_ccode_name (delegate_target_type));
cfundecl.add_parameter (cparam);
}
if (d.tree_can_fail) {
@@ -214,7 +214,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
if (d.has_target) {
- var cparam = new CCodeParameter ("self", "gpointer");
+ var cparam = new CCodeParameter ("self", get_ccode_name (delegate_target_type));
cparam_map.set (get_param_pos (get_ccode_instance_pos (d)), cparam);
}
@@ -249,10 +249,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var deleg_type = (DelegateType) d.return_type;
if (deleg_type.delegate_symbol.has_target) {
- var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "gpointer*");
+ var cparam = new CCodeParameter (get_delegate_target_cname ("result"), get_ccode_name (delegate_target_type) + "*");
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (d)), cparam);
if (deleg_type.is_disposable ()) {
- cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), "GDestroyNotify*");
+ cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), get_ccode_name (delegate_target_destroy_type) + "*");
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (d) + 0.01), cparam);
}
}
@@ -465,8 +465,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
generate_type_declaration (param.variable_type, decl_space);
string ctypename = get_ccode_name (param.variable_type);
- string target_ctypename = "gpointer";
- string target_destroy_notify_ctypename = "GDestroyNotify";
+ string target_ctypename = get_ccode_name (delegate_target_type);
+ string target_destroy_notify_ctypename = get_ccode_name (delegate_target_destroy_type);
if (param.parent_symbol is Delegate
&& get_ccode_name (param.variable_type) == get_ccode_name (param.parent_symbol)) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 9506fe6de..c9731a1ca 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -93,13 +93,13 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
// return delegate target if appropriate
var deleg_type = (DelegateType) m.return_type;
if (deleg_type.delegate_symbol.has_target) {
- var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "gpointer*");
+ var cparam = new CCodeParameter (get_delegate_target_cname ("result"), get_ccode_name (delegate_target_type) + "*");
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), get_variable_cexpression (cparam.name));
}
if (deleg_type.is_disposable ()) {
- cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), "GDestroyNotify*");
+ cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), get_ccode_name (delegate_target_destroy_type) + "*");
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), get_variable_cexpression (cparam.name));
@@ -590,11 +590,11 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
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);
+ ccode.add_declaration (get_ccode_name (delegate_target_type), vardecl);
if (deleg_type.is_disposable ()) {
vardecl = new CCodeVariableDeclarator.zero (get_delegate_target_destroy_notify_cname (get_variable_cname ("_vala_%s".printf (param.name))), new CCodeConstant ("NULL"));
- ccode.add_declaration ("GDestroyNotify", vardecl);
+ ccode.add_declaration (get_ccode_name (delegate_target_destroy_type), vardecl);
}
}
}
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 4460cba11..cfa9ef906 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -99,9 +99,9 @@ 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_ccode_delegate_target_name (f));
+ instance_struct.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (f));
if (delegate_type.is_disposable ()) {
- instance_struct.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_ccode_name (f)));
+ instance_struct.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_ccode_name (f)));
}
}
}
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index c63d9fc65..21f72dee1 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -66,9 +66,9 @@ public class Vala.GAsyncModule : GtkModule {
} 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_ccode_delegate_target_name (param));
+ data.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (param));
if (deleg_type.is_disposable ()) {
- data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
+ data.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
}
}
}
@@ -93,8 +93,8 @@ public class Vala.GAsyncModule : GtkModule {
} else if (m.return_type is DelegateType) {
var deleg_type = (DelegateType) m.return_type;
if (deleg_type.delegate_symbol.has_target) {
- data.add_field ("gpointer", get_delegate_target_cname ("result"));
- data.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname ("result"));
+ data.add_field (get_ccode_name (delegate_target_type), get_delegate_target_cname ("result"));
+ data.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname ("result"));
}
}
}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index c50696d00..d81c530b8 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -435,9 +435,9 @@ 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_ccode_delegate_target_name (f));
+ instance_struct.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (f));
if (delegate_type.is_disposable ()) {
- instance_struct.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_ccode_name (f)));
+ instance_struct.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_ccode_name (f)));
}
}
}
@@ -537,9 +537,9 @@ 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_ccode_delegate_target_name (f));
+ instance_priv_struct.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (f));
if (delegate_type.is_disposable ()) {
- instance_priv_struct.add_field ("GDestroyNotify", get_delegate_target_destroy_notify_cname (get_ccode_name (f)));
+ instance_priv_struct.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_ccode_name (f)));
}
}
}