[vala/wip/attributes: 61/119] codegen: Add get_ccode_dup_function



commit decf8219a005e4f762400182437c781131d3a087
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 29 20:35:54 2011 +0200

    codegen: Add get_ccode_dup_function

 codegen/valaccodebasemodule.vala      |   18 +++++++-----------
 codegen/valaccodestructmodule.vala    |    4 ++--
 codegen/valadovabasemodule.vala       |    9 +++++----
 codegen/valatyperegisterfunction.vala |    2 +-
 4 files changed, 15 insertions(+), 18 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index bb7bdbd..a142474 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2242,22 +2242,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				}
 			} else if (cl != null && cl.is_immutable) {
 				// allow duplicates of immutable instances as for example strings
-				dup_function = type.data_type.get_dup_function ();
-				if (dup_function == null) {
-					dup_function = "";
-				}
+				dup_function = get_ccode_dup_function (type.data_type) ();
 			} 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) {
-					dup_function = "";
-				}
 			} else if (type is ValueType) {
-				dup_function = type.data_type.get_dup_function ();
-				if (dup_function == null && type.nullable) {
+				dup_function = get_ccode_dup_function (type.data_type) ();
+				if (dup_function == "" && type.nullable) {
 					dup_function = generate_struct_dup_wrapper ((ValueType) type);
-				} else if (dup_function == null) {
-					dup_function = "";
 				}
 			} else {
 				// duplicating non-reference counted objects may cause side-effects (and performance issues)
@@ -5637,6 +5629,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).copy_function;
 	}
 
+	public static string get_ccode_dup_function (TypeSymbol sym) {
+		return get_ccode_copy_function(sym);
+	}
+
 	public static string get_ccode_free_function (TypeSymbol sym) {
 		return get_ccode_attribute(sym).free_function;
 	}
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index f6b1d2c..94d1f35 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -113,7 +113,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 			decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
 		}
 
-		var function = new CCodeFunction (st.get_dup_function (), get_ccode_name (st) + "*");
+		var function = new CCodeFunction (get_ccode_dup_function (st) (), get_ccode_name (st) + "*");
 		if (st.is_private_symbol ()) {
 			function.modifiers = CCodeModifiers.STATIC;
 		}
@@ -184,7 +184,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 	}
 
 	void add_struct_dup_function (Struct st) {
-		var function = new CCodeFunction (st.get_dup_function (), get_ccode_name (st) + "*");
+		var function = new CCodeFunction (get_ccode_dup_function (st) (), get_ccode_name (st) + "*");
 		if (st.access == SymbolAccessibility.PRIVATE) {
 			function.modifiers = CCodeModifiers.STATIC;
 		}
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index fa52ba0..98b1b29 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -999,10 +999,7 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 			if (type.data_type.is_reference_counting ()) {
 				dup_function = type.data_type.get_ref_function ();
 			} else if (type is ValueType) {
-				dup_function = type.data_type.get_dup_function ();
-				if (dup_function == null) {
-					dup_function = "";
-				}
+				dup_function = get_ccode_dup_function (type.data_type);
 			}
 
 			return new CCodeIdentifier (dup_function);
@@ -2297,6 +2294,10 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
 		return CCodeBaseModule.get_ccode_copy_function (node);
 	}
 
+	public string get_ccode_dup_function (CodeNode node) {
+		return CCodeBaseModule.get_ccode_dup_function (node);
+	}
+
 	public DataType? get_this_type () {
 		if (current_method != null && current_method.binding == MemberBinding.INSTANCE) {
 			return current_method.this_parameter.variable_type;
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index e79b995..a107c0a 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -162,7 +162,7 @@ public abstract class Vala.TypeRegisterFunction {
 		reg_call.add_argument (new CCodeConstant ("\"%s\"".printf (CCodeBaseModule.get_ccode_name (get_type_declaration ()))));
 		if (get_type_declaration () is Struct) {
 			var st = (Struct) get_type_declaration ();
-			reg_call.add_argument (new CCodeCastExpression (new CCodeIdentifier (st.get_dup_function ()), "GBoxedCopyFunc"));
+			reg_call.add_argument (new CCodeCastExpression (new CCodeIdentifier (CCodeBaseModule.get_dup_function (st)), "GBoxedCopyFunc"));
 			reg_call.add_argument (new CCodeCastExpression (new CCodeIdentifier (CCodeBaseModule.get_ccode_free_function (st)), "GBoxedFreeFunc"));
 		} else if (get_type_declaration () is Enum) {
 			var en = get_type_declaration () as Enum;



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