1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
static bool cgen_decls_expr(CGenerator *g, Expression *e) {
return true;
}
static bool cgen_decls_block(CGenerator *g, Block *b) {
return true;
}
static bool cgen_decls_decl(CGenerator *g, Declaration *d) {
if ((d->flags & DECL_FLAG_HAS_EXPR) && d->expr.kind == EXPR_FN && arr_len(d->idents) == 1) {
d->expr.fn.c.name = d->idents[0];
if (!cgen_fn_header(g, &d->expr.fn, d->where))
return false;
cgen_write(g, ";\n");
if (!cgen_decls_block(g, &d->expr.fn.body))
return false;
} else if (d->flags & DECL_FLAG_HAS_EXPR) {
if (!cgen_decls_expr(g, &d->expr))
return false;
}
return true;
}
static bool cgen_decls_stmt(CGenerator *g, Statement *s) {
switch (s->kind) {
case STMT_DECL:
if (!cgen_decls_decl(g, &s->decl))
return false;
break;
case STMT_EXPR:
break;
case STMT_RET:
break;
}
return true;
}
static bool cgen_decls_file(CGenerator *g, ParsedFile *f) {
cgen_write(g, "/* declarations */\n");
arr_foreach(f->stmts, Statement, s) {
if (!cgen_decls_stmt(g, s))
return false;
}
return true;
}
|