add pointer to integer conversion in foreach statements, fixes bug 433288
authorJürg Billeter <j@bitron.ch>
Mon, 30 Apr 2007 07:38:03 +0000 (07:38 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 30 Apr 2007 07:38:03 +0000 (07:38 +0000)
2007-04-30  Jürg Billeter  <j@bitron.ch>

* vala/valacodegenerator.vala: add pointer to integer conversion in
  foreach statements, fixes bug 433288

svn path=/trunk/; revision=289

vala/ChangeLog
vala/vala/valacodegenerator.vala

index 16978c0..f66389d 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-30  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valacodegenerator.vala: add pointer to integer conversion in
+         foreach statements, fixes bug 433288
+
 2007-04-24  Jürg Billeter  <j@bitron.ch>
 
        * vapi/glib-2.0.vala: add g_bit_nth_lsf, g_bit_nth_msf, and
index 394127f..4b79237 100644 (file)
@@ -2638,9 +2638,25 @@ public class Vala.CodeGenerator : CodeVisitor {
                        cblock.add_statement (citdecl);
                        
                        var cbody = new CCodeBlock ();
-                       
+
+                       CCodeExpression element_expr = new CCodeMemberAccess.pointer (new CCodeIdentifier (it_name), "data");
+
+                       /* cast pointer to actual type if appropriate */
+                       if (stmt.type_reference.data_type is Struct) {
+                               var st = (Struct) stmt.type_reference.data_type;
+                               if (st == uint_type.data_type) {
+                                       var cconv = new CCodeFunctionCall (new CCodeIdentifier ("GPOINTER_TO_UINT"));
+                                       cconv.add_argument (element_expr);
+                                       element_expr = cconv;
+                               } else if (st == bool_type.data_type || st.is_integer_type ()) {
+                                       var cconv = new CCodeFunctionCall (new CCodeIdentifier ("GPOINTER_TO_INT"));
+                                       cconv.add_argument (element_expr);
+                                       element_expr = cconv;
+                               }
+                       }
+
                        var cdecl = new CCodeDeclaration (stmt.type_reference.get_cname ());
-                       cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (stmt.variable_name, new CCodeMemberAccess.pointer (new CCodeIdentifier (it_name), "data")));
+                       cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer (stmt.variable_name, element_expr));
                        cbody.add_statement (cdecl);
                        
                        cbody.add_statement (stmt.body.ccodenode);
@@ -3394,7 +3410,11 @@ public class Vala.CodeGenerator : CodeVisitor {
                        if (m != null && m.return_type.type_parameter != null && expr.static_type.data_type != null) {
                                if (expr.static_type.data_type is Struct) {
                                        var st = (Struct) expr.static_type.data_type;
-                                       if (st == bool_type.data_type || st.is_integer_type ()) {
+                                       if (st == uint_type.data_type) {
+                                               var cconv = new CCodeFunctionCall (new CCodeIdentifier ("GPOINTER_TO_UINT"));
+                                               cconv.add_argument (ccall);
+                                               ccall = cconv;
+                                       } else if (st == bool_type.data_type || st.is_integer_type ()) {
                                                var cconv = new CCodeFunctionCall (new CCodeIdentifier ("GPOINTER_TO_INT"));
                                                cconv.add_argument (ccall);
                                                ccall = cconv;