Move type definitions to the program node

This commit is contained in:
2025-01-12 10:35:24 +01:00
parent 7985704981
commit 3bf9189d8d
8 changed files with 160 additions and 47 deletions

View File

@ -65,10 +65,6 @@ namespace source
void empty_visitor::visit(block *block)
{
for (const auto& constant : block->definitions())
{
constant->accept(this);
}
for (const auto& definition : block->value_definitions)
{
definition->accept(this);
@ -78,6 +74,10 @@ namespace source
void empty_visitor::visit(program *program)
{
for (auto definition : program->type_definitions)
{
definition->accept(this);
}
visit(reinterpret_cast<block *>(program));
}
@ -447,11 +447,9 @@ namespace source
delete m_body;
}
block::block(const struct position position, std::vector<definition *>&& definitions,
std::vector<definition *>&& value_definitions,
block::block(const struct position position, std::vector<definition *>&& value_definitions,
statement *body)
: node(position), m_definitions(std::move(definitions)),
m_body(std::move(body)), value_definitions(std::move(value_definitions))
: node(position), m_body(std::move(body)), value_definitions(std::move(value_definitions))
{
}
@ -460,11 +458,6 @@ namespace source
visitor->visit(this);
}
std::vector<definition *>& block::definitions()
{
return m_definitions;
}
statement& block::body()
{
return *m_body;
@ -472,10 +465,6 @@ namespace source
block::~block()
{
for (auto definition : m_definitions)
{
delete definition;
}
for (auto definition : value_definitions)
{
delete definition;
@ -483,9 +472,11 @@ namespace source
delete m_body;
}
program::program(const struct position position, std::vector<definition *>&& definitions,
program::program(const struct position position,
std::vector<definition *>&& type_definitions,
std::vector<definition *>&& value_definitions, statement *body)
: block(position, std::move(definitions), std::move(value_definitions), body)
: block(position, std::move(value_definitions), body),
type_definitions(std::move(type_definitions))
{
}
@ -494,6 +485,14 @@ namespace source
visitor->visit(this);
}
program::~program()
{
for (auto definition : type_definitions)
{
delete definition;
}
}
char_literal::char_literal(const struct position position, const unsigned char value)
: expression(position), m_character(value)
{

View File

@ -143,7 +143,7 @@ block: constant_part variable_part statement
*definition++ = variable;
}
$$ = new elna::source::block(elna::source::position{},
{}, std::move(definitions), std::move($3));
std::move(definitions), std::move($3));
};
procedure_definition:
PROCEDURE IDENTIFIER formal_parameter_list SEMICOLON block SEMICOLON