Add forward type declaration representation

This commit is contained in:
2025-03-06 03:46:10 +01:00
parent 8dc02047df
commit dbeaca7cbf
5 changed files with 215 additions and 26 deletions

View File

@ -41,25 +41,65 @@ namespace gcc
declaration_visitor::declaration_visitor(std::shared_ptr<symbol_table> symbol_table)
: symbols(symbol_table)
{
this->unresolved.insert({ "Int", std::make_shared<type>(elna_int_type_node) });
this->unresolved.insert({ "Word", std::make_shared<type>(elna_word_type_node) });
this->unresolved.insert({ "Char", std::make_shared<type>(elna_char_type_node) });
this->unresolved.insert({ "Bool", std::make_shared<type>(elna_bool_type_node) });
this->unresolved.insert({ "Byte", std::make_shared<type>(elna_byte_type_node) });
this->unresolved.insert({ "Float", std::make_shared<type>(elna_float_type_node) });
this->unresolved.insert({ "String", std::make_shared<type>(elna_string_type_node) });
this->symbols->enter("Int", elna_int_type_node);
this->symbols->enter("Word", elna_word_type_node);
this->symbols->enter("Char", elna_char_type_node);
this->symbols->enter("Bool", elna_bool_type_node);
this->symbols->enter("Byte", elna_byte_type_node);
this->symbols->enter("Float", elna_float_type_node);
this->symbols->enter("String", elna_string_type_node);
}
tree get_inner_alias(const type& t)
tree declaration_visitor::get_inner_alias(const boot::alias_type& t)
{
if (t.reference == nullptr)
{
return t.resolved;
return NULL_TREE;
}
else
else if (auto reference = t.reference->is_primitive())
{
return get_inner_alias(*t.reference);
return this->symbols->lookup(reference->identifier);
}
else if (auto reference = t.reference->is_alias())
{
return get_inner_alias(*reference);
}
else if (auto reference = t.reference->is_record())
{
return make_node(RECORD_TYPE);
}
else if (auto reference = t.reference->is_union())
{
return make_node(UNION_TYPE);
}
return NULL_TREE;
}
boot::type *declaration_visitor::build_type(boot::type_expression *type_expression)
{
if (auto alias_node = type_expression->is_primitive())
{
return this->unresolved.at(alias_node->name);
}
else if (auto alias_node = type_expression->is_record())
{
return build_record(alias_node.get());
}
else if (auto alias_node = type_expression->is_union())
{
return build_union(alias_node.get());
}
return nullptr;
}
boot::record_type *declaration_visitor::build_record(boot::record_type_expression *type_expression)
{
return new boot::record_type();
}
boot::union_type *declaration_visitor::build_union(boot::union_type_expression *type_expression)
{
return new boot::union_type();
}
void declaration_visitor::visit(boot::program *program)
@ -80,26 +120,30 @@ namespace gcc
{
unresolved_declaration->reference = unresolved_alias->second;
}
else
{
unresolved_declaration->reference = new boot::primitive_type(alias_node->name);
}
}
else if (auto alias_node = type->body().is_record())
{
unresolved_declaration->resolved = make_node(RECORD_TYPE);
unresolved_declaration->reference = build_record(alias_node.get());
}
else if (auto alias_node = type->body().is_union())
{
unresolved_declaration->resolved = make_node(UNION_TYPE);
unresolved_declaration->reference = build_union(alias_node.get());
}
}
for (auto unresolved : this->unresolved)
{
auto inner_alias = get_inner_alias(unresolved.second);
auto inner_alias = get_inner_alias(*unresolved.second);
this->symbols->enter(unresolved.first, inner_alias);
}
}
void declaration_visitor::visit(boot::type_definition *definition)
{
this->unresolved.insert({ definition->identifier, std::make_shared<type>() });
this->unresolved.insert({ definition->identifier, new boot::alias_type() });
}
generic_visitor::generic_visitor(std::shared_ptr<symbol_table> symbol_table)