Unify the build_type function

This commit is contained in:
2025-03-06 22:59:41 +01:00
parent dbeaca7cbf
commit 28bb573bf9
5 changed files with 102 additions and 99 deletions

View File

@ -69,5 +69,66 @@ namespace boot
{
return this;
}
void declaration_visitor::visit(program *program)
{
for (type_definition *const type : program->types)
{
this->unresolved.insert({ type->identifier, new alias_type() });
}
for (type_definition *const type : program->types)
{
type->accept(this);
}
}
void declaration_visitor::visit(type_definition *definition)
{
auto unresolved_declaration = this->unresolved.at(definition->identifier);
definition->body().accept(this);
if (this->current_type != nullptr)
{
unresolved_declaration->reference = this->current_type;
}
this->current_type = nullptr;
}
void declaration_visitor::visit(primitive_type_expression *type)
{
auto unresolved_alias = this->unresolved.find(type->name);
if (unresolved_alias != this->unresolved.end())
{
this->current_type = unresolved_alias->second;
}
else
{
this->current_type = new primitive_type(type->name);
}
}
void declaration_visitor::visit(array_type_expression *type)
{
}
void declaration_visitor::visit(pointer_type_expression *type)
{
}
void declaration_visitor::visit(record_type_expression *type)
{
this->current_type = new record_type();
}
void declaration_visitor::visit(union_type_expression *type)
{
this->current_type = new union_type();
}
void declaration_visitor::visit(procedure_type_expression *type)
{
}
}
}