Commit 4a562865 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Support marshalling multi-dimensional arrays, based on patch by Didier

2009-01-06  Jürg Billeter  <j@bitron.ch>

	* vala/valaarraytype.vala:
	* gobject/valadbusmodule.vala:

	Support marshalling multi-dimensional arrays,
	based on patch by Didier Villevalois, fixes bug 565792

	* gobject/valadbusclientmodule.vala:

	Fix array out parameters in static D-Bus clients

svn path=/trunk/; revision=2278
parent 49023806
2009-01-06 Jürg Billeter <j@bitron.ch>
* vala/valaarraytype.vala:
* gobject/valadbusmodule.vala:
Support marshalling multi-dimensional arrays,
based on patch by Didier Villevalois, fixes bug 565792
* gobject/valadbusclientmodule.vala:
Fix array out parameters in static D-Bus clients
2009-01-05 Jürg Billeter <j@bitron.ch>
* vapigen/valagidlparser.vala:
......
......@@ -22,6 +22,7 @@ Daniel Lucraft
Daniel Silverstone
Daniel Svensson
David Keijser
Didier Villevalois
Ed Schouten
Emmanuele Bassi
Étienne Bersac
......
/* valadbusclientmodule.vala
*
* Copyright (C) 2007-2008 Jürg Billeter
* Copyright (C) 2007-2009 Jürg Billeter
* Copyright (C) 2008 Philip Van Hoof
*
* This library is free software; you can redistribute it and/or
......@@ -1013,6 +1013,16 @@ public class Vala.DBusClientModule : DBusModule {
cdecl.add_declarator (new CCodeVariableDeclarator ("_" + param.name));
postfragment.append (cdecl);
var array_type = param.parameter_type as ArrayType;
if (array_type != null) {
for (int dim = 1; dim <= array_type.rank; dim++) {
cdecl = new CCodeDeclaration ("int");
cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("_%s_length%d".printf (param.name, dim), new CCodeConstant ("0")));
postfragment.append (cdecl);
}
}
var target = new CCodeIdentifier ("_" + param.name);
var expr = read_expression (postfragment, param.parameter_type, new CCodeIdentifier ("_iter"), target);
postfragment.append (new CCodeExpressionStatement (new CCodeAssignment (target, expr)));
......@@ -1022,13 +1032,11 @@ public class Vala.DBusClientModule : DBusModule {
postfragment.append (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), target)));
if (param.parameter_type is ArrayType) {
cdecl = new CCodeDeclaration ("int");
cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("_%s_length1".printf (param.name), new CCodeConstant ("0")));
postfragment.append (cdecl);
// TODO check that parameter is not NULL (out parameters are optional)
postfragment.append (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("%s_length1".printf (param.name))), new CCodeIdentifier ("_%s_length1".printf (param.name)))));
if (array_type != null) {
for (int dim = 1; dim <= array_type.rank; dim++) {
// TODO check that parameter is not NULL (out parameters are optional)
postfragment.append (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("%s_length%d".printf (param.name, dim))), new CCodeIdentifier ("_%s_length%d".printf (param.name, dim)))));
}
}
}
}
......
/* valadbusmodule.vala
*
* Copyright (C) 2008 Jürg Billeter
* Copyright (C) 2008-2009 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
......@@ -406,6 +406,18 @@ public class Vala.DBusModule : GAsyncModule {
}
void write_array (CCodeFragment fragment, ArrayType array_type, CCodeExpression iter_expr, CCodeExpression array_expr) {
string array_iter_name = "_tmp%d".printf (next_temp_var_id++);
var cdecl = new CCodeDeclaration (array_type.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (array_iter_name));
fragment.append (cdecl);
fragment.append (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier (array_iter_name), array_expr)));
write_array_dim (fragment, array_type, 1, iter_expr, array_expr, new CCodeIdentifier (array_iter_name));
}
void write_array_dim (CCodeFragment fragment, ArrayType array_type, int dim, CCodeExpression iter_expr, CCodeExpression array_expr, CCodeExpression array_iter_expr) {
string subiter_name = "_tmp%d".printf (next_temp_var_id++);
string index_name = "_tmp%d".printf (next_temp_var_id++);
......@@ -420,18 +432,24 @@ public class Vala.DBusModule : GAsyncModule {
var iter_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_message_iter_open_container"));
iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, iter_expr));
iter_call.add_argument (new CCodeIdentifier ("DBUS_TYPE_ARRAY"));
iter_call.add_argument (new CCodeConstant ("\"%s\"".printf (array_type.element_type.get_type_signature ())));
iter_call.add_argument (new CCodeConstant ("\"%s%s\"".printf (string.nfill (array_type.rank - dim, 'a'), array_type.element_type.get_type_signature ())));
iter_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (subiter_name)));
fragment.append (new CCodeExpressionStatement (iter_call));
var cforblock = new CCodeBlock ();
var cforfragment = new CCodeFragment ();
cforblock.add_statement (cforfragment);
var cfor = new CCodeForStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier (index_name), get_array_length (array_expr, 1)), cforblock);
var cfor = new CCodeForStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier (index_name), get_array_length (array_expr, dim)), cforblock);
cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier (index_name), new CCodeConstant ("0")));
cfor.add_iterator (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier (index_name)));
write_expression (cforfragment, array_type.element_type, new CCodeIdentifier (subiter_name), new CCodeElementAccess (array_expr, new CCodeIdentifier (index_name)));
if (dim < array_type.rank) {
write_array_dim (cforfragment, array_type, dim + 1, new CCodeIdentifier (subiter_name), array_expr, array_iter_expr);
} else {
var array_iter_incr = new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, array_iter_expr);
var element_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, array_iter_incr);
write_expression (cforfragment, array_type.element_type, new CCodeIdentifier (subiter_name), element_expr);
}
fragment.append (cfor);
iter_call = new CCodeFunctionCall (new CCodeIdentifier ("dbus_message_iter_close_container"));
......
......@@ -179,7 +179,7 @@ public class Vala.ArrayType : ReferenceType {
return null;
}
return "a" + element_type_signature;
return string.nfill (rank, 'a') + element_type_signature;
}
public override void accept_children (CodeVisitor visitor) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment