Parse import declarations
This commit is contained in:
@ -75,33 +75,8 @@ namespace elna::boot
|
||||
|
||||
void declaration_visitor::visit(program *program)
|
||||
{
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
const std::string& type_identifier = type->identifier.identifier;
|
||||
visit(static_cast<unit *>(program));
|
||||
|
||||
if (!this->unresolved.insert({ type_identifier, std::make_shared<alias_type>(type_identifier) }).second
|
||||
|| this->symbols->contains(type_identifier))
|
||||
{
|
||||
add_error<already_declared_error>(type->identifier.identifier, this->input_file, type->position());
|
||||
}
|
||||
}
|
||||
for (type_definition *const type : program->types)
|
||||
{
|
||||
type->accept(this);
|
||||
}
|
||||
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);
|
||||
}
|
||||
for (variable_declaration *const variable : program->variables)
|
||||
{
|
||||
variable->accept(this);
|
||||
}
|
||||
for (procedure_definition *const procedure : program->procedures)
|
||||
{
|
||||
procedure->accept(this);
|
||||
}
|
||||
for (statement *const statement : program->body)
|
||||
{
|
||||
statement->accept(this);
|
||||
@ -205,9 +180,20 @@ namespace elna::boot
|
||||
build_procedure(definition->heading()), definition->parameter_names);
|
||||
|
||||
this->symbols->enter(definition->identifier.identifier, info);
|
||||
if (definition->body != nullptr)
|
||||
if (definition->body.has_value())
|
||||
{
|
||||
definition->body->accept(this);
|
||||
for (constant_definition *const constant : definition->body.value().constants())
|
||||
{
|
||||
constant->accept(this);
|
||||
}
|
||||
for (variable_declaration *const variable : definition->body.value().variables())
|
||||
{
|
||||
variable->accept(this);
|
||||
}
|
||||
for (statement *const statement : definition->body.value().body())
|
||||
{
|
||||
statement->accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,7 +228,7 @@ namespace elna::boot
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(escape_statement *)
|
||||
void declaration_visitor::visit(import_declaration *)
|
||||
{
|
||||
}
|
||||
|
||||
@ -305,19 +291,34 @@ namespace elna::boot
|
||||
}
|
||||
}
|
||||
|
||||
void declaration_visitor::visit(block *block)
|
||||
void declaration_visitor::visit(unit *unit)
|
||||
{
|
||||
for (constant_definition *const constant : block->constants)
|
||||
for (type_definition *const type : unit->types)
|
||||
{
|
||||
constant->accept(this);
|
||||
const std::string& type_identifier = type->identifier.identifier;
|
||||
|
||||
if (!this->unresolved.insert({ type_identifier, std::make_shared<alias_type>(type_identifier) }).second
|
||||
|| this->symbols->contains(type_identifier))
|
||||
{
|
||||
add_error<already_declared_error>(type->identifier.identifier, this->input_file, type->position());
|
||||
}
|
||||
}
|
||||
for (variable_declaration *const variable : block->variables)
|
||||
for (type_definition *const type : unit->types)
|
||||
{
|
||||
type->accept(this);
|
||||
}
|
||||
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);
|
||||
}
|
||||
for (variable_declaration *const variable : unit->variables)
|
||||
{
|
||||
variable->accept(this);
|
||||
}
|
||||
for (statement *const statement : block->body)
|
||||
for (procedure_definition *const procedure : unit->procedures)
|
||||
{
|
||||
statement->accept(this);
|
||||
procedure->accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user