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

@@ -1,4 +1,18 @@
CORE_Static Intern_String
get_unique_name() {
static uint64_t counter;
static char char_counter;
if (char_counter == 0 || char_counter > 'Z') char_counter = 'A';
return pctx->internf("%c%uUnique", char_counter++, counter++);
}
CORE_Static Intern_String
get_unique_name_for_decl(Ast_Decl *decl) {
static char char_counter;
if (char_counter == 0 || char_counter > 'Z') char_counter = 'A';
return pctx->internf("%c%u_%Q", char_counter++, decl->di, decl->name);
}
#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) {
@@ -297,6 +311,9 @@ Ast_Decl *get_or_instantiate_polymorph_type(Token *pos, Ast_Decl *poly, Array<As
unset_flag(result->flags, AST_POLYMORPH);
result->type_val = type_incomplete(result);
result->polymorph_hash = hash;
assert(result->di != poly->di);
result->name = get_unique_name_for_decl(result);
poly->polymorphs.add(result);
}