[vala] codegen: Use set_delegate_target for local variable access



commit 4bdcea830d293f2ccaf038dbd68a052054eb49eb
Author: Jürg Billeter <j bitron ch>
Date:   Sat Oct 9 18:16:32 2010 +0200

    codegen: Use set_delegate_target for local variable access

 codegen/valaccodedelegatemodule.vala     |   26 +-------------------------
 codegen/valaccodememberaccessmodule.vala |   13 +++++++++++++
 2 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 7dd9b39..2b698f1 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -154,7 +154,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 			}
 			return get_delegate_target (delegate_expr);
 		} else if (delegate_expr.symbol_reference != null) {
-			if (delegate_expr.symbol_reference is FormalParameter) {
+			if (delegate_expr.symbol_reference is FormalParameter || delegate_expr.symbol_reference is LocalVariable) {
 				if (get_delegate_target_destroy_notify (delegate_expr) != null) {
 					delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr);
 				}
@@ -168,30 +168,6 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
 				} else {
 					return target_expr;
 				}
-			} else if (delegate_expr.symbol_reference is LocalVariable) {
-				var local = (LocalVariable) delegate_expr.symbol_reference;
-				if (local.captured) {
-					// captured variables are stored on the heap
-					var block = (Block) local.parent_symbol;
-					delegate_target_destroy_notify = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
-					return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (local.name)));
-				} else if (current_method != null && current_method.coroutine) {
-					delegate_target_destroy_notify = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
-					return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name)));
-				} else {
-					var target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (local.name)));
-					if (expr_owned) {
-						delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
-					}
-					if (is_out) {
-						if (expr_owned) {
-							delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, delegate_target_destroy_notify);
-						}
-						return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
-					} else {
-						return target_expr;
-					}
-				}
 			} else if (delegate_expr.symbol_reference is Field) {
 				var field = (Field) delegate_expr.symbol_reference;
 				string target_cname = get_delegate_target_cname (field.get_cname ());
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index a997c09..a0d6115 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -433,6 +433,9 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					for (int dim = 1; dim <= array_type.rank; dim++) {
 						append_array_size (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_length_cname (get_variable_cname (local.name), dim)));
 					}
+				} else if (local.variable_type is DelegateType) {
+					set_delegate_target (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (local.name))));
+					set_delegate_target_destroy_notify (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name))));
 				}
 			} else {
 				set_cvalue (expr, get_variable_cexpression (local.name));
@@ -440,6 +443,16 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					for (int dim = 1; dim <= array_type.rank; dim++) {
 						append_array_size (expr, get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim)));
 					}
+				} else if (local.variable_type is DelegateType) {
+					if (current_method != null && current_method.coroutine) {
+						set_delegate_target (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name))));
+						set_delegate_target_destroy_notify (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name))));
+					} else {
+						set_delegate_target (expr, new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (local.name))));
+						if (expr.value_type.value_owned) {
+							set_delegate_target_destroy_notify (expr, new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (local.name))));
+						}
+					}
 				}
 
 				if (expr.parent_node is ReturnStatement &&



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