[vala/wip/effectfree: 8/8] codegen: Use temporary variables in member access for possible side effects



commit e5e890ef0385d954896a39574e75e69e6d42b16e
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jun 15 13:27:21 2011 +0200

    codegen: Use temporary variables in member access for possible side effects

 codegen/valaccodememberaccessmodule.vala |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 443992f..2944d03 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -23,6 +23,14 @@
  */
 
 public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
+	private static unowned CodeNode get_outer_expression_parent (Expression expr) {
+		unowned CodeNode cur = expr.parent_node;
+		while (cur is Expression) {
+			cur = cur.parent_node;
+		}
+		return cur;
+	}
+
 	public override void visit_member_access (MemberAccess expr) {
 		CCodeExpression pub_inst = null;
 	
@@ -326,6 +334,14 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 
 				// don't unref variable
 				local.active = false;
+			} else if (!expr.lvalue && !expr.target_value.value_type.is_real_non_null_struct_type () && !(expr.target_value.value_type is ArrayType && ((ArrayType) expr.target_value.value_type).inline_allocated)) {
+				var defined_variables = new ArrayList<LocalVariable> ();
+				get_outer_expression_parent(expr).get_defined_variables (defined_variables);
+				if (defined_variables.contains (local)) {
+					// statement may have side effects on this variable
+					var temp_value = create_temp_value (expr.target_value.value_type, expr.target_value, expr);
+					expr.target_value = temp_value;
+				}
 			}
 		} else if (expr.symbol_reference is Parameter) {
 			var param = (Parameter) expr.symbol_reference;



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