Move type definitions to the program node
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
@ -126,8 +126,10 @@ program:
|
||||
{
|
||||
*value_definition++ = variable;
|
||||
}
|
||||
driver.tree = std::make_unique<elna::source::program>(elna::source::position{},
|
||||
auto tree = new elna::source::program(elna::source::position{},
|
||||
std::move(definitions), std::move(value_definitions), std::move($5));
|
||||
|
||||
driver.tree.reset(tree);
|
||||
}
|
||||
block: constant_part variable_part statement
|
||||
{
|
||||
@ -143,7 +145,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
|
||||
@ -285,7 +287,7 @@ expressions:
|
||||
}
|
||||
| expression { $$.emplace_back(std::move($1)); }
|
||||
designator_expression:
|
||||
designator_expression LEFT_SQUARE expression RIGHT_SQUARE
|
||||
designator_expression LEFT_SQUARE expression RIGHT_SQUARE
|
||||
{
|
||||
$$ = new elna::source::array_access_expression(elna::source::make_position(@1), $1, $3);
|
||||
}
|
||||
|
Reference in New Issue
Block a user