[vala] Fix nested struct expression as method argument



commit 5f275fbc05603c38a32e9a80cc2fa922381c1d7d
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Sat Jan 23 17:05:25 2010 +0100

    Fix nested struct expression as method argument
    
    Fixes bug 580046.

 ccode/valaccodecommaexpression.vala      |    6 +++++-
 codegen/valaccodebasemodule.vala         |   10 +++++++++-
 codegen/valaccodememberaccessmodule.vala |   10 +++++++++-
 3 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/ccode/valaccodecommaexpression.vala b/ccode/valaccodecommaexpression.vala
index 79f78ae..7f16ffd 100644
--- a/ccode/valaccodecommaexpression.vala
+++ b/ccode/valaccodecommaexpression.vala
@@ -1,6 +1,6 @@
 /* valaccodecommaexpression.vala
  *
- * Copyright (C) 2006-2008  Jürg Billeter
+ * Copyright (C) 2006-2010  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -37,6 +37,10 @@ public class Vala.CCodeCommaExpression : CCodeExpression {
 		inner.add (expr);
 	}
 
+	public void set_expression (int index, CCodeExpression expr) {
+		inner[index] = expr;
+	}
+
 	public List<CCodeExpression> get_inner () {
 		return new ReadOnlyList<CCodeExpression> (inner);
 	}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index e1b6bdb..428fdad 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4373,7 +4373,15 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 	}
 
 	public override void visit_addressof_expression (AddressofExpression expr) {
-		expr.ccodenode = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, (CCodeExpression) expr.inner.ccodenode);
+		if (expr.inner.ccodenode is CCodeCommaExpression) {
+			var ccomma = expr.inner.ccodenode as CCodeCommaExpression;
+			var inner = ccomma.get_inner ();
+			var last = inner.get (inner.size - 1);
+			ccomma.set_expression (inner.size - 1, new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, (CCodeExpression) last));
+			expr.ccodenode = ccomma;
+		} else {
+			expr.ccodenode = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, (CCodeExpression) expr.inner.ccodenode);
+		}
 	}
 
 	public override void visit_reference_transfer_expression (ReferenceTransferExpression expr) {
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index b498440..3ebb4bf 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -126,7 +126,15 @@ internal class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 				if (instance_target_type.data_type.is_reference_type () || (expr.inner != null && expr.inner.value_type is PointerType)) {
 					expr.ccodenode = new CCodeMemberAccess.pointer (inst, f.get_cname ());
 				} else {
-					expr.ccodenode = new CCodeMemberAccess (inst, f.get_cname ());
+					if (inst is CCodeCommaExpression) {
+						var ccomma = inst as CCodeCommaExpression;
+						var inner = ccomma.get_inner ();
+						var last = inner.get (inner.size - 1);
+						ccomma.set_expression (inner.size - 1, new CCodeMemberAccess (last, f.get_cname ()));
+						expr.ccodenode = ccomma;
+					} else {
+						expr.ccodenode = new CCodeMemberAccess (inst, f.get_cname ());
+					}
 				}
 			} else if (f.binding == MemberBinding.CLASS) {
 				var cl = (Class) f.parent_symbol;



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