Check for duplicate fields in the declaration visitor

This commit is contained in:
2025-03-15 23:01:05 +01:00
parent fa73f14070
commit 978dd44a25
5 changed files with 131 additions and 47 deletions

View File

@ -66,8 +66,23 @@ namespace boot
}
for (auto& unresolved : this->unresolved)
{
auto info = std::make_shared<type_info>(type_info(type(unresolved.second)));
this->symbols->enter(std::move(unresolved.first), info);
if (!unresolved.second->reference.empty())
{
auto info = std::make_shared<type_info>(type_info(type(unresolved.second)));
this->symbols->enter(std::move(unresolved.first), info);
}
}
for (boot::variable_declaration *const variable : program->variables)
{
variable->accept(this);
}
for (boot::procedure_definition *const procedure : program->procedures)
{
procedure->accept(this);
}
for (statement *const body_statement : program->body)
{
body_statement->accept(this);
}
}
@ -123,6 +138,7 @@ namespace boot
this->current_type = type();
return false;
}
field_names.insert(field.first);
field.second->accept(this);
if (!this->current_type.empty())
{
@ -140,10 +156,6 @@ namespace boot
{
this->current_type = type(type_definition);
}
else
{
this->current_type = type();
}
}
void declaration_visitor::visit(union_type_expression *type_expression)
@ -154,13 +166,99 @@ namespace boot
{
this->current_type = type(type_definition);
}
else
{
this->current_type = type();
}
}
void declaration_visitor::visit(procedure_type_expression *type_expression)
{
for (variable_declaration *const parameter : type_expression->parameters)
{
parameter->accept(this);
}
if (type_expression->return_type != nullptr)
{
type_expression->return_type->accept(this);
}
}
void declaration_visitor::visit(variable_declaration *declaration)
{
declaration->variable_type().accept(this);
}
void declaration_visitor::visit(procedure_definition *definition)
{
definition->heading().accept(this);
if (definition->body != nullptr)
{
definition->body->accept(this);
}
}
void declaration_visitor::visit(block *block)
{
for (variable_declaration *const variable : block->variables)
{
variable->accept(this);
}
for (statement *const body_statement : block->body)
{
body_statement->accept(this);
}
}
void declaration_visitor::visit(assign_statement *statement)
{
}
void declaration_visitor::visit(if_statement *statement)
{
}
void declaration_visitor::visit(while_statement *statement)
{
}
void declaration_visitor::visit(return_statement *statement)
{
}
void declaration_visitor::visit(defer_statement *statement)
{
}
void declaration_visitor::visit(procedure_call *call)
{
}
void declaration_visitor::visit(cast_expression *expression)
{
}
void declaration_visitor::visit(traits_expression *expression)
{
}
void declaration_visitor::visit(binary_expression *expression)
{
}
void declaration_visitor::visit(unary_expression *expression)
{
}
void declaration_visitor::visit(variable_expression *)
{
}
void declaration_visitor::visit(array_access_expression *)
{
}
void declaration_visitor::visit(field_access_expression *)
{
}
void declaration_visitor::visit(dereference_expression *)
{
}
}

View File

@ -22,7 +22,6 @@ namespace elna
namespace boot
{
type::type()
: tag(type_tag::alias)
{
}
@ -145,6 +144,7 @@ namespace boot
case type_tag::empty:
break;
case type_tag::alias:
this->alias.~weak_ptr<alias_type>();
break;
case type_tag::primitive:
this->primitive.~shared_ptr<primitive_type>();