summaryrefslogtreecommitdiff
path: root/typedefs_cgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'typedefs_cgen.c')
-rw-r--r--typedefs_cgen.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/typedefs_cgen.c b/typedefs_cgen.c
index 0feee25..9da3121 100644
--- a/typedefs_cgen.c
+++ b/typedefs_cgen.c
@@ -1,13 +1,17 @@
static bool typedefs_stmt(CGenerator *g, Statement *s);
static bool typedefs_decl(CGenerator *g, Declaration *d);
+static bool typedefs_expr(CGenerator *g, Expression *e);
static bool typedefs_block(CGenerator *g, Block *b) {
Block *prev = g->block;
+ printf("%s\n",b->stmts[0].where.code);
if (!cgen_block_enter(g, b))
return false;
arr_foreach(b->stmts, Statement, s)
if (!typedefs_stmt(g, s))
return false;
+ if (b->ret_expr && !typedefs_expr(g, b->ret_expr))
+ return false;
cgen_block_exit(g, prev);
return true;
}
@@ -18,6 +22,18 @@ static bool typedefs_expr(CGenerator *g, Expression *e) {
/* needs to go before decls_cgen.c... */
e->fn.c.id = g->ident_counter++;
}
+ if (e->kind == EXPR_TYPE && e->typeval.kind == TYPE_STRUCT) {
+ StructDef *sdef = e->typeval.struc;
+ if (sdef->c.id || sdef->c.name) {
+ /* we've already done this */
+ } else {
+ cgen_write(g, "struct ");
+ IdentID id = g->ident_counter++;
+ cgen_ident_id(g, id);
+ sdef->c.id = id;
+ cgen_write(g, ";");
+ }
+ }
return true;
}