[vala/wip/attributes: 27/119] codegen: Add get_ccode_instance_pos



commit 04c927b2166b19276109220abf9caa4c9c9269a6
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jun 28 16:10:24 2011 +0200

    codegen: Add get_ccode_instance_pos

 codegen/valaccodebasemodule.vala       |   24 +++++++++++++++++++++---
 codegen/valaccodedelegatemodule.vala   |    4 ++--
 codegen/valaccodemethodcallmodule.vala |   16 ++++++++--------
 codegen/valaccodemethodmodule.vala     |   10 +++++-----
 4 files changed, 36 insertions(+), 18 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2d5d015..c7aaa0d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4097,7 +4097,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				creation_call = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_name (m)));
 			}
 
-			if ((st != null && !st.is_simple_type ()) && !(m.cinstance_parameter_position < 0)) {
+			if ((st != null && !st.is_simple_type ()) && !(get_ccode_instance_pos (m) < 0)) {
 				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
 			} else if (st != null && get_ccode_name (st) == "va_list") {
 				creation_call.add_argument (instance);
@@ -4227,7 +4227,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				last_pos = min_pos;
 			}
 
-			if ((st != null && !st.is_simple_type ()) && m.cinstance_parameter_position < 0) {
+			if ((st != null && !st.is_simple_type ()) && get_ccode_instance_pos (m) < 0) {
 				// instance parameter is at the end in a struct creation method
 				creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance));
 			}
@@ -4961,7 +4961,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 	public override void visit_lambda_expression (LambdaExpression lambda) {
 		// use instance position from delegate
 		var dt = (DelegateType) lambda.target_type;
-		lambda.method.cinstance_parameter_position = dt.delegate_symbol.cinstance_parameter_position;
+		foreach (var attr in lambda.attributes) {
+			var copy = new Attribute (attr.name, attr.source_reference);
+			foreach (var arg in attr.args) {
+				copy.add_argument (arg, attr.args[arg]);
+			}
+			lambda.method.attributes.append (copy);
+		}
 
 		lambda.accept_children (this);
 
@@ -5699,6 +5705,18 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return true;
 	}
 
+	public static double get_ccode_instance_pos (CodeNode node) {
+		var a = node.get_attribute ("CCode");
+		if (a != null && a.has_argument ("instance_pos")) {
+			return a.get_double ("instance_pos");
+		}
+		if (node is Delegate) {
+			return -2;
+		} else {
+			return 0;
+		}
+	}
+
 	public override void visit_class (Class cl) {
 	}
 
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index aa41536..761de09 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -211,7 +211,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 
 		if (d.has_target) {
 			var cparam = new CCodeParameter ("self", "gpointer");
-			cparam_map.set (get_param_pos (d.cinstance_parameter_position), cparam);
+			cparam_map.set (get_param_pos (get_ccode_instance_pos (d)), cparam);
 		}
 
 		if (d.sender_type != null) {
@@ -300,7 +300,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 					i = 1;
 				}
 			}
-			carg_map.set (get_param_pos (m.cinstance_parameter_position), arg);
+			carg_map.set (get_param_pos (get_ccode_instance_pos (m)), arg);
 		}
 
 		bool first = true;
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index ab348f4..ce9da2e 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -175,8 +175,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 				instance = new CCodeIdentifier ("_data_");
 			}
 
-			in_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
-			out_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
+			in_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+			out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
 		} else if (m != null && m.binding == MemberBinding.INSTANCE && !(m is CreationMethod)) {
 			instance = get_cvalue (ma.inner);
 
@@ -203,8 +203,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 				}
 			}
 
-			in_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
-			out_arg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
+			in_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
+			out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), instance);
 		} else if (m != null && m.binding == MemberBinding.CLASS) {
 			var cl = (Class) m.parent_symbol;
 			var cast = new CCodeFunctionCall (new CCodeIdentifier (cl.get_upper_case_cname (null) + "_CLASS"));
@@ -228,8 +228,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			}
 
 			cast.add_argument (klass);
-			in_arg_map.set (get_param_pos (m.cinstance_parameter_position), cast);
-			out_arg_map.set (get_param_pos (m.cinstance_parameter_position), cast);
+			in_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), cast);
+			out_arg_map.set (get_param_pos (get_ccode_instance_pos (m)), cast);
 		}
 
 		if (m != null && m.has_generic_type_parameter) {
@@ -604,8 +604,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
 			var d = deleg_type.delegate_symbol;
 			if (d.has_target) {
 				CCodeExpression delegate_target_destroy_notify;
-				in_arg_map.set (get_param_pos (d.cinstance_parameter_position), get_delegate_target_cexpression (expr.call, out delegate_target_destroy_notify));
-				out_arg_map.set (get_param_pos (d.cinstance_parameter_position), get_delegate_target_cexpression (expr.call, out delegate_target_destroy_notify));
+				in_arg_map.set (get_param_pos (get_ccode_instance_pos (d)), get_delegate_target_cexpression (expr.call, out delegate_target_destroy_notify));
+				out_arg_map.set (get_param_pos (get_ccode_instance_pos (d)), get_delegate_target_cexpression (expr.call, out delegate_target_destroy_notify));
 			}
 		}
 
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 13fc80a..7b9afc2 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -764,11 +764,11 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 			var closure_block = current_closure_block;
 			int block_id = get_block_id (closure_block);
 			var instance_param = new CCodeParameter ("_data%d_".printf (block_id), "Block%dData*".printf (block_id));
-			cparam_map.set (get_param_pos (m.cinstance_parameter_position), instance_param);
+			cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), instance_param);
 		} else if (m.parent_symbol is Class && m is CreationMethod) {
 			var cl = (Class) m.parent_symbol;
 			if (!cl.is_compact && vcall == null) {
-				cparam_map.set (get_param_pos (m.cinstance_parameter_position), new CCodeParameter ("object_type", "GType"));
+				cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), new CCodeParameter ("object_type", "GType"));
 			}
 		} else if (m.binding == MemberBinding.INSTANCE || (m.parent_symbol is Struct && m is CreationMethod)) {
 			TypeSymbol parent_type = find_parent_type (m);
@@ -801,13 +801,13 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 					instance_param = new CCodeParameter ("self", get_ccode_name (this_type));
 				}
 			}
-			cparam_map.set (get_param_pos (m.cinstance_parameter_position), instance_param);
+			cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), instance_param);
 		} else if (m.binding == MemberBinding.CLASS) {
 			TypeSymbol parent_type = find_parent_type (m);
 			DataType this_type;
 			this_type = new ClassType ((Class) parent_type);
 			var class_param = new CCodeParameter ("klass", get_ccode_name (this_type));
-			cparam_map.set (get_param_pos (m.cinstance_parameter_position), class_param);
+			cparam_map.set (get_param_pos (get_ccode_instance_pos (m)), class_param);
 		}
 
 		if (is_gtypeinstance_creation_method (m)) {
@@ -913,7 +913,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
 			cname = cname.substring (0, cname.length - "_async".length);
 		}
 		var vcall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, cname + suffix));
-		carg_map.set (get_param_pos (m.cinstance_parameter_position), new CCodeIdentifier ("self"));
+		carg_map.set (get_param_pos (get_ccode_instance_pos (m)), new CCodeIdentifier ("self"));
 
 		generate_cparameters (m, cfile, cparam_map, vfunc, null, carg_map, vcall, direction);
 



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