Unique names for polymorphic types

This commit is contained in:
Krzosa Karol
2023-04-01 11:43:26 +02:00
parent b14979d754
commit 9e077d4d88
3 changed files with 32 additions and 24 deletions

View File

@@ -41,27 +41,6 @@ gen_last_line() {
}
}
CORE_Static String
string_scope_name(Ast_Scope *scope) {
String string = {};
if (scope->parent_scope) string = string_scope_name(scope->parent_scope);
assert_message(scope->scope_id != 0, "Scope id is equal to 0 which is invalid, scope didn't initialize id");
string = pctx->fmt("%QS%u_", string, scope->scope_id);
return string;
}
CORE_Static void
gen_scope_name(Ast_Scope *scope) {
gen("%Q", string_scope_name(scope));
}
CORE_Static Intern_String
get_unique_name(Ast *ast) {
String result = string_scope_name(ast->parent_scope);
assert(result.len);
return pctx->internf("%Q%d", result, ast->pos->line);
}
global String prefixed_string_type;
CORE_Static const char *
get_ctype_name_for_type(Ast_Type *type) {
@@ -565,7 +544,7 @@ gen_ast(Ast *ast) {
if (is_tuple(node->resolved_type)) {
Scoped_Arena scratch(pctx->scratch);
Intern_String tuple_name = get_unique_name(node);
Intern_String tuple_name = get_unique_name();
gen_simple_decl(node->resolved_type, tuple_name);
gen(";");
@@ -804,7 +783,7 @@ gen_ast(Ast *ast) {
Scoped_Arena scratch(pctx->scratch);
Intern_String var_name = get_unique_name(node);
Intern_String var_name = get_unique_name();
gen_simple_decl(node->resolved_type, var_name);
gen(" = ");
gen_expr(node->expr);