Add di's to ast_copy
This commit is contained in:
@@ -911,6 +911,7 @@ CORE_Static String
|
||||
compile_to_c_code() {
|
||||
pctx->time.code_generation = os_time();
|
||||
|
||||
#if 0
|
||||
int di = 0;
|
||||
For(pctx->ordered_decls) {
|
||||
for (Ast_Iter iter = iterate_depth_first(pctx->heap, it); iter.ast; next(&iter)) {
|
||||
@@ -960,10 +961,12 @@ compile_to_c_code() {
|
||||
}
|
||||
}
|
||||
String str = string_flatten(pctx->perm, &pctx->gen);
|
||||
printf("%s\n", str.str);
|
||||
printf("%s", str.str);
|
||||
pctx->gen.reset();
|
||||
di += 1;
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
prefixed_string_type = string_fmt(pctx->perm, "%QString", pctx->symbol_prefix);
|
||||
if (pctx->single_header_library_mode) {
|
||||
|
||||
@@ -223,6 +223,14 @@ 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) {
|
||||
Ast *result = (Ast *)push_copy(pctx->perm, ast, size);
|
||||
result->parent_scope = parent_scope;
|
||||
result->di = ++pctx->unique_ids;
|
||||
return result;
|
||||
}
|
||||
|
||||
// We are not copying module and file Ast's
|
||||
// We are not copying resolved data
|
||||
Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
@@ -230,10 +238,9 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
switch (ast->kind) {
|
||||
case AST_SCOPE: {
|
||||
Ast_Scope *src = (Ast_Scope *)ast;
|
||||
Ast_Scope *dst = push_struct_copy(pctx->perm, Ast_Scope, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
Ast_Scope *dst = ast_create_copy(parent_scope, Ast_Scope, src);
|
||||
|
||||
dst->decls = {};
|
||||
free_all_nodes(&dst->decls);
|
||||
For(src->decls) {
|
||||
Ast_Decl *copy = (Ast_Decl *)ast_copy(it, dst);
|
||||
add(pctx->perm, &dst->decls, copy);
|
||||
@@ -253,14 +260,15 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
case AST_IDENT:
|
||||
case AST_VALUE: {
|
||||
Ast_Atom *src = (Ast_Atom *)ast;
|
||||
Ast_Atom *dst = push_struct_copy(pctx->perm, Ast_Atom, ast);
|
||||
Ast_Atom *dst = ast_create_copy(parent_scope, Ast_Atom, ast);
|
||||
|
||||
dst->parent_scope = parent_scope;
|
||||
return dst;
|
||||
} break;
|
||||
|
||||
case AST_INDEX: {
|
||||
Ast_Index *src = (Ast_Index *)ast;
|
||||
Ast_Index *dst = push_struct_copy(pctx->perm, Ast_Index, ast);
|
||||
Ast_Index *dst = ast_create_copy(parent_scope, Ast_Index, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->expr = (Ast_Expr *)ast_copy(src->expr, parent_scope);
|
||||
dst->index = (Ast_Expr *)ast_copy(src->index, parent_scope);
|
||||
@@ -269,7 +277,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_UNARY: {
|
||||
Ast_Unary *src = (Ast_Unary *)ast;
|
||||
Ast_Unary *dst = push_struct_copy(pctx->perm, Ast_Unary, ast);
|
||||
Ast_Unary *dst = ast_create_copy(parent_scope, Ast_Unary, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->expr = (Ast_Expr *)ast_copy(src->expr, parent_scope);
|
||||
return dst;
|
||||
@@ -277,7 +285,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_BINARY: {
|
||||
Ast_Binary *src = (Ast_Binary *)ast;
|
||||
Ast_Binary *dst = push_struct_copy(pctx->perm, Ast_Binary, ast);
|
||||
Ast_Binary *dst = ast_create_copy(parent_scope, Ast_Binary, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->left = (Ast_Expr *)ast_copy(src->left, parent_scope);
|
||||
dst->right = (Ast_Expr *)ast_copy(src->right, parent_scope);
|
||||
@@ -286,7 +294,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_CALL_ITEM: {
|
||||
Ast_Call_Item *src = (Ast_Call_Item *)ast;
|
||||
Ast_Call_Item *dst = push_struct_copy(pctx->perm, Ast_Call_Item, ast);
|
||||
Ast_Call_Item *dst = ast_create_copy(parent_scope, Ast_Call_Item, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->item = (Ast_Expr *)ast_copy(src->item, parent_scope);
|
||||
if (src->call_flags & CALL_INDEX) {
|
||||
@@ -301,7 +309,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
case AST_COMPOUND:
|
||||
case AST_CALL: {
|
||||
Ast_Call *src = (Ast_Call *)ast;
|
||||
Ast_Call *dst = push_struct_copy(pctx->perm, Ast_Call, ast);
|
||||
Ast_Call *dst = ast_create_copy(parent_scope, Ast_Call, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->name = (Ast_Expr *)ast_copy(src->name, parent_scope);
|
||||
|
||||
@@ -320,7 +328,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
case AST_RUNTIME_ASSERT:
|
||||
case AST_CONSTANT_ASSERT: {
|
||||
Ast_Builtin *src = (Ast_Builtin *)ast;
|
||||
Ast_Builtin *dst = push_struct_copy(pctx->perm, Ast_Builtin, ast);
|
||||
Ast_Builtin *dst = ast_create_copy(parent_scope, Ast_Builtin, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->expr = (Ast_Expr *)ast_copy(src->expr, parent_scope);
|
||||
return dst;
|
||||
@@ -328,7 +336,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_SWITCH: {
|
||||
Ast_Switch *src = (Ast_Switch *)ast;
|
||||
Ast_Switch *dst = push_struct_copy(pctx->perm, Ast_Switch, ast);
|
||||
Ast_Switch *dst = ast_create_copy(parent_scope, Ast_Switch, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->value = (Ast_Expr *)ast_copy(src->value, parent_scope);
|
||||
dst->default_scope = (Ast_Scope *)ast_copy(src->default_scope, parent_scope);
|
||||
@@ -344,7 +352,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_SWITCH_CASE: {
|
||||
Ast_Switch_Case *src = (Ast_Switch_Case *)ast;
|
||||
Ast_Switch_Case *dst = push_struct_copy(pctx->perm, Ast_Switch_Case, ast);
|
||||
Ast_Switch_Case *dst = ast_create_copy(parent_scope, Ast_Switch_Case, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
|
||||
dst->scope = (Ast_Scope *)ast_copy(src->scope, parent_scope);
|
||||
@@ -358,7 +366,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_VAR_UNPACK: {
|
||||
Ast_Var_Unpack *src = (Ast_Var_Unpack *)ast;
|
||||
Ast_Var_Unpack *dst = push_struct_copy(pctx->perm, Ast_Var_Unpack, ast);
|
||||
Ast_Var_Unpack *dst = ast_create_copy(parent_scope, Ast_Var_Unpack, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
|
||||
dst->expr = (Ast_Expr *)ast_copy(src->expr, parent_scope);
|
||||
@@ -373,7 +381,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
case AST_PASS:
|
||||
case AST_BREAK: {
|
||||
Ast *src = (Ast *)ast;
|
||||
Ast *dst = push_struct_copy(pctx->perm, Ast, ast);
|
||||
Ast *dst = ast_create_copy(parent_scope, Ast, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
return dst;
|
||||
} break;
|
||||
@@ -387,9 +395,9 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
case AST_CONST:
|
||||
case AST_VAR: {
|
||||
Ast_Decl *src = (Ast_Decl *)ast;
|
||||
Ast_Decl *dst = push_struct_copy(pctx->perm, Ast_Decl, ast);
|
||||
Ast_Decl *dst = ast_create_copy(parent_scope, Ast_Decl, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->overload_op_info = push_struct_copy(pctx->perm, Ast_Operator_Info, src->overload_op_info);
|
||||
// dst->overload_op_info = ast_create_copy(parent_scope, Ast_Operator_Info, src->overload_op_info);
|
||||
// omitting polymorphs
|
||||
// omitting polymorph parameters
|
||||
dst->scope = (Ast_Scope *)ast_copy(src->scope, parent_scope);
|
||||
@@ -400,7 +408,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_ARRAY: {
|
||||
Ast_Array *src = (Ast_Array *)ast;
|
||||
Ast_Array *dst = push_struct_copy(pctx->perm, Ast_Array, ast);
|
||||
Ast_Array *dst = ast_create_copy(parent_scope, Ast_Array, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->expr = (Ast_Expr *)ast_copy(src->expr, parent_scope);
|
||||
return dst;
|
||||
@@ -408,7 +416,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_FOR: {
|
||||
Ast_For *src = (Ast_For *)ast;
|
||||
Ast_For *dst = push_struct_copy(pctx->perm, Ast_For, ast);
|
||||
Ast_For *dst = ast_create_copy(parent_scope, Ast_For, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->scope = (Ast_Scope *)ast_copy(src->scope, parent_scope);
|
||||
dst->init = (Ast_Expr *)ast_copy(src->init, parent_scope);
|
||||
@@ -419,7 +427,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_IF: {
|
||||
Ast_If *src = (Ast_If *)ast;
|
||||
Ast_If *dst = push_struct_copy(pctx->perm, Ast_If, ast);
|
||||
Ast_If *dst = ast_create_copy(parent_scope, Ast_If, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->ifs.init(pctx->perm, src->ifs.len);
|
||||
For(src->ifs) {
|
||||
@@ -432,7 +440,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_IF_NODE: {
|
||||
Ast_If_Node *src = (Ast_If_Node *)ast;
|
||||
Ast_If_Node *dst = push_struct_copy(pctx->perm, Ast_If_Node, ast);
|
||||
Ast_If_Node *dst = ast_create_copy(parent_scope, Ast_If_Node, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
dst->expr = (Ast_Expr *)ast_copy(src->expr, parent_scope);
|
||||
dst->init = (Ast_Binary *)ast_copy(src->init, parent_scope);
|
||||
@@ -442,7 +450,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_RETURN: {
|
||||
Ast_Return *src = (Ast_Return *)ast;
|
||||
Ast_Return *dst = push_struct_copy(pctx->perm, Ast_Return, ast);
|
||||
Ast_Return *dst = ast_create_copy(parent_scope, Ast_Return, ast);
|
||||
|
||||
dst->expr.init(pctx->perm, src->expr.len);
|
||||
For(src->expr) {
|
||||
@@ -454,7 +462,7 @@ Ast *ast_copy(Ast *ast, Ast_Scope *parent_scope) {
|
||||
|
||||
case AST_LAMBDA_EXPR: {
|
||||
Ast_Lambda *src = (Ast_Lambda *)ast;
|
||||
Ast_Lambda *dst = push_struct_copy(pctx->perm, Ast_Lambda, ast);
|
||||
Ast_Lambda *dst = ast_create_copy(parent_scope, Ast_Lambda, ast);
|
||||
dst->parent_scope = parent_scope;
|
||||
|
||||
dst->args.init(pctx->perm, src->args.len);
|
||||
|
||||
@@ -943,7 +943,8 @@ try_resolving_lambda_scope(Operand *op, Ast_Lambda *lambda, Ast_Type *lambda_typ
|
||||
// We remove all declarations to cleanup the scope
|
||||
// for iteration
|
||||
//
|
||||
// If I want to implement :NestedDeclarations
|
||||
// :NestedDeclarations
|
||||
// If I want to implement nested declarations
|
||||
// then probably this will need to get reverted
|
||||
free_all_nodes(&lambda->scope->decls);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user