Parse import declarations

This commit is contained in:
2025-05-16 23:16:19 +02:00
parent 981059e745
commit 573d812f1c
9 changed files with 333 additions and 227 deletions

View File

@@ -308,8 +308,14 @@ namespace elna::boot
}
procedure_definition::procedure_definition(const struct position position, identifier_definition identifier,
procedure_type_expression *heading, block *body)
: definition(position, identifier), m_heading(heading), body(body)
procedure_type_expression *heading, block&& body)
: definition(position, identifier), m_heading(heading), body(std::move(body))
{
}
procedure_definition::procedure_definition(const struct position position, identifier_definition identifier,
procedure_type_expression *heading)
: definition(position, identifier), m_heading(heading), body(std::nullopt)
{
}
@@ -326,7 +332,6 @@ namespace elna::boot
procedure_definition::~procedure_definition()
{
delete m_heading;
delete body;
}
type_definition::type_definition(const struct position position, identifier_definition identifier,
@@ -350,34 +355,94 @@ namespace elna::boot
return *m_body;
}
block::block(const struct position position)
: node(position)
block::block(std::vector<constant_definition *>&& constants, std::vector<variable_declaration *>&& variables,
std::vector<statement *>&& body)
: m_variables(std::move(variables)), m_constants(std::move(constants)), m_body(std::move(body))
{
}
void block::accept(parser_visitor *visitor)
block::block(block&& that)
: m_variables(std::move(that.m_variables)), m_constants(std::move(that.m_constants)),
m_body(std::move(that.m_body))
{
visitor->visit(this);
}
block& block::operator=(block&& that)
{
std::swap(m_variables, that.m_variables);
std::swap(m_constants, that.m_constants);
std::swap(m_body, that.m_body);
return *this;
}
const std::vector<variable_declaration *>& block::variables()
{
return m_variables;
}
const std::vector<constant_definition *>& block::constants()
{
return m_constants;
}
const std::vector<statement *>& block::body()
{
return m_body;
}
block::~block()
{
for (statement *body_statement : this->body)
for (statement *body_statement : this->body())
{
delete body_statement;
}
for (variable_declaration *variable : this->variables)
for (variable_declaration *variable : this->variables())
{
delete variable;
}
for (constant_definition *constant : this->constants)
for (constant_definition *constant : this->constants())
{
delete constant;
}
}
unit::unit(const struct position position)
: node(position)
{
}
void unit::accept(parser_visitor *visitor)
{
visitor->visit(this);
}
unit::~unit()
{
for (procedure_definition *procedure : this->procedures)
{
delete procedure;
}
for (variable_declaration *variable : this->variables)
{
delete variable;
}
for (type_definition *type : this->types)
{
delete type;
}
for (constant_definition *constant : this->constants)
{
delete constant;
}
for (import_declaration *declaration : this->imports)
{
delete declaration;
}
}
program::program(const struct position position)
: block(position)
: unit(position)
{
}
@@ -388,13 +453,9 @@ namespace elna::boot
program::~program()
{
for (procedure_definition *procedure : this->procedures)
for (statement *body_statement : this->body)
{
delete procedure;
}
for (type_definition *type : this->types)
{
delete type;
delete body_statement;
}
}
@@ -837,13 +898,12 @@ namespace elna::boot
delete this->alternative;
}
escape_statement::escape_statement(const struct position position,
escape_direction direction, const std::string& label)
: node(position), direction(direction), label(label)
import_declaration::import_declaration(const struct position position, std::vector<std::string>&& segments)
: node(position), segments(std::move(segments))
{
}
void escape_statement::accept(parser_visitor *visitor)
void import_declaration::accept(parser_visitor *visitor)
{
visitor->visit(this);
}