From 2ae50e907a7042aecb00bcff7643859d3f657895 Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Sat, 2 Nov 2024 08:28:59 -0400 Subject: More type parsing Signed-off-by: Quinn Stephens --- compiler/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'compiler/main.c') diff --git a/compiler/main.c b/compiler/main.c index da261bc..ada6243 100644 --- a/compiler/main.c +++ b/compiler/main.c @@ -173,6 +173,14 @@ parse_args(int argc, char **argv) set_out_fname(); } +static void +print_ptrs(int n_ptrs) +{ + for (int n = 0; n < n_ptrs; n++) { + putchar('*'); + } +} + static void print_alias(struct type *typ) { @@ -207,7 +215,7 @@ print_struct(struct type *typ) { struct struct_member *mem; - printf("struct {\n"); + printf("struct (%lu bytes) {\n", typ->size); for (size_t r = 0; r < typ->members.n_rows; r++) { mem = (struct struct_member*)typ->members.rows[r].head; @@ -216,7 +224,9 @@ print_struct(struct type *typ) } do { - printf(" %.*s %.*s; (%d pointer(s))\n", (int)mem->typ->name_len, mem->typ->name, (int)mem->name_len, mem->name, mem->n_ptrs); + printf(" %.*s", (int)mem->typ->name_len, mem->typ->name); + print_ptrs(mem->n_ptrs); + printf(" %.*s;\n", (int)mem->name_len, mem->name); mem = (struct struct_member*)mem->hashmap_entry.list_entry.next; } while (mem != (struct struct_member*)&typ->members.rows[r]); -- cgit v1.2.3