[vala] codegen: Small refactoring for generic type parameters



commit dd71fb33b4d64018a4f44cb5531b4cf590b80b18
Author: JÃrg Billeter <j bitron ch>
Date:   Mon Aug 1 22:32:46 2011 +0200

    codegen: Small refactoring for generic type parameters

 codegen/valaccodebasemodule.vala       |   15 +++++----------
 codegen/valaccodemethodcallmodule.vala |   15 +++++----------
 2 files changed, 10 insertions(+), 20 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 0feed1b..e5c11b1 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1822,17 +1822,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 				if (current_method != null) {
 					// allow capturing generic type parameters
+					var suffices = new string[] {"type", "dup_func", "destroy_func"};
 					foreach (var type_param in current_method.get_type_parameters ()) {
-						string func_name;
-
-						func_name = "%s_type".printf (type_param.name.down ());
-						ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name), get_variable_cexpression (func_name));
-
-						func_name = "%s_dup_func".printf (type_param.name.down ());
-						ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name), get_variable_cexpression (func_name));
-
-						func_name = "%s_destroy_func".printf (type_param.name.down ());
-						ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name), get_variable_cexpression (func_name));
+						foreach (string suffix in suffices) {
+							string func_name = "%s_%s".printf (type_param.name.down (), suffix);
+							ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name), get_variable_cexpression (func_name));
+						}
 					}
 				}
 			}
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index e9a6476..67104a7 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -290,19 +290,14 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 			if (!current_class.is_compact && current_class.get_type_parameters ().size > 0) {
 				/* type, dup func, and destroy func fields for generic types */
+				var suffices = new string[] {"type", "dup_func", "destroy_func"};
 				foreach (TypeParameter type_param in current_class.get_type_parameters ()) {
-					CCodeIdentifier param_name;
-
 					var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv");
 
-					param_name = new CCodeIdentifier ("%s_type".printf (type_param.name.down ()));
-					ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
-
-					param_name = new CCodeIdentifier ("%s_dup_func".printf (type_param.name.down ()));
-					ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
-
-					param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()));
-					ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
+					foreach (string suffix in suffices) {
+						var param_name = new CCodeIdentifier ("%s_%s".printf (type_param.name.down (), suffix));
+						ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name);
+					}
 				}
 			}
 			// object chainup can't be used as expression



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