Polymorphism: Add already resolved decls for identifiers

This commit is contained in:
Krzosa Karol
2023-04-03 11:55:14 +02:00
parent 41d2baa56b
commit b543e1df9d
4 changed files with 43 additions and 26 deletions

View File

@@ -63,24 +63,27 @@ Ast_Expr *create_typespec_from_type(Token *pos, Ast_Scope *parent_scope, Ast_Typ
Ast_Array *arr = ast_array(pos, create_typespec_from_type(pos, parent_scope, type->arr.base));
result = arr;
} break;
case TYPE_LAMBDA: {
invalid_codepath;
} break;
case TYPE_STRUCT:
case TYPE_UNION:
case TYPE_ENUM: {
// We fill out the resolved_decl here because the typespecs for
// polymorphic types can be really complex and very context dependent.
// For example for a namespaced polymorph we would need to figure out the
// namespace, add binary expression etc.
Ast_Decl *decl = (Ast_Decl *)type->ast;
// @warning:
// Can we do this differently?
// WE MIGHT HAVE PROBLEM WITH NAMESPACES in the future!!!
if (decl->flags & AST_POLYMORPH_INSTANCE) {
Ast_Atom *ident = ast_ident(pos, decl->name);
ident->parent_scope = parent_scope;
result = ast_call(pos, ident, decl->instantiation_call_items);
}
else result = ast_ident(pos, decl->name);
Ast_Atom *atom = ast_ident(pos, decl->name);
atom->resolved_decl = decl;
result = atom;
} break;
case TYPE_LAMBDA: {
// @warning: Not sure if this is correct, need to test!
Ast_Decl *decl = (Ast_Decl *)type->ast;
Ast_Atom *atom = ast_ident(pos, decl->name);
atom->resolved_decl = decl;
result = atom;
} break;
invalid_default_case;
}
result->parent_scope = parent_scope;
return result;