summaryrefslogtreecommitdiff
path: root/decls_cgen.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-11-30 16:24:22 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-11-30 16:24:22 -0500
commit8f996b4ac75c7c62f04f09fffa81a686c1f74ab6 (patch)
tree59654893bdb959019b2715c50c229be05ce1e998 /decls_cgen.c
parentdb0367b2aa29de32d941cdea9af810b7eef0b74a (diff)
cleanup, found a weird bug
Diffstat (limited to 'decls_cgen.c')
-rw-r--r--decls_cgen.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/decls_cgen.c b/decls_cgen.c
index 40087f5..7fcb106 100644
--- a/decls_cgen.c
+++ b/decls_cgen.c
@@ -79,31 +79,34 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) {
} else if (d->flags & DECL_HAS_EXPR) {
if (d->flags & DECL_IS_CONST) {
for (size_t idx = 0; idx < arr_len(d->idents); idx++) {
- Identifier i = d->idents[idx];
Type *type = d->type.kind == TYPE_TUPLE ? &d->type.tuple[idx] : &d->type;
if (type->kind == TYPE_TYPE) {
Value *val = d->type.kind == TYPE_TUPLE ? &d->val.tuple[idx] : &d->val;
if (val->type->kind == TYPE_STRUCT) {
- /* generate struct definition */
- cgen_write(g, "struct ");
- if (g->block == NULL)
- cgen_ident(g, i);
- else
- cgen_ident_id(g, d->c.ids[idx]);
- cgen_write(g, "{");
- cgen_nl(g);
- g->indent_lvl++;
- arr_foreach(val->type->struc->fields, Field, f) {
- if (!cgen_type_pre(g, f->type, d->where)) return false;
- cgen_write(g, " ");
- cgen_ident(g, f->name);
- if (!cgen_type_post(g, f->type, d->where)) return false;
- cgen_write(g, ";");
+ StructDef *sdef = val->type->struc;
+ if (!(sdef->flags & STRUCT_DEF_CGENERATED)) {
+ /* generate struct definition */
+ cgen_write(g, "struct ");
+ if (sdef->c.name)
+ cgen_ident(g, sdef->c.name);
+ else
+ cgen_ident_id(g, sdef->c.id);
+ cgen_write(g, "{");
cgen_nl(g);
+ g->indent_lvl++;
+ arr_foreach(sdef->fields, Field, f) {
+ if (!cgen_type_pre(g, f->type, d->where)) return false;
+ cgen_write(g, " ");
+ cgen_ident(g, f->name);
+ if (!cgen_type_post(g, f->type, d->where)) return false;
+ cgen_write(g, ";");
+ cgen_nl(g);
+ }
+ g->indent_lvl--;
+ cgen_write(g, "};");
+ cgen_nl(g);
+ sdef->flags |= STRUCT_DEF_CGENERATED;
}
- g->indent_lvl--;
- cgen_write(g, "};");
- cgen_nl(g);
}
}
}