[vala/wip/attributes: 32/100] codegen: Add get_ccode_pos



commit fdf80806e2c9e2844041e9281889e5ea8597b709
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 18:30:01 2011 +0200

    codegen: Add get_ccode_pos

 codegen/valaccodearraymodule.vala      |    4 +-
 codegen/valaccodebasemodule.vala       |   33 ++++++++++++++++++++++++++++---
 codegen/valaccodedelegatemodule.vala   |    8 +++---
 codegen/valaccodemethodcallmodule.vala |    2 +-
 codegen/valaccodemethodmodule.vala     |    4 +-
 codegen/valagtypemodule.vala           |    4 +-
 6 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 2776811..9de2446 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -727,9 +727,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 		generate_type_declaration (array_type.element_type, decl_space);
 
-		cparam_map.set (get_param_pos (param.cparameter_position), main_cparam);
+		cparam_map.set (get_param_pos (get_ccode_pos (param)), main_cparam);
 		if (carg_map != null) {
-			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
+			carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
 		}
 
 		if (!get_ccode_no_array_length (param)) {
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 3a08c24..7726c30 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4177,7 +4177,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 						cexpr = handle_struct_argument (null, arg, cexpr);
 					}
 
-					arg_pos = get_param_pos (param.cparameter_position, ellipsis);
+					arg_pos = get_param_pos (get_ccode_pos (param), ellipsis);
 				} else {
 					// default argument position
 					cexpr = handle_struct_argument (null, arg, cexpr);
@@ -4206,7 +4206,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				 * parameter yet */
 				param.initializer.emit (this);
 			
-				carg_map.set (get_param_pos (param.cparameter_position), get_cvalue (param.initializer));
+				carg_map.set (get_param_pos (get_ccode_pos (param)), get_cvalue (param.initializer));
 				i++;
 			}
 
@@ -5732,7 +5732,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 		if (node is Parameter) {
 			var param = (Parameter) node;
-			return param.cparameter_position + 0.1;
+			return get_ccode_pos (param) + 0.1;
 		} else {
 			return -3;
 		}
@@ -5745,12 +5745,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 		if (node is Parameter) {
 			var param = (Parameter) node;
-			return param.cparameter_position + 0.1;
+			return get_ccode_pos (param) + 0.1;
 		} else {
 			return -3;
 		}
 	}
 
+	public static double get_ccode_pos (Parameter param) {
+		return get_ccode_attribute(param).pos;
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
@@ -6294,6 +6298,23 @@ public class Vala.CCodeAttribute : AttributeCache {
 		}
 	}
 
+	public double pos {
+		get {
+			if (_pos == null) {
+				var param = (Parameter) node;
+				var sym = param.parent_symbol;
+				if (sym is Method) {
+					_pos = ((Method) sym).get_parameters().index_of (param) + 1;
+				} else if (sym is Delegate) {
+					_pos = ((Delegate) sym).get_parameters().index_of (param) + 1;
+				} else if (sym is Signal) {
+					_pos = ((Signal) sym).get_parameters().index_of (param) + 1;
+				}
+			}
+			return _pos;
+		}
+	}
+
 	public bool no_array_length { get; private set; }
 	public string? array_length_type { get; private set; }
 
@@ -6317,6 +6338,7 @@ public class Vala.CCodeAttribute : AttributeCache {
 	private string _take_value_function;
 	private string _param_spec_function;
 	private string _default_value;
+	private double? _pos;
 
 	public CCodeAttribute (CodeNode node) {
 		this.node = node;
@@ -6359,6 +6381,9 @@ public class Vala.CCodeAttribute : AttributeCache {
 				no_array_length = !attr.get_bool ("array_length");
 			}
 			array_length_type = attr.get_string ("array_length_type");
+			if (attr.has_argument ("pos")) {
+				_pos = attr.get_double ("pos");
+			}
 		}
 	}
 
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index fe78e3e..52eca76 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -313,7 +313,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 		foreach (Parameter param in m.get_parameters ()) {
 			if (first && d.sender_type != null && m.get_parameters ().size == d.get_parameters ().size + 1) {
 				// sender parameter
-				carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier ("_sender"));
+				carg_map.set (get_param_pos (get_ccode_pos (param)), new CCodeIdentifier ("_sender"));
 
 				first = false;
 				continue;
@@ -321,7 +321,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 			CCodeExpression arg;
 			arg = new CCodeIdentifier (get_variable_cname (d_params.get (i).name));
-			carg_map.set (get_param_pos (param.cparameter_position), arg);
+			carg_map.set (get_param_pos (get_ccode_pos (param)), arg);
 
 			// handle array arguments
 			if (!get_ccode_no_array_length (param) && param.variable_type is ArrayType) {
@@ -468,9 +468,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 		var main_cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
 
-		cparam_map.set (get_param_pos (param.cparameter_position), main_cparam);
+		cparam_map.set (get_param_pos (get_ccode_pos (param)), main_cparam);
 		if (carg_map != null) {
-			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
+			carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
 		}
 
 		if (param.variable_type is DelegateType) {
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 6d30f17..9cc3573 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -432,7 +432,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 				} else {
 					cexpr = handle_struct_argument (null, arg, cexpr);
 				}
-				arg_pos = get_param_pos (param.cparameter_position, ellipsis);
+				arg_pos = get_param_pos (get_ccode_pos (param), ellipsis);
 			} else {
 				// default argument position
 				cexpr = handle_struct_argument (null, arg, cexpr);
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 91dce2b..c24418d 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -751,9 +751,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 			cparam = new CCodeParameter.with_ellipsis ();
 		}
 
-		cparam_map.set (get_param_pos (param.cparameter_position, param.ellipsis), cparam);
+		cparam_map.set (get_param_pos (get_ccode_pos (param), param.ellipsis), cparam);
 		if (carg_map != null && !param.ellipsis) {
-			carg_map.set (get_param_pos (param.cparameter_position, param.ellipsis), get_variable_cexpression (param.name));
+			carg_map.set (get_param_pos (get_ccode_pos (param), param.ellipsis), get_variable_cexpression (param.name));
 		}
 
 		return cparam;
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 122985c..f0ef83c 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -39,9 +39,9 @@ public class Vala.GTypeModule : GErrorModule {
 
 		var cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
 
-		cparam_map.set (get_param_pos (param.cparameter_position), cparam);
+		cparam_map.set (get_param_pos (get_ccode_pos (param)), cparam);
 		if (carg_map != null) {
-			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
+			carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
 		}
 
 		return cparam;



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