aboutsummaryrefslogtreecommitdiff
path: root/boot/ast.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/ast.cc')
-rw-r--r--boot/ast.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index edc10a7..15e4928 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -72,6 +72,11 @@ namespace elna::boot
__builtin_unreachable();
}
+ void empty_visitor::visit(constant_declaration *)
+ {
+ __builtin_unreachable();
+ }
+
void empty_visitor::visit(procedure_declaration *)
{
__builtin_unreachable();
@@ -357,6 +362,11 @@ namespace elna::boot
}
}
+ void walking_visitor::visit(constant_declaration *declaration)
+ {
+ declaration->initializer->accept(this);
+ }
+
void walking_visitor::visit(array_type_expression *expression)
{
expression->base().accept(this);
@@ -1007,6 +1017,31 @@ namespace elna::boot
return *m_underlying_type;
}
+ constant_declaration::constant_declaration(const source_position position,
+ identifier_definition identifier, expression *const initializer)
+ : node(position), identifier(std::move(identifier)), initializer(initializer)
+ {
+ }
+
+ constant_declaration::~constant_declaration()
+ {
+ delete this->initializer;
+ }
+
+ void constant_declaration::accept(parser_visitor *visitor)
+ {
+ visitor->visit(this);
+ }
+
+ block::block(std::vector<constant_declaration *>&& constants,
+ std::vector<variable_declaration *>&& variables,
+ std::vector<statement *>&& statements)
+ : constants(std::move(constants)),
+ variables(std::move(variables)),
+ statements(std::move(statements))
+ {
+ }
+
block::block(std::vector<variable_declaration *>&& variables, std::vector<statement *>&& statements)
: variables(std::move(variables)), statements(std::move(statements))
{
@@ -1014,6 +1049,7 @@ namespace elna::boot
block& block::operator=(block&& that) noexcept
{
+ std::swap(this->constants, that.constants);
std::swap(this->variables, that.variables);
std::swap(this->statements, that.statements);
std::swap(this->symbols, that.symbols);
@@ -1031,6 +1067,10 @@ namespace elna::boot
{
delete variable;
}
+ for (const constant_declaration *constant : this->constants)
+ {
+ delete constant;
+ }
}
procedure_body::procedure_body(block&& body, expression *return_expression)
@@ -1059,6 +1099,7 @@ namespace elna::boot
void traverse_block(parser_visitor *visitor, const block& body)
{
+ visit_all(visitor, body.constants);
visit_all(visitor, body.variables);
visit_all(visitor, body.statements);
}