[vala/emit-let] codegen: Add not_in_coroutine convenience parameter to get an lvalue.



commit 7323d9ae8f094f7709a1ac4cf092f9dc2026640d
Author: Luca Bruno <lethalman88 gmail com>
Date:   Tue Jan 18 10:44:33 2011 +0100

    codegen: Add not_in_coroutine convenience parameter to get an lvalue.

 codegen/valaccodebasemodule.vala         |   32 +++-------------------
 codegen/valaccodememberaccessmodule.vala |   41 +++++++++++++++++++++--------
 2 files changed, 34 insertions(+), 39 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5a71851..a7cd475 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1704,17 +1704,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 
 		if (requires_destroy (param_type) && !is_unowned_delegate) {
-			bool old_coroutine = false;
-			if (current_method != null) {
-				old_coroutine = current_method.coroutine;
-				current_method.coroutine = false;
-			}
-
-			free_block.add_statement (new CCodeExpressionStatement (get_unref_expression_ (param)));
-
-			if (old_coroutine) {
-				current_method.coroutine = true;
-			}
+			free_block.add_statement (new CCodeExpressionStatement (destroy_value (get_symbol_cvalue (param, null, true))));
 		}
 	}
 
@@ -1794,20 +1784,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			// free in reverse order
 			for (int i = local_vars.size - 1; i >= 0; i--) {
 				var local = local_vars[i];
-				if (local.captured) {
-					if (requires_destroy (local.variable_type)) {
-						bool old_coroutine = false;
-						if (current_method != null) {
-							old_coroutine = current_method.coroutine;
-							current_method.coroutine = false;
-						}
-
-						free_block.add_statement (new CCodeExpressionStatement (get_unref_expression_ (local)));
-
-						if (old_coroutine) {
-							current_method.coroutine = true;
-						}
-					}
+				if (local.captured && requires_destroy (local.variable_type)) {
+					free_block.add_statement (new CCodeExpressionStatement(destroy_value (get_symbol_cvalue (local, null, true))));
 				}
 			}
 
@@ -3183,7 +3161,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 			for (int dim = 1; dim <= array_type.rank; dim++) {
 				var len_l = get_result_cexpression (get_array_length_cname ("result", dim));
-				if (!is_in_coroutine ())
+				if (!is_in_coroutine ()) {
 					len_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, len_l);
 				}
 				var len_r = get_array_length_cexpression (stmt.return_expression, dim);
@@ -3500,7 +3478,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
-	public virtual TargetValue get_symbol_cvalue (Symbol sym, CCodeExpression? inner = null) {
+	public virtual TargetValue get_symbol_cvalue (Symbol sym, CCodeExpression? inner = null, bool not_in_coroutine = false) {
 		assert_not_reached ();
 	}
 
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 74545e0..10702df 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -521,8 +521,13 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		}
 	}
 
-	/* Returns lvalue access to the given local variable */
-	public TargetValue get_local_cvalue (LocalVariable local) {
+	/**
+	 * Returns lvalue access to the given local variable.
+	 *
+	 * @param not_in_coroutine enforces not to be in a coroutine
+	 * @return the computed C lvalue
+	 */
+	public TargetValue get_local_cvalue (LocalVariable local, bool not_in_coroutine = false) {
 		var result = new GLibValue (local.variable_type.copy ());
 
 		var array_type = local.variable_type as ArrayType;
@@ -560,7 +565,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					result.array_size_cvalue = get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
 				}
 			} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
-				if (is_in_coroutine ()) {
+				if (is_in_coroutine () && !not_in_coroutine) {
 					result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name)));
 					result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
 				} else {
@@ -575,10 +580,15 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		return result;
 	}
 
-	/* Returns access values to the given parameter */
-	public TargetValue get_parameter_cvalue (Parameter param) {
+	/**
+	 * Returns lvalue access to the given local variable.
+	 *
+	 * @param not_in_coroutine enforces not to be in a coroutine
+	 * @return the computed C lvalue
+	 */
+	public TargetValue get_parameter_cvalue (Parameter param, bool not_in_coroutine = false) {
 		var result = new GLibValue (param.variable_type.copy ());
-		if (param.captured || is_in_coroutine ()) {
+		if (param.captured || (is_in_coroutine () && !not_in_coroutine)) {
 			result.value_type.value_owned = true;
 		}
 
@@ -586,7 +596,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		var delegate_type = result.value_type as DelegateType;
 
 		if (param.name == "this") {
-			if (is_in_coroutine ()) {
+			if (is_in_coroutine () && !not_in_coroutine) {
 				// use closure
 				result.cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "self");
 			} else {
@@ -615,7 +625,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 					result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (param.name)));
 					result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
 				}
-			} else if (is_in_coroutine ()) {
+			} else if (is_in_coroutine () && !not_in_coroutine) {
 				// use closure
 				result.cvalue = get_variable_cexpression (param.name);
 				if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
@@ -683,12 +693,18 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		return value;
 	}
 
-	/* Returns lvalue access to the given symbol */
-	public override TargetValue get_symbol_cvalue (Symbol sym, CCodeExpression? inner = null) {
+	/**
+	 * Returns lvalue access to the given symbol.
+	 *
+	 * @param not_in_coroutine enforces not to be in a coroutine for local variables and parameters
+	 * @param inner instance expression for accessing fields or properties
+	 * @return the computed C lvalue
+	 */
+	public override TargetValue get_symbol_cvalue (Symbol sym, CCodeExpression? inner = null, bool not_in_coroutine = false) {
 		if (sym is LocalVariable) {
-			return get_local_cvalue ((LocalVariable) sym);
+			return get_local_cvalue ((LocalVariable) sym, not_in_coroutine);
 		} else if (sym is Parameter) {
-			return get_parameter_cvalue ((Parameter) sym);
+			return get_parameter_cvalue ((Parameter) sym, not_in_coroutine);
 		} else {
 			assert_not_reached ();
 		}
@@ -704,6 +720,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		return load_variable (local, result);
 	}
 
+	/* Returns unowned access to the given parameter */
 	public TargetValue load_parameter (Parameter param) {
 		var result = (GLibValue) get_parameter_cvalue (param);
 		if (result.value_type is DelegateType) {



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