diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-10-09 23:35:03 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-10-09 23:35:03 +0200 |
| commit | da1e84e33de1a9c2cc1745b8f42bc7f0cee8fc5c (patch) | |
| tree | 6222ecd61c9d6e9d59c6169b99e4a24a5d347fea /boot/ast.cc | |
| parent | 134d3ac4caff6d87c79b0892e57073594cb0064c (diff) | |
| download | elna-da1e84e33de1a9c2cc1745b8f42bc7f0cee8fc5c.tar.gz | |
Add const sections
Diffstat (limited to 'boot/ast.cc')
| -rw-r--r-- | boot/ast.cc | 41 |
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); } |
