[vala/wip/attributes: 11/121] codegen: Add get_ccode_ref_function



commit 695df5111c04dcadf22eab68352c420012caf9ed
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   |   40 +++++++++++++++++++++++++++++++++--
 codegen/valagdbusservermodule.vala |    4 +-
 codegen/valagtypemodule.vala       |    6 ++--
 3 files changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 8ffb6a8..bc88c51 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2235,8 +2235,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 ((ObjectTypeSymbol) 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;
 				}
@@ -3670,7 +3670,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;
 		}
@@ -5622,6 +5622,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) {
 	}
 
@@ -6039,6 +6043,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;
@@ -6046,6 +6059,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;
@@ -6069,6 +6083,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");
 		}
 	}
 
@@ -6269,4 +6284,23 @@ 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) {
+			foreach (var prereq in ((Interface) sym).get_prerequisites ()) {
+				var ref_func = CCodeBaseModule.get_ccode_ref_function ((ObjectTypeSymbol) 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]