[vala/wip/attributes: 15/100] codegen: Add get_ccode_copy_function



commit a4708adcb4694b84aa6e0ff3748d466ab4286c74
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 09:13:20 2011 +0200

    codegen: Add get_ccode_copy_function

 codegen/valaccodebasemodule.vala   |   27 +++++++++++++++++++++++----
 codegen/valaccodestructmodule.vala |    6 +++---
 2 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3a070d2..e842d2e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2511,7 +2511,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 					generate_struct_copy_function (st);
 				}
 
-				var copy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_copy_function ()));
+				var copy_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_copy_function (st)));
 				copy_call.add_argument (new CCodeIdentifier ("self"));
 				copy_call.add_argument (new CCodeIdentifier ("dup"));
 				ccode.add_expression (copy_call);
@@ -3742,7 +3742,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			var vt = (ValueType) type;
 			var st = (Struct) vt.type_symbol;
-			var copy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_copy_function ()));
+			var copy_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_copy_function (st)));
 			copy_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr));
 			copy_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
 
@@ -5638,6 +5638,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).ref_sink_function;
 	}
 
+	public static string get_ccode_copy_function (TypeSymbol sym) {
+		return get_ccode_attribute(sym).copy_function;
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
@@ -5700,12 +5704,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	void generate_struct_copy_function (Struct st) {
-		if (cfile.add_declaration (st.get_copy_function ())) {
+		if (cfile.add_declaration (get_ccode_copy_function (st))) {
 			// only generate function once per source file
 			return;
 		}
 
-		var function = new CCodeFunction (st.get_copy_function (), "void");
+		var function = new CCodeFunction (get_ccode_copy_function (st), "void");
 		function.modifiers = CCodeModifiers.STATIC;
 		function.add_parameter (new CCodeParameter ("self", "const " + get_ccode_name (st) + "*"));
 		function.add_parameter (new CCodeParameter ("dest", get_ccode_name (st) + "*"));
@@ -6096,6 +6100,19 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public string copy_function {
+		get {
+			if (_copy_function == null) {
+				if (sym is Struct) {
+					_copy_function = lower_case_prefix + "copy";
+				} else {
+					_copy_function = "";
+				}
+			}
+			return _copy_function;
+		}
+	}
+
 	private string _name;
 	private string _const_name;
 	private string _type_name;
@@ -6107,6 +6124,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 	private bool? _ref_function_void;
 	private string _unref_function;
 	private string _ref_sink_function;
+	private string _copy_function;
 
 	public CCodeAttribute (CodeNode node) {
 		this.node = node;
@@ -6136,6 +6154,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 			}
 			_unref_function = attr.get_string ("unref_function");
 			_ref_sink_function = attr.get_string ("ref_sink_function");
+			_copy_function = attr.get_string ("copy_function");
 		}
 	}
 
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index 13254c8..9df2690 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -128,7 +128,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 		decl_space.add_function_declaration (function);
 
 		if (st.is_disposable ()) {
-			function = new CCodeFunction (st.get_copy_function (), "void");
+			function = new CCodeFunction (get_ccode_copy_function (st), "void");
 			if (st.is_private_symbol ()) {
 				function.modifiers = CCodeModifiers.STATIC;
 			}
@@ -201,7 +201,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 		ccode.add_assignment (new CCodeIdentifier ("dup"), creation_call);
 
 		if (st.is_disposable ()) {
-			var copy_call = new CCodeFunctionCall (new CCodeIdentifier (st.get_copy_function ()));
+			var copy_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_copy_function (st)));
 			copy_call.add_argument (new CCodeIdentifier ("self"));
 			copy_call.add_argument (new CCodeIdentifier ("dup"));
 			ccode.add_expression (copy_call);
@@ -251,7 +251,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 	}
 
 	void add_struct_copy_function (Struct st) {
-		var function = new CCodeFunction (st.get_copy_function (), "void");
+		var function = new CCodeFunction (get_ccode_copy_function (st), "void");
 		if (st.access == SymbolAccessibility.PRIVATE) {
 			function.modifiers = CCodeModifiers.STATIC;
 		}



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