[vala/wip/attributes: 59/119] Drop TypeSymbol.get_free_function



commit b5e7d328c11c52813f9bd2335e6449a2d1d5f47c
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 29 20:17:08 2011 +0200

    Drop TypeSymbol.get_free_function

 codegen/valaccodebasemodule.vala |   12 ++++++++----
 codegen/valadovabasemodule.vala  |    6 +++---
 vala/valaclass.vala              |   23 -----------------------
 vala/valagirparser.vala          |    2 +-
 vala/valastruct.vala             |    9 ---------
 vala/valatypesymbol.vala         |   11 -----------
 6 files changed, 12 insertions(+), 51 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 36a0c5f..bb7bdbd 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2246,7 +2246,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				if (dup_function == null) {
 					dup_function = "";
 				}
-			} else if (cl != null && cl.is_gboxed) {
+			} else if (cl != null && get_ccode_is_gboxed (cl)) {
 				// allow duplicates of gboxed instances
 				dup_function = generate_dup_func_wrapper (type);
 				if (dup_function == null) {
@@ -2554,7 +2554,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		push_function (function);
 
 		var cl = type.data_type as Class;
-		assert (cl != null && cl.is_gboxed);
+		assert (cl != null && get_ccode_is_gboxed (cl));
 
 		var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_boxed_copy"));
 		free_call.add_argument (new CCodeIdentifier (get_ccode_type_id (cl)));
@@ -2585,7 +2585,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		push_function (function);
 
 		var cl = type.data_type as Class;
-		if (cl != null && cl.is_gboxed) {
+		if (cl != null && get_ccode_is_gboxed (cl)) {
 			var free_call = new CCodeFunctionCall (new CCodeIdentifier ("g_boxed_free"));
 			free_call.add_argument (new CCodeIdentifier (get_ccode_type_id (cl)));
 			free_call.add_argument (new CCodeIdentifier ("self"));
@@ -2678,7 +2678,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 					}
 				} else {
 					var cl = type.data_type as Class;
-					if (cl != null && cl.is_gboxed) {
+					if (cl != null && get_ccode_is_gboxed (cl)) {
 						unref_function = generate_free_func_wrapper (type);
 					} else {
 						unref_function = get_ccode_free_function (type.data_type);
@@ -5641,6 +5641,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).free_function;
 	}
 
+	public static bool get_ccode_is_gboxed (TypeSymbol sym) {
+		return get_ccode_free_function (sym) == "g_boxed_free";
+	}
+
 	public static string get_ccode_type_id (CodeNode node) {
 		if (node is DataType) {
 			var type = (DataType) node;
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 91bb309..fa52ba0 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1027,12 +1027,12 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 				if (type.data_type.is_reference_counting ()) {
 					unref_function = type.data_type.get_unref_function ();
 				} else {
-					unref_function = type.data_type.get_free_function ();
+					unref_function = get_ccode_free_function (type.data_type);
 				}
 			} else {
 				if (type.nullable) {
-					unref_function = type.data_type.get_free_function ();
-					if (unref_function == null) {
+					unref_function = get_ccode_free_function (type.data_type);
+					if (unref_function == "") {
 						unref_function = "free";
 					}
 				} else {
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index d25b49e..a3bbe9f 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -102,8 +102,6 @@ public class Vala.Class : ObjectTypeSymbol {
 	 */
 	public bool has_class_private_fields { get; private set; }
 
-	public bool is_gboxed { get { return (free_function == "g_boxed_free"); } }
-
 	private string cname;
 	public string const_cname { get; set; }
 	private string lower_case_cprefix;
@@ -115,7 +113,6 @@ public class Vala.Class : ObjectTypeSymbol {
 	private string ref_sink_function;
 	private string param_spec_function;
 	private string copy_function;
-	private string free_function;
 	private string marshaller_type_name;
 	private string get_value_function;
 	private string set_value_function;
@@ -681,9 +678,6 @@ public class Vala.Class : ObjectTypeSymbol {
 		if (a.has_argument ("copy_function")) {
 			set_dup_function (a.get_string ("copy_function"));
 		}
-		if (a.has_argument ("free_function")) {
-			set_free_function (a.get_string ("free_function"));
-		}
 		if (a.has_argument ("type_id")) {
 			type_id = a.get_string ("type_id");
 		}
@@ -908,24 +902,7 @@ public class Vala.Class : ObjectTypeSymbol {
 		this.copy_function = name;
 	}
 
-	public string get_default_free_function () {
-		if (base_class != null) {
-			return base_class.get_free_function ();
-		}
-		return get_lower_case_cprefix () + "free";
-	}
 
-	public override string? get_free_function () {
-		if (free_function == null) {
-			free_function = get_default_free_function ();
-		}
-		return free_function;
-	}
-	
-	public void set_free_function (string name) {
-		this.free_function = name;
-	}
-	
 	public override bool is_subtype_of (TypeSymbol t) {
 		if (this == t) {
 			return true;
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 2a6a0e5..51f65cd 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2609,7 +2609,7 @@ public class Vala.GirParser : CodeVisitor {
 			var typeid = reader.get_attribute ("glib:get-type");
 			if (typeid != null) {
 				cl.set_type_id ("%s ()".printf (typeid));
-				cl.set_free_function ("g_boxed_free");
+				cl.set_attribute_string ("CCode", "free_function", "g_boxed_free");
 				cl.set_dup_function ("g_boxed_copy");
 			}
 
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index d64b0f6..dee6d24 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -736,15 +736,6 @@ public class Vala.Struct : TypeSymbol {
 		}
 	}
 	
-	public override string? get_free_function () {
-		// TODO use attribute check instead
-		if (external_package) {
-			return null;
-		} else {
-			return get_lower_case_cprefix () + "free";
-		}
-	}
-
 	public string get_default_destroy_function () {
 		return get_lower_case_cprefix () + "destroy";
 	}
diff --git a/vala/valatypesymbol.vala b/vala/valatypesymbol.vala
index ea2da2e..cc59d83 100644
--- a/vala/valatypesymbol.vala
+++ b/vala/valatypesymbol.vala
@@ -62,17 +62,6 @@ public abstract class Vala.TypeSymbol : Symbol {
 	}
 	
 	/**
-	 * Returns the C function name that frees instances of this data type.
-	 * The specified C function must accept one argument pointing to the
-	 * instance to be freed.
-	 *
-	 * @return the name of the C function if supported or null otherwise
-	 */
-	public virtual string? get_free_function () {
-		return null;
-	}
-
-	/**
 	 * Returns the C function name that destroys the contents of instances
 	 * of this data type. This is only applicable to structs. The specified
 	 * C function must accept one argument pointing to the instance to be



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]