From d4f4c7d652a3647f0aa616f973a52f35d8b49f06 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Fri, 17 Apr 2026 23:05:13 +0200 Subject: [PATCH] C-Generator: fix nested function type output * fix generated code for type definitions involving function that take function pointer arguments * fix and extend bogus test (!) --- generator/c/c_generator.c2 | 59 +++++++++++++--------------- test/functions/func_param_nested.c2t | 30 +++++++++++++- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/generator/c/c_generator.c2 b/generator/c/c_generator.c2 index d4b65c1a8..fed8f063d 100644 --- a/generator/c/c_generator.c2 +++ b/generator/c/c_generator.c2 @@ -461,6 +461,30 @@ fn void Generator.emitStruct(Generator* gen, string_buffer.Buf* out, Decl* d, u3 } } +fn void Generator.emitFunctionParam(Generator* gen, string_buffer.Buf* out, QualType qt, u32 name_idx, u32 arg_num) { + char[16] temp; + const char* name; + if (name_idx) { + name = gen.idx2name(name_idx); + } else { + // some compilers do not accept unnamed arguments in function definitions + snprintf(temp, elemsof(temp), "_arg%d", arg_num); + name = temp; + } + if (qt.isFunction()) { + FunctionType* ft = qt.getFunctionType(); + FunctionDecl* fd = ft.getDecl(); + if (fd.isParam()) { + gen.gen_member_type_func(fd, out, name); + return; + } + // TODO: when to we get here? + } + gen.emitTypePre(out, qt); + out.space(); + out.add(name); +} + fn void Generator.emitFunctionType(Generator* gen, string_buffer.Buf* out, Decl* d) { FunctionTypeDecl* ftd = (FunctionTypeDecl*)d; FunctionDecl* fd = ftd.getDecl(); @@ -474,15 +498,9 @@ fn void Generator.emitFunctionType(Generator* gen, string_buffer.Buf* out, Decl* u32 num_params = fd.getNumParams(); VarDecl** params = fd.getParams(); for (u32 i=0; i