[vala/emit-j] codegen: Use destroy_variable in store_*



commit 83c2095d821724234d667f6ae4934ae9e1cd7800
Author: Jürg Billeter <j bitron ch>
Date:   Wed Feb 16 17:19:59 2011 +0100

    codegen: Use destroy_variable in store_*

 codegen/valaccodeassignmentmodule.vala   |   24 +++++++++++++++++++-----
 codegen/valaccodememberaccessmodule.vala |    2 +-
 codegen/valadovaassignmentmodule.vala    |    4 ++++
 codegen/valadovamemberaccessmodule.vala  |    2 +-
 vala/valaassignment.vala                 |   14 +++++++++-----
 vala/valacodegenerator.vala              |    4 ++++
 6 files changed, 38 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 136712e..83552a6 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -170,11 +170,6 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 	}
 
 	void store_variable (Variable variable, TargetValue lvalue, TargetValue value, bool initializer) {
-		if (!initializer && requires_destroy (variable.variable_type)) {
-			/* unref old value */
-			ccode.add_expression (destroy_value (lvalue));
-		}
-
 		ccode.add_assignment (get_cvalue_ (lvalue), get_cvalue_ (value));
 
 		var array_type = variable.variable_type as ArrayType;
@@ -221,10 +216,29 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 	}
 
 	public override void store_local (LocalVariable local, TargetValue value, bool initializer) {
+		if (!initializer && requires_destroy (local.variable_type)) {
+			/* unref old value */
+			ccode.add_expression (destroy_local (local));
+		}
+
 		store_variable (local, get_local_cvalue (local), value, initializer);
 	}
 
 	public override void store_parameter (Parameter param, TargetValue value) {
+		if (requires_destroy (param.variable_type)) {
+			/* unref old value */
+			ccode.add_expression (destroy_parameter (param));
+		}
+
 		store_variable (param, get_parameter_cvalue (param), value, false);
 	}
+
+	public override void store_field (Field field, Expression? instance, TargetValue value) {
+		if (requires_destroy (field.variable_type)) {
+			/* unref old value */
+			ccode.add_expression (destroy_field (field, instance));
+		}
+
+		store_variable (field, get_field_cvalue (field, instance), value, false);
+	}
 }
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 97fedd8..1ea26bc 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -694,7 +694,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 	}
 
 	/* Returns unowned access to the given field */
-	public TargetValue load_field (Field field, Expression? instance) {
+	public override TargetValue load_field (Field field, Expression? instance) {
 		return load_variable (field, get_field_cvalue (field, instance));
 	}
 }
diff --git a/codegen/valadovaassignmentmodule.vala b/codegen/valadovaassignmentmodule.vala
index 1338b02..e212314 100644
--- a/codegen/valadovaassignmentmodule.vala
+++ b/codegen/valadovaassignmentmodule.vala
@@ -148,4 +148,8 @@ public class Vala.DovaAssignmentModule : DovaMemberAccessModule {
 	public override void store_parameter (Parameter param, TargetValue value) {
 		store_variable (param, get_parameter_cvalue (param), value, false);
 	}
+
+	public override void store_field (Field field, Expression? instance, TargetValue value) {
+		store_variable (field, get_field_cvalue (field, instance), value, false);
+	}
 }
diff --git a/codegen/valadovamemberaccessmodule.vala b/codegen/valadovamemberaccessmodule.vala
index 7cc3d67..8538db0 100644
--- a/codegen/valadovamemberaccessmodule.vala
+++ b/codegen/valadovamemberaccessmodule.vala
@@ -295,7 +295,7 @@ public abstract class Vala.DovaMemberAccessModule : DovaControlFlowModule {
 		return load_variable (param, get_parameter_cvalue (param));
 	}
 
-	public TargetValue load_field (Field field, Expression? instance) {
+	public override TargetValue load_field (Field field, Expression? instance) {
 		return load_variable (field, get_field_cvalue (field, instance));
 	}
 }
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 199226f..9fb81c6 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -466,14 +466,14 @@ public class Vala.Assignment : Expression {
 			var field = ma.symbol_reference as Field;
 			var property = ma.symbol_reference as Property;
 
-			bool instance = (field != null && field.binding == MemberBinding.INSTANCE)
-				|| (property != null && property.binding == MemberBinding.INSTANCE);
+			bool instance = (field != null && field.binding != MemberBinding.STATIC)
+				|| (property != null && property.binding != MemberBinding.STATIC);
 
 			if (operator == AssignmentOperator.SIMPLE &&
-			    (local != null || param != null) &&
+			    (local != null || param != null || field != null) &&
 			    !is_array_add ()) {
 				// visit_assignment not necessary
-				if (instance) {
+				if (instance && ma.inner != null) {
 					ma.inner.emit (codegen);
 				}
 
@@ -484,6 +484,8 @@ public class Vala.Assignment : Expression {
 					codegen.store_local (local, new_value, false);
 				} else if (param != null) {
 					codegen.store_parameter (param, new_value);
+				} else if (field != null) {
+					codegen.store_field (field, instance ? ma.inner : null, new_value);
 				}
 
 				// when load_variable is changed to use temporary
@@ -493,6 +495,8 @@ public class Vala.Assignment : Expression {
 					target_value = codegen.load_local (local);
 				} else if (param != null) {
 					target_value = codegen.load_parameter (param);
+				} else if (field != null) {
+					target_value = codegen.load_field (field, instance ? ma.inner : null);
 				}
 
 				codegen.visit_expression (this);
@@ -505,7 +509,7 @@ public class Vala.Assignment : Expression {
 				// should be removed when moving codegen from
 				// visit_assignment to emit_store_field
 				ma.emit (codegen);
-			} else if (instance) {
+			} else if (instance && ma.inner != null) {
 				ma.inner.emit (codegen);
 			}
 		} else if (ea != null) {
diff --git a/vala/valacodegenerator.vala b/vala/valacodegenerator.vala
index d3ca065..a768032 100644
--- a/vala/valacodegenerator.vala
+++ b/vala/valacodegenerator.vala
@@ -41,4 +41,8 @@ public abstract class Vala.CodeGenerator : CodeVisitor {
 	public abstract TargetValue load_parameter (Parameter param);
 
 	public abstract void store_parameter (Parameter param, TargetValue value);
+
+	public abstract TargetValue load_field (Field field, Expression? instance);
+
+	public abstract void store_field (Field field, Expression? instance, TargetValue value);
 }



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