[vala/wip/attributes: 30/121] codegen: Add get_ccode_array_length_pos



commit c1a8ac2029a51534c61fba334d0b6ccdf9a5ac1b
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 18:14:25 2011 +0200

    codegen: Add get_ccode_array_length_pos

 codegen/valaccodearraymodule.vala      |    4 ++--
 codegen/valaccodebasemodule.vala       |   15 ++++++++++++++-
 codegen/valaccodedelegatemodule.vala   |    6 +++---
 codegen/valaccodemethodcallmodule.vala |    8 ++++----
 codegen/valaccodemethodmodule.vala     |    4 ++--
 5 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 83b4d1e..2776811 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -743,9 +743,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			
 			for (int dim = 1; dim <= array_type.rank; dim++) {
 				var cparam = new CCodeParameter (get_parameter_array_length_cname (param, dim), length_ctype);
-				cparam_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), cparam);
+				cparam_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (cparam.name));
+					carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), get_variable_cexpression (cparam.name));
 				}
 			}
 		}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4e0ad95..c566629 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4153,7 +4153,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 						if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
 							var array_type = (ArrayType) param.variable_type;
 							for (int dim = 1; dim <= array_type.rank; dim++) {
-								carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_array_length_cexpression (arg, dim));
+								carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), get_array_length_cexpression (arg, dim));
 							}
 						} else if (param.variable_type is DelegateType) {
 							var deleg_type = (DelegateType) param.variable_type;
@@ -5725,6 +5725,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return get_ccode_attribute(sym).array_length_type;
 	}
 
+	public static double get_ccode_array_length_pos (CodeNode node) {
+		var a = node.get_attribute ("CCode");
+		if (a != null && a.has_argument ("array_length_pos")) {
+			return a.get_double ("array_length_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 0875007..6447b53 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -244,7 +244,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 			for (int dim = 1; dim <= array_type.rank; dim++) {
 				var cparam = new CCodeParameter (get_array_length_cname ("result", dim), array_length_type);
-				cparam_map.set (get_param_pos (d.carray_length_parameter_position + 0.01 * dim), cparam);
+				cparam_map.set (get_param_pos (get_ccode_array_length_pos (d) + 0.01 * dim), cparam);
 			}
 		} else if (d.return_type is DelegateType) {
 			// return delegate target if appropriate
@@ -338,7 +338,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 					} else {
 						clength = new CCodeIdentifier (get_parameter_array_length_cname (d_params.get (i), dim));
 					}
-					carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), clength);
+					carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), clength);
 				}
 			} else if (param.variable_type is DelegateType) {
 				var deleg_type = (DelegateType) param.variable_type;
@@ -364,7 +364,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 				} else {
 					clength = new CCodeIdentifier (get_array_length_cname ("result", dim));
 				}
-				carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), clength);
+				carg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), clength);
 			}
 		} else if (m.return_type is DelegateType) {
 			var deleg_type = (DelegateType) m.return_type;
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index ffa30cb..26b0b37 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -342,7 +342,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 								} else {
 									array_length_expr = get_array_length_cexpression (arg, dim);
 								}
-								carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), array_length_expr);
+								carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), array_length_expr);
 							}
 						} else if (param.variable_type is DelegateType) {
 							var deleg_type = (DelegateType) param.variable_type;
@@ -406,7 +406,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 								var temp_array_length = get_temp_variable (array_length_type);
 								emit_temp_var (temp_array_length);
 								append_array_length (arg, get_variable_cexpression (temp_array_length.name));
-								carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_lengths (arg).get (dim - 1)));
+								carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_lengths (arg).get (dim - 1)));
 							}
 						} else if (param.variable_type is DelegateType) {
 							var deleg_type = (DelegateType) param.variable_type;
@@ -490,7 +490,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 					emit_temp_var (temp_var);
 
-					out_arg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+					out_arg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
 
 					append_array_length (expr, temp_ref);
 				} else {
@@ -552,7 +552,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 
 					emit_temp_var (temp_var);
 
-					out_arg_map.set (get_param_pos (deleg.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+					out_arg_map.set (get_param_pos (get_ccode_array_length_pos (deleg) + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
 
 					append_array_length (expr, temp_ref);
 				} else {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index d29c47b..ef7a8ab 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -86,9 +86,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 
 			for (int dim = 1; dim <= array_type.rank; dim++) {
 				var cparam = new CCodeParameter (get_array_length_cname ("result", dim), array_length_type);
-				cparam_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), cparam);
+				cparam_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), cparam);
 				if (carg_map != null) {
-					carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (cparam.name));
+					carg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), get_variable_cexpression (cparam.name));
 				}
 			}
 		} else if (m.return_type is DelegateType) {



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