Commit df15a36a authored by Rico Tzschichholz's avatar Rico Tzschichholz

codegen: Improve ccode for fixed-length array parameters

#163
parent 74264388
......@@ -723,14 +723,18 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
string ctypename = get_ccode_name (param.variable_type);
string name = get_variable_cname (param.name);
var array_type = (ArrayType) param.variable_type;
if (param.direction != ParameterDirection.IN) {
if (array_type.fixed_length) {
ctypename += "*";
}
var main_cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
if (param.direction != ParameterDirection.IN) {
ctypename += "*";
}
var array_type = (ArrayType) param.variable_type;
var main_cparam = new CCodeParameter (name, ctypename);
generate_type_declaration (array_type.element_type, decl_space);
......@@ -739,7 +743,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
}
if (get_ccode_array_length (param)) {
if (!array_type.fixed_length && get_ccode_array_length (param)) {
string length_ctype = "int";
if (get_ccode_array_length_type (param) != null) {
length_ctype = get_ccode_array_length_type (param);
......
......@@ -364,7 +364,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
var unary = arg as UnaryExpression;
if (unary == null || unary.operator != UnaryOperator.OUT) {
if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
if (get_ccode_array_length (param) && param.variable_type is ArrayType && !((ArrayType) param.variable_type).fixed_length) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression? array_length_expr = null;
......@@ -430,7 +430,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (arg));
if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
if (get_ccode_array_length (param) && param.variable_type is ArrayType && !((ArrayType) param.variable_type).fixed_length) {
var array_type = (ArrayType) param.variable_type;
var array_length_type = int_type;
if (get_ccode_array_length_type (param) != null) {
......
......@@ -570,7 +570,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
} else if (!m.coroutine) {
// declare local variable for out parameter to allow assignment even when caller passes NULL
var vardecl = new CCodeVariableDeclarator.zero (get_variable_cname ("_vala_%s".printf (param.name)), default_value_for_type (param.variable_type, true));
var vardecl = new CCodeVariableDeclarator.zero (get_variable_cname ("_vala_%s".printf (param.name)), default_value_for_type (param.variable_type, true), get_ccode_declarator_suffix (param.variable_type));
ccode.add_declaration (get_ccode_name (param.variable_type), vardecl);
if (param.variable_type is ArrayType) {
......
......@@ -254,6 +254,37 @@ void test_struct_array () {
assert (FOO_ARRAY_CONST[0].bar == 42);
}
void give_fixed_array (out int i[3]) {
i = { 3, 4, 5 };
}
void take_fixed_array (int i[3]) {
assert (i.length == 3);
assert (i[1] == 2);
}
void change_fixed_array (ref int i[3]) {
assert (i.length == 3);
//FIXME assert (i[1] == 7);
//FIXME i[1] = 9;
}
void test_fixed_array () {
int i[3] = { 1, 2, 3 };
assert (i.length == 3);
take_fixed_array (i);
int k[3] = { 6, 7, 8 };
change_fixed_array (ref k);
assert (k.length == 3);
//FIXME assert (k[1] == 9);
int j[3];
give_fixed_array (out j);
assert (j.length == 3);
//FIXME assert (j[1] == 4);
}
void main () {
test_integer_array ();
test_string_array ();
......@@ -270,4 +301,5 @@ void main () {
test_array_move ();
test_array_resize ();
test_struct_array ();
test_fixed_array ();
}
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