From b745d1f5d1195f9e890f94f98ebb8409039ae062 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Mon, 30 Apr 2007 07:38:03 +0000 Subject: [PATCH] add pointer to integer conversion in foreach statements, fixes bug 433288 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- vala/ChangeLog | 5 +++++ vala/vala/valacodegenerator.vala | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) 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; -- 2.7.4