Fix generated C code when calling struct methods
authorJuerg Billeter <j@bitron.ch>
Wed, 16 Apr 2008 16:15:53 +0000 (16:15 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Wed, 16 Apr 2008 16:15:53 +0000 (16:15 +0000)
2008-04-16  Juerg Billeter  <j@bitron.ch>

* gobject/valaccodegeneratorinvocationexpression.vala:

  Fix generated C code when calling struct methods

svn path=/trunk/; revision=1245

ChangeLog
gobject/valaccodegeneratorinvocationexpression.vala

index b29fe31..29d9e15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2008-04-16  Jürg Billeter  <j@bitron.ch>
 
+       * gobject/valaccodegeneratorinvocationexpression.vala:
+
+         Fix generated C code when calling struct methods
+
+2008-04-16  Jürg Billeter  <j@bitron.ch>
+
        * gobject/valaccodegenerator.vala,
          gobject/valaccodegeneratorinvocationexpression.vala:
 
index 3528550..3b20b3d 100644 (file)
@@ -82,7 +82,20 @@ public class Vala.CCodeGenerator {
                        }
 
                        if (instance_expression_type.data_type is Struct && !((Struct) instance_expression_type.data_type).is_simple_type () && instance_expression_type.data_type != current_type_symbol) {
-                               instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance);
+                               if (instance is CCodeIdentifier) {
+                                       instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance);
+                               } else {
+                                       // if instance is e.g. a function call, we can't take the address of the expression
+                                       // (tmp = expr, &tmp)
+                                       var ccomma = new CCodeCommaExpression ();
+
+                                       var temp_var = get_temp_variable (instance_expression_type);
+                                       temp_vars.insert (0, temp_var);
+                                       ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_var.name), instance));
+                                       ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_var.name)));
+
+                                       instance = ccomma;
+                               }
                        }
 
                        // parent_symbol may be null for late bound methods