diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 19:05:10 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 19:05:10 +0000 |
| commit | 1991cb62d26b954e54cf13c2d765fb3a0bbaa3ca (patch) | |
| tree | d183776b150690beb2ee45c1ace4e67ab5a29adc /src/ast | |
| parent | a3ee8766e0fc9cb5c96fd9d38d5b0af7b02e01ff (diff) | |
Fix for #87
Diffstat (limited to 'src/ast')
| -rw-r--r-- | src/ast/ast.c | 38 |
1 files changed, 38 insertions, 0 deletions
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,12 +169,31 @@ 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) + { + return xstrdup("void"); + } switch (t->kind) { @@ -293,12 +312,31 @@ 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) + { + return xstrdup("void"); + } switch (t->kind) { |
