Copying and printing the copy

This commit is contained in:
Krzosa Karol
2023-03-31 22:44:11 +02:00
parent e70d544029
commit b6835d0f6a
5 changed files with 26 additions and 9 deletions

View File

@@ -227,6 +227,7 @@ end_of_switch:
#define ast_create_copy(parent_scope, T, ast) (T *)ast__create_copy(parent_scope, sizeof(T), ast)
Ast *ast__create_copy(Ast_Scope *parent_scope, size_t size, Ast *ast) {
if (ast == 0) return 0;
Ast *result = (Ast *)push_copy(pctx->perm, ast, size);
result->parent_scope = parent_scope;
result->di = ++pctx->unique_ids;
@@ -242,9 +243,9 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
Ast_Scope *src = (Ast_Scope *)ast;
Ast_Scope *dst = ast_create_copy(parent_scope, Ast_Scope, src);
free_all_nodes(&dst->decls);
dst->decls = {};
For(src->decls) {
Ast_Decl *copy = (Ast_Decl *)ast_copy(it, dst);
Ast_Decl *copy = (Ast_Decl *)ast_copy(it, src);
add(pctx->perm, &dst->decls, copy);
}