summaryrefslogtreecommitdiff
path: root/codegen.c
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2023-07-26 15:15:53 -0700
committerMatthew Sotoudeh <matthew@masot.net>2023-07-26 15:15:53 -0700
commitcab3795047870ccc3a9d124e8b940e47d062a7c6 (patch)
tree8eac2a7dd5fa32e50183f58eb817f3ce0b1383f6 /codegen.c
parentf35b7e32809c5d54850ce75c4dad1a8598235cf0 (diff)
fix bug in printing type decls
Diffstat (limited to 'codegen.c')
-rw-r--r--codegen.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/codegen.c b/codegen.c
index 7e8565a..8b99e64 100644
--- a/codegen.c
+++ b/codegen.c
@@ -145,7 +145,11 @@ const void typedecl(Type *type) {
println("typedef char Type_%d ;", type->id);
break;
case TY_PTR:
+ // When we recurse, we need to set the type id to 0 because we haven't
+ // printed it out yet.
+ type->id = 0;
typedecl(type->base);
+ if (!type->id) type->id = count();
println("typedef Type_%d * Type_%d ;", type->base->id, type->id);
break;
case TY_FUNC: {
@@ -167,7 +171,9 @@ const void typedecl(Type *type) {
break;
}
case TY_ARRAY:
+ type->id = 0;
typedecl(type->base);
+ if (!type->id) type->id = count();
if (type->array_len == -1)
println("typedef Type_%d Type_%d [ ] ;", type->base->id, type->id);
else
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback