[vala/wip/attributes: 11/13] codegen: Add get_ccode_unref_function
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 11/13] codegen: Add get_ccode_unref_function
- Date: Sun, 26 Jun 2011 15:46:52 +0000 (UTC)
commit c1ffdcbcd458d09a0e337bc073ca7ff3a5efc25c
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jun 26 16:32:36 2011 +0200
codegen: Add get_ccode_unref_function
codegen/valaccodebasemodule.vala | 40 +++++++++++++++++++++++++++++++++--
codegen/valagdbusservermodule.vala | 2 +-
codegen/valagtypemodule.vala | 4 +-
3 files changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 93d07dd..28f3571 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2678,8 +2678,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
string unref_function;
if (type is ReferenceType) {
if (type.data_type.is_reference_counting ()) {
- unref_function = type.data_type.get_unref_function ();
- if (type.data_type is Interface && unref_function == null) {
+ unref_function = get_ccode_unref_function ((ObjectTypeSymbol) type.data_type);
+ if (type.data_type is Interface && unref_function == "") {
Report.error (type.source_reference, "missing class prerequisite for interface `%s', add GLib.Object to interface declaration if unsure".printf (type.data_type.get_full_name ()));
return null;
}
@@ -3696,7 +3696,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var cl = type.data_type as Class;
if (cl != null && cl.is_reference_counting ()
- && cl.get_unref_function () == "") {
+ && get_ccode_unref_function (cl) == "") {
// empty unref_function => no unref necessary
return false;
}
@@ -5626,6 +5626,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_ccode_attribute(sym).ref_function;
}
+ public static string get_ccode_unref_function (ObjectTypeSymbol sym) {
+ return get_ccode_attribute(sym).unref_function;
+ }
+
public override void visit_class (Class cl) {
}
@@ -6052,6 +6056,15 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
+ public string unref_function {
+ get {
+ if (_unref_function == null) {
+ _unref_function = get_default_unref_function ();
+ }
+ return _unref_function;
+ }
+ }
+
private string _name;
private string _const_name;
private string _type_name;
@@ -6060,6 +6073,7 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _lower_case_prefix;
private string _lower_case_suffix;
private string _ref_function;
+ private string _unref_function;
public CCodeAttribute (CodeNode node) {
this.node = node;
@@ -6084,6 +6098,7 @@ public class Vala.CCodeAttribute : AttributeCache {
}
_lower_case_suffix = attr.get_string ("lower_case_csuffix");
_ref_function = attr.get_string ("ref_function");
+ _unref_function = attr.get_string ("unref_function");
}
}
@@ -6303,4 +6318,23 @@ public class Vala.CCodeAttribute : AttributeCache {
}
return "";
}
+
+ private string get_default_unref_function () {
+ if (sym is Class) {
+ var cl = (Class) sym;
+ if (cl.is_fundamental ()) {
+ return lower_case_prefix + "unref";
+ } else if (cl.base_class != null) {
+ return CCodeBaseModule.get_ccode_unref_function (cl.base_class);
+ }
+ } else if (sym is Interface) {
+ foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
+ string unref_func = CCodeBaseModule.get_ccode_unref_function ((ObjectTypeSymbol) prereq.data_type);
+ if (unref_func != "") {
+ return unref_func;
+ }
+ }
+ }
+ return "";
+ }
}
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index b21e97e..f875cae 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -1277,7 +1277,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
ccode.add_declaration ("gpointer*", new CCodeVariableDeclarator ("data", new CCodeIdentifier ("user_data")));
- var unref_object = new CCodeFunctionCall (new CCodeIdentifier (sym.get_unref_function ()));
+ var unref_object = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_unref_function (sym)));
unref_object.add_argument (new CCodeElementAccess (new CCodeIdentifier ("data"), new CCodeConstant ("0")));
ccode.add_expression (unref_object);
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 732d845..8c74e31 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -998,7 +998,7 @@ public class Vala.GTypeModule : GErrorModule {
ccode.close ();
ccode.open_if (new CCodeIdentifier ("old"));
- ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_unref_function ()));
+ ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_unref_function (cl)));
ccall.add_argument (new CCodeIdentifier ("old"));
ccode.add_expression (ccall);
ccode.close ();
@@ -1063,7 +1063,7 @@ public class Vala.GTypeModule : GErrorModule {
ccode.close ();
ccode.open_if (new CCodeIdentifier ("old"));
- ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_unref_function ()));
+ ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_unref_function (cl)));
ccall.add_argument (new CCodeIdentifier ("old"));
ccode.add_expression (ccall);
ccode.close ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]