Skip to content

Commit

Permalink
Translate static array parameter as pointer, not ref
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jul 19, 2023
1 parent 06679bc commit 850a448
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 5 additions & 2 deletions source/ctod/ctype.d
Original file line number Diff line number Diff line change
Expand Up @@ -698,15 +698,18 @@ pure nothrow:
final switch(tag) {
case Tag.cArray:
return next[0].toString() ~ "[$]";
case Tag.staticArrayParam:
// Possible to translate as `ref` parameter, but we also translate passing `sa` to `sa.ptr`
// So translating as pointer makes this more consistent
// return "ref " ~ next[0].toString() ~ "[" ~ countExpr ~ "]";
goto case;
case Tag.pointer:
if (next[0].isFunction) {
return fmtFunction(next[0].next[0], "function", next[0].params);
} else {
//format(isConst ? "const(%s*)" : "%s*", next[0]);
return isConst ? ("const("~next[0].toString()~"*)") : next[0].toString() ~ "*";
}
case Tag.staticArrayParam:
return "ref " ~ next[0].toString() ~ "[" ~ countExpr ~ "]";
case Tag.staticArray:
return next[0].toString() ~ "[" ~ countExpr ~ "]";
case Tag.funcDecl:
Expand Down
7 changes: 2 additions & 5 deletions source/ctod/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ pragma(inline, true) private void foo(int* x, int function() y) {
");

// array parameters
test(`
void farrays(int x[1], int y[][4], int z[3][5], int *w[5], int (*v)[5]);
`, `
void farrays(ref int[1] x, int[4]* y, ref int[5][3] z, ref int*[5] w, int[5]* v);
`);
test(`void farrays(int x[1], int y[][4], int z[3][5], int *w[5], int (*v)[5]);`,
`void farrays(int* x, int[4]* y, int[5]* z, int** w, int[5]* v);`);

// TODO: qualifiers in array parameter
// "void fquals(int x[const static 5]) {}"
Expand Down

0 comments on commit 850a448

Please sign in to comment.