Move type definitions to the program node

This commit is contained in:
Eugen Wissner 2025-01-12 10:35:24 +01:00
parent 7985704981
commit 065fbe6167
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
4 changed files with 26 additions and 26 deletions

View File

@ -100,7 +100,7 @@ namespace gcc
void generic_visitor::visit(source::program *program)
{
for (const auto& constant : program->definitions())
for (const auto& constant : program->type_definitions)
{
constant->accept(this);
}

View File

@ -596,19 +596,16 @@ namespace source
class block : public node
{
std::vector<definition *> m_definitions;
statement *m_body;
public:
std::vector<definition *> value_definitions;
block(const struct position position, std::vector<definition *>&& definitions,
std::vector<definition *>&& value_definitions,
block(const struct position position, std::vector<definition *>&& value_definitions,
statement *body);
virtual void accept(parser_visitor *visitor) override;
statement& body();
std::vector<definition *>& definitions();
virtual ~block() override;
};
@ -616,9 +613,13 @@ namespace source
class program : public block
{
public:
program(const struct position position, std::vector<definition *>&& definitions,
std::vector<definition *> type_definitions;
program(const struct position position, std::vector<definition *>&& type_definitions,
std::vector<definition *>&& value_definitions, statement *body);
virtual void accept(parser_visitor *visitor) override;
virtual ~program() override;
};
template<typename T>

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