Fix iterator traversal order

This commit is contained in:
Krzosa Karol
2023-03-31 12:41:19 +02:00
parent 534db633ed
commit 1839279235
4 changed files with 76 additions and 54 deletions

View File

@@ -828,6 +828,35 @@ CORE_Static String
compile_to_c_code() {
pctx->time.code_generation = os_time();
For(pctx->ordered_decls) {
for (Ast_Iter iter = iterate_depth_first(pctx->heap, it); iter.ast; next(&iter)) {
Ast_Decl *decl = (Ast_Decl *)iter.ast;
switch (iter.kind) {
case AST_STRUCT: {
genln("(struct %s", decl->name.str);
global_indent += 1;
} break;
case AST_STRUCT + 128: {
global_indent -= 1;
genln(")");
} break;
case AST_VAR: {
genln("(var %s: ", decl->name.str);
auto typespec = (Ast_Atom *)decl->typespec;
Ast_Decl *type = typespec->resolved_decl;
assert(typespec);
gen("%s", type->name.str);
} break;
case AST_VAR + 128: {
gen(")");
} break;
}
}
String str = string_flatten(pctx->perm, &pctx->gen);
printf("%s", str.str);
pctx->gen.reset();
}
prefixed_string_type = string_fmt(pctx->perm, "%QString", pctx->symbol_prefix);
if (pctx->single_header_library_mode) {
gen(R"(