From 1991cb62d26b954e54cf13c2d765fb3a0bbaa3ca Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Fri, 23 Jan 2026 19:05:10 +0000 Subject: Fix for #87 --- src/ast/ast.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/ast') diff --git a/src/ast/ast.c b/src/ast/ast.c index 712f6e3..78d7efb 100644 --- a/src/ast/ast.c +++ b/src/ast/ast.c @@ -169,7 +169,26 @@ int type_eq(Type *a, Type *b) return 1; } +static char *type_to_string_impl(Type *t); + char *type_to_string(Type *t) +{ + if (!t) + { + return xstrdup("void"); + } + char *res = type_to_string_impl(t); + if (t->is_const) + { + char *final = xmalloc(strlen(res) + 7); + sprintf(final, "const %s", res); + free(res); + return final; + } + return res; +} + +static char *type_to_string_impl(Type *t) { if (!t) { @@ -293,7 +312,26 @@ char *type_to_string(Type *t) // C-compatible type stringifier. // Strictly uses 'struct T' for explicit structs to support external types. // Does NOT mangle pointers to 'Ptr'. +static char *type_to_c_string_impl(Type *t); + char *type_to_c_string(Type *t) +{ + if (!t) + { + return xstrdup("void"); + } + char *res = type_to_c_string_impl(t); + if (t->is_const) + { + char *final = xmalloc(strlen(res) + 7); + sprintf(final, "const %s", res); + free(res); + return final; + } + return res; +} + +static char *type_to_c_string_impl(Type *t) { if (!t) { -- cgit v1.2.3