aboutsummaryrefslogtreecommitdiff
path: root/boot/ast.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/ast.cc')
-rw-r--r--boot/ast.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index ec5b27d..a50d3d3 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -91,6 +91,11 @@ namespace elna::boot
__builtin_unreachable();
}
+ void empty_visitor::visit(for_statement *)
+ {
+ __builtin_unreachable();
+ }
+
void empty_visitor::visit(defer_statement *)
{
__builtin_unreachable();
@@ -286,6 +291,20 @@ namespace elna::boot
}
}
+ void walking_visitor::visit(for_statement *statement)
+ {
+ statement->initial_value().accept(this);
+ statement->final_value().accept(this);
+ if (statement->step != nullptr)
+ {
+ statement->step->accept(this);
+ }
+ for (auto *body_statement : statement->body)
+ {
+ body_statement->accept(this);
+ }
+ }
+
void walking_visitor::visit(defer_statement *statement)
{
for (auto *block_statement : statement->statements)
@@ -1522,6 +1541,41 @@ namespace elna::boot
}
}
+ for_statement::for_statement(const source_position position, identifier&& control_variable,
+ expression *initial_value, expression *final_value,
+ std::vector<statement *>&& body, expression *step)
+ : node(position), m_initial_value(initial_value), m_final_value(final_value),
+ control_variable(std::move(control_variable)), body(std::move(body)), step(step)
+ {
+ }
+
+ for_statement::~for_statement()
+ {
+ delete this->m_initial_value;
+ delete this->m_final_value;
+ delete this->step;
+
+ for (const statement *body_statement : this->body)
+ {
+ delete body_statement;
+ }
+ }
+
+ void for_statement::accept(parser_visitor *visitor)
+ {
+ visitor->visit(this);
+ }
+
+ expression& for_statement::initial_value()
+ {
+ return *this->m_initial_value;
+ }
+
+ expression& for_statement::final_value()
+ {
+ return *this->m_final_value;
+ }
+
const char *print_binary_operator(const binary_operator operation)
{
switch (operation)