[vala/wip/attributes: 10/13] codegen: Add get_ccode_ref_function
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/attributes: 10/13] codegen: Add get_ccode_ref_function
- Date: Sun, 26 Jun 2011 15:05:43 +0000 (UTC)
commit 97e9203259bad1845ec0aa2539268b784a55a667
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jun 26 16:28:40 2011 +0200
codegen: Add get_ccode_ref_function
codegen/valaccodebasemodule.vala | 41 +++++++++++++++++++++++++++++++++--
codegen/valagdbusservermodule.vala | 4 +-
codegen/valagtypemodule.vala | 6 ++--
3 files changed, 43 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 692ac01..7c630d6 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2233,8 +2233,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
string dup_function;
var cl = type.data_type as Class;
if (type.data_type.is_reference_counting ()) {
- dup_function = type.data_type.get_ref_function ();
- if (type.data_type is Interface && dup_function == null) {
+ dup_function = get_ccode_ref_function (type.data_type);
+ if (type.data_type is Interface && dup_function == "") {
Report.error (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;
}
@@ -3668,7 +3668,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var cl = type.data_type as Class;
if (cl != null && cl.is_reference_counting ()
- && cl.get_ref_function () == "") {
+ && get_ccode_ref_function (cl) == "") {
// empty ref_function => no ref necessary
return false;
}
@@ -5620,6 +5620,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_ccode_attribute(sym).lower_case_suffix;
}
+ public static string get_ccode_ref_function (ObjectTypeSymbol sym) {
+ return get_ccode_attribute(sym).ref_function;
+ }
+
public override void visit_class (Class cl) {
}
@@ -6037,6 +6041,15 @@ public class Vala.CCodeAttribute : AttributeCache {
}
}
+ public string ref_function {
+ get {
+ if (_ref_function == null) {
+ _ref_function = get_default_ref_function ();
+ }
+ return _ref_function;
+ }
+ }
+
private string _name;
private string _const_name;
private string _type_name;
@@ -6044,6 +6057,7 @@ public class Vala.CCodeAttribute : AttributeCache {
private string _prefix;
private string _lower_case_prefix;
private string _lower_case_suffix;
+ private string _ref_function;
public CCodeAttribute (CodeNode node) {
this.node = node;
@@ -6067,6 +6081,7 @@ public class Vala.CCodeAttribute : AttributeCache {
_lower_case_prefix = _prefix;
}
_lower_case_suffix = attr.get_string ("lower_case_csuffix");
+ _ref_function = attr.get_string ("ref_function");
}
}
@@ -6267,4 +6282,24 @@ public class Vala.CCodeAttribute : AttributeCache {
return Symbol.camel_case_to_lower_case (sym.name);
}
}
+
+ private string get_default_ref_function () {
+ if (sym is Class) {
+ var cl = (Class) sym;
+ if (cl.is_fundamental ()) {
+ return lower_case_prefix + "ref";
+ } else if (cl.base_class != null) {
+ return CCodeBaseModule.get_ccode_ref_function (cl.base_class);
+ }
+ } else if (sym is Interface) {
+ var iface = (Interface) sym;
+ foreach (var prereq in iface.prerequisites) {
+ var ref_func = CCodeBaseModule.get_ccode_ref_function (prereq.data_type);
+ if (ref_func != "") {
+ return ref_func;
+ }
+ }
+ }
+ return "";
+ }
}
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index ce9279e..b21e97e 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -1225,8 +1225,8 @@ public class Vala.GDBusServerModule : GDBusClientModule {
alloc_data.add_argument (new CCodeConstant ("3"));
ccode.add_assignment (new CCodeIdentifier ("data"), alloc_data);
- var ref_function = sym.get_ref_function ();
- if (sym is Interface && ref_function == null) {
+ var ref_function = get_ccode_ref_function (sym);
+ if (sym is Interface && ref_function == "") {
Report.error (sym.source_reference, "missing class prerequisite for interface `%s', add GLib.Object to interface declaration if unsure".printf (sym.get_full_name ()));
return;
}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 515169a..732d845 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -811,7 +811,7 @@ public class Vala.GTypeModule : GErrorModule {
var main_condition = new CCodeUnaryExpression (CCodeUnaryOperator.LOGICAL_NEGATION, vpointer);
var main_else_if_condition = new CCodeBinaryExpression (CCodeBinaryOperator.BITWISE_AND, new CCodeIdentifier ("collect_flags"), new CCodeIdentifier ("G_VALUE_NOCOPY_CONTENTS"));
- var ref_fct = new CCodeFunctionCall (new CCodeIdentifier (cl.get_ref_function()));
+ var ref_fct = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_ref_function (cl)));
ref_fct.add_argument (vpointer);
ccode.open_if (main_condition);
ccode.add_assignment (object_p_ptr, null_);
@@ -878,7 +878,7 @@ public class Vala.GTypeModule : GErrorModule {
ccode.close ();
- var ref_call = new CCodeFunctionCall (new CCodeIdentifier (cl.get_ref_function ()));
+ var ref_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_ref_function (cl)));
ref_call.add_argument (new CCodeIdentifier ("object"));
ccode.add_assignment (vpointer, ref_call);
@@ -989,7 +989,7 @@ public class Vala.GTypeModule : GErrorModule {
ccode.add_assignment (vpointer, new CCodeConstant ("v_object"));
- ccall = new CCodeFunctionCall (new CCodeIdentifier (cl.get_ref_function ()));
+ ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_ref_function (cl)));
ccall.add_argument (vpointer);
ccode.add_expression (ccall);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]