[vala/emit-let: 4/4] codegen: Add convenience load_this_parameter method.



commit 28c4b9fd287f447853b86e88f4e2429c6587b21f
Author: Luca Bruno <lucabru src gnome org>
Date:   Tue Jan 18 23:46:44 2011 +0100

    codegen: Add convenience load_this_parameter method.

 codegen/valaccodebasemodule.vala         |   51 +++++++----------------------
 codegen/valaccodememberaccessmodule.vala |   16 +++++++++
 codegen/valagasyncmodule.vala            |    6 +---
 3 files changed, 30 insertions(+), 43 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 118d99f..19834df 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -968,24 +968,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				if (f.variable_type is ArrayType && !f.no_array_length &&
 				    f.initializer is ArrayCreationExpression) {
 					var array_type = (ArrayType) f.variable_type;
-					var this_access = new MemberAccess.simple ("this");
-					this_access.value_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
-					set_cvalue (this_access, new CCodeIdentifier ("self"));
-					var ma = new MemberAccess (this_access, f.name);
-					ma.symbol_reference = f;
-					ma.value_type = f.variable_type.copy ();
-					visit_member_access (ma);
+					var this_value = load_this_parameter (get_data_type_for_symbol ((TypeSymbol) f.parent_symbol));
+					var field_value = get_variable_cvalue (f, this_value);
 
 					List<Expression> sizes = ((ArrayCreationExpression) f.initializer).get_sizes ();
 					for (int dim = 1; dim <= array_type.rank; dim++) {
-						var array_len_lhs = get_array_length_cexpression (ma, dim);
+						var array_len_lhs = get_array_length_cvalue (field_value, dim);
 						var size = sizes[dim - 1];
 						ccode.add_assignment (array_len_lhs, get_cvalue (size));
 					}
 
 					if (array_type.rank == 1 && f.is_internal_symbol ()) {
-						var lhs_array_size = get_array_size_cvalue (ma.target_value);
-						var rhs_array_len = get_array_length_cexpression (ma, 1);
+						var lhs_array_size = get_array_size_cvalue (field_value);
+						var rhs_array_len = get_array_length_cvalue (field_value, 1);
 						ccode.add_assignment (lhs_array_size, rhs_array_len);
 					}
 				}
@@ -1001,23 +996,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			
 			if (requires_destroy (f.variable_type) && instance_finalize_context != null) {
 				push_context (instance_finalize_context);
-
-				var this_access = new MemberAccess.simple ("this");
-				this_access.value_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
-
-				var field_st = f.parent_symbol as Struct;
-				if (field_st != null && !field_st.is_simple_type ()) {
-					set_cvalue (this_access, new CCodeIdentifier ("(*self)"));
-				} else {
-					set_cvalue (this_access, new CCodeIdentifier ("self"));
-				}
-
-				var ma = new MemberAccess (this_access, f.name);
-				ma.symbol_reference = f;
-				ma.value_type = f.variable_type.copy ();
-				visit_member_access (ma);
-				ccode.add_expression (get_unref_expression (lhs, f.variable_type, ma));
-
+				var type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
+				ccode.add_expression (get_unref_expression_ (f, load_this_parameter (type)));
 				pop_context ();
 			}
 		} else if (f.binding == MemberBinding.CLASS)  {
@@ -3494,6 +3474,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		}
 	}
 
+	public virtual TargetValue load_this_parameter (DataType type) {
+		assert_not_reached ();
+	}
+
 	public virtual TargetValue get_variable_cvalue (Variable variable, TargetValue? inner = null, bool not_in_coroutine = false) {
 		assert_not_reached ();
 	}
@@ -5591,17 +5575,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		foreach (Field f in st.get_fields ()) {
 			if (f.binding == MemberBinding.INSTANCE) {
 				if (requires_destroy (f.variable_type)) {
-					var lhs = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), f.get_cname ());
-
-					var this_access = new MemberAccess.simple ("this");
-					this_access.value_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
-					set_cvalue (this_access, new CCodeIdentifier ("(*self)"));
-
-					var ma = new MemberAccess (this_access, f.name);
-					ma.symbol_reference = f;
-					ma.value_type = f.variable_type.copy ();
-					visit_member_access (ma);
-					ccode.add_expression (get_unref_expression (lhs, f.variable_type, ma));
+					var this_value = load_this_parameter (get_data_type_for_symbol ((TypeSymbol) f.parent_symbol));
+					ccode.add_expression (get_unref_expression_ (f, this_value));
 				}
 			}
 		}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index ad6155f..f2b66c5 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -790,4 +790,20 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 		result.value_type.value_owned = false;
 		return load_variable (field, result);
 	}
+
+	public override TargetValue load_this_parameter (DataType type) {
+		var result = new GLibValue (type);
+		if (is_in_coroutine ()) {
+			// use closure
+			result.cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "self");
+		} else {
+			var st = type.data_type as Struct;
+			if (st != null && !st.is_simple_type ()) {
+				result.cvalue = new CCodeIdentifier ("(*self)");
+			} else {
+				result.cvalue = new CCodeIdentifier ("self");
+			}
+		}
+		return result;
+	}
 }
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index d4ce037..a638e39 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -128,11 +128,7 @@ public class Vala.GAsyncModule : GSignalModule {
 			this_type.value_owned = true;
 
 			if (requires_destroy (this_type)) {
-				var ma = new MemberAccess.simple ("this");
-				ma.symbol_reference = m.this_parameter;
-				ma.value_type = m.this_parameter.variable_type.copy ();
-				visit_member_access (ma);
-				freeblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "self"), m.this_parameter.variable_type, ma)));
+				freeblock.add_statement (new CCodeExpressionStatement (get_unref_expression_ (m.this_parameter)));
 			}
 		}
 



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