summaryrefslogtreecommitdiff
path: root/typedefs_cgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'typedefs_cgen.c')
-rw-r--r--typedefs_cgen.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/typedefs_cgen.c b/typedefs_cgen.c
index 08b582d..879eb2f 100644
--- a/typedefs_cgen.c
+++ b/typedefs_cgen.c
@@ -35,7 +35,20 @@ static bool typedefs_decl(CGenerator *g, Declaration *d) {
/* generate typedef */
IdentID id = 0;
if (g->block != NULL) id = d->c.ids[idx] = g->ident_counter++;
- if (val->type->kind == TYPE_STRUCT) continue; /* we don't need to typedef this; we can just use its tag */
+ if (val->type->kind == TYPE_STRUCT) {
+ /* we'll actually define the struct later; here we can just declare it */
+ cgen_write(g, "struct ");
+ if (g->block == NULL) {
+ /* we can refer to this by its name */
+ cgen_ident(g, i);
+ } else {
+ /* we need to use an ID ): */
+ cgen_ident_id(g, id);
+ }
+ cgen_write(g, ";");
+ cgen_nl(g);
+ continue;
+ }
cgen_write(g, "typedef ");
if (!cgen_type_pre(g, val->type, d->where)) return false;
cgen_write(g, " ");