From da1e84e33de1a9c2cc1745b8f42bc7f0cee8fc5c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 9 Oct 2026 23:35:03 +0200 Subject: Add const sections --- boot/ast.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'boot/ast.cc') 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&& constants, + std::vector&& variables, + std::vector&& statements) + : constants(std::move(constants)), + variables(std::move(variables)), + statements(std::move(statements)) + { + } + block::block(std::vector&& variables, std::vector&& 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); } -- cgit v1.2.3