From: Jürg Billeter Date: Mon, 30 Apr 2007 07:38:03 +0000 (+0000) Subject: add pointer to integer conversion in foreach statements, fixes bug 433288 X-Git-Tag: VALA_0_0_9~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b745d1f5d1195f9e890f94f98ebb8409039ae062;p=platform%2Fupstream%2Fvala.git add pointer to integer conversion in foreach statements, fixes bug 433288 2007-04-30 Jürg Billeter * vala/valacodegenerator.vala: add pointer to integer conversion in foreach statements, fixes bug 433288 svn path=/trunk/; revision=289 --- diff --git a/vala/ChangeLog b/vala/ChangeLog index 16978c0..f66389d 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,8 @@ +2007-04-30 Jürg Billeter + + * vala/valacodegenerator.vala: add pointer to integer conversion in + foreach statements, fixes bug 433288 + 2007-04-24 Jürg Billeter * vapi/glib-2.0.vala: add g_bit_nth_lsf, g_bit_nth_msf, and diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index 394127f..4b79237 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -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;