[vala/wip/attributes: 31/100] codegen: Add get_ccode_delegate_target_pos



commit 43cc8b56cbfec464cc54556b6c170280a5c31a9e
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 18:18:50 2011 +0200

    codegen: Add get_ccode_delegate_target_pos

 codegen/valaccodebasemodule.vala       |   17 +++++++++++++++--
 codegen/valaccodedelegatemodule.vala   |   24 ++++++++++++------------
 codegen/valaccodemethodcallmodule.vala |   16 ++++++++--------
 codegen/valaccodemethodmodule.vala     |    8 ++++----
 4 files changed, 39 insertions(+), 26 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c566629..3a08c24 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4161,9 +4161,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 							if (d.has_target) {
 								CCodeExpression delegate_target_destroy_notify;
 								var delegate_target = get_delegate_target_cexpression (arg, out delegate_target_destroy_notify);
-								carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), delegate_target);
+								carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), delegate_target);
 								if (deleg_type.value_owned) {
-									carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), delegate_target_destroy_notify);
+									carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), delegate_target_destroy_notify);
 								}
 							}
 						}
@@ -5738,6 +5738,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
+	public static double get_ccode_delegate_target_pos (CodeNode node) {
+		var a = node.get_attribute ("CCode");
+		if (a != null && a.has_argument ("delegate_target_pos")) {
+			return a.get_double ("delegate_target_pos");
+		}
+		if (node is Parameter) {
+			var param = (Parameter) node;
+			return param.cparameter_position + 0.1;
+		} else {
+			return -3;
+		}
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 6447b53..fe78e3e 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -252,10 +252,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 			if (deleg_type.delegate_symbol.has_target) {
 				var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "void**");
-				cparam_map.set (get_param_pos (d.cdelegate_target_parameter_position), cparam);
+				cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (d)), cparam);
 				if (deleg_type.value_owned) {
 					cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), "GDestroyNotify*");
-					cparam_map.set (get_param_pos (d.cdelegate_target_parameter_position + 0.01), cparam);
+					cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (d) + 0.01), cparam);
 				}
 			}
 		} else if (d.return_type.is_real_non_null_struct_type ()) {
@@ -345,10 +345,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 				if (deleg_type.delegate_symbol.has_target) {
 					var ctarget = new CCodeIdentifier (get_delegate_target_cname (d_params.get (i).name));
-					carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), ctarget);
+					carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), ctarget);
 					if (deleg_type.value_owned) {
 						var ctarget_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (d_params.get (i).name));
-						carg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), ctarget_destroy_notify);
+						carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), ctarget_destroy_notify);
 					}
 				}
 			}
@@ -371,10 +371,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 			if (deleg_type.delegate_symbol.has_target) {
 				var ctarget = new CCodeIdentifier (get_delegate_target_cname ("result"));
-				carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), ctarget);
+				carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), ctarget);
 				if (deleg_type.value_owned) {
 					var ctarget_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname ("result"));
-					carg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), ctarget_destroy_notify);
+					carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), ctarget_destroy_notify);
 				}
 			}
 		} else if (m.return_type.is_real_non_null_struct_type ()) {
@@ -481,23 +481,23 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 			if (d.has_target) {
 				var cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
-				cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
+				cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
+					carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
 				}
 				if (deleg_type.value_owned) {
 					cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), target_destroy_notify_ctypename);
-					cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), cparam);
+					cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), cparam);
 					if (carg_map != null) {
-						carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), get_variable_cexpression (cparam.name));
+						carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), get_variable_cexpression (cparam.name));
 					}
 				}
 			}
 		} else if (param.variable_type is MethodType) {
 			var cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
-			cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
+			cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
 			if (carg_map != null) {
-				carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
+				carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
 			}
 		}
 
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 26b0b37..6d30f17 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -359,17 +359,17 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 									closure_new.add_argument (delegate_target_destroy_notify);
 									cexpr = new CCodeConditionalExpression (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cexpr, new CCodeIdentifier ("NULL")), new CCodeIdentifier ("NULL"), closure_new);
 								} else {
-									carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), delegate_target);
+									carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), delegate_target);
 									if (deleg_type.value_owned) {
 										assert (delegate_target_destroy_notify != null);
-										carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), delegate_target_destroy_notify);
+										carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), delegate_target_destroy_notify);
 									}
 								}
 							}
 						} else if (param.variable_type is MethodType) {
 							// callbacks in dynamic method calls
 							CCodeExpression delegate_target_destroy_notify;
-							carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_delegate_target_cexpression (arg, out delegate_target_destroy_notify));
+							carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_delegate_target_cexpression (arg, out delegate_target_destroy_notify));
 						} else if (param.variable_type is GenericType) {
 							if (m != null && m.simple_generics) {
 								var generic_type = (GenericType) param.variable_type;
@@ -415,12 +415,12 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 								temp_var = get_temp_variable (new PointerType (new VoidType ()));
 								emit_temp_var (temp_var);
 								set_delegate_target (arg, get_variable_cexpression (temp_var.name));
-								carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target (arg)));
+								carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target (arg)));
 								if (deleg_type.value_owned) {
 									temp_var = get_temp_variable (gdestroynotify_type);
 									emit_temp_var (temp_var);
 									set_delegate_target_destroy_notify (arg, get_variable_cexpression (temp_var.name));
-									carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_destroy_notify (arg)));
+									carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_destroy_notify (arg)));
 								}
 							}
 						}
@@ -506,7 +506,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 				emit_temp_var (temp_var);
 
-				out_arg_map.set (get_param_pos (m.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+				out_arg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
 
 				set_delegate_target (expr, temp_ref);
 
@@ -516,7 +516,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 					emit_temp_var (temp_var);
 
-					out_arg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+					out_arg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
 
 					set_delegate_target_destroy_notify (expr, temp_ref);
 				} else {
@@ -568,7 +568,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 				emit_temp_var (temp_var);
 
-				out_arg_map.set (get_param_pos (deleg.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+				out_arg_map.set (get_param_pos (get_ccode_delegate_target_pos (deleg)), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
 
 				set_delegate_target (expr, temp_ref);
 			}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index ef7a8ab..91dce2b 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -97,15 +97,15 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 			var d = deleg_type.delegate_symbol;
 			if (d.has_target) {
 				var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "void**");
-				cparam_map.set (get_param_pos (m.cdelegate_target_parameter_position), cparam);
+				cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
+					carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), get_variable_cexpression (cparam.name));
 				}
 				if (deleg_type.value_owned) {
 					cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), "GDestroyNotify*");
-					cparam_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), cparam);
+					cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), cparam);
 					if (carg_map != null) {
-						carg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), get_variable_cexpression (cparam.name));
+						carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), get_variable_cexpression (cparam.name));
 					}
 				}
 			}



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