From 51e2f98e33ae10fc3052335cc6847bc93d0784fa Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 14 Jul 2026 01:45:58 +0200 Subject: Add static array initializer --- boot/semantic.cc | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'boot/semantic.cc') diff --git a/boot/semantic.cc b/boot/semantic.cc index f46dce9..f42b094 100644 --- a/boot/semantic.cc +++ b/boot/semantic.cc @@ -343,6 +343,31 @@ namespace elna::boot } } + void type_analysis_visitor::visit(array_constructor_expression *expression) + { + auto array = inner_aliased_type(expression->type_decoration).get(); + + if (array == nullptr) + { + add_error(type_expectation_error::kind::result, expression->position()); + return; + } + if (expression->elements.size() > array->size) + { + add_error(array->size, expression->elements.size(), + expression->position()); + return; + } + for (auto element : expression->elements) + { + if (!is_assignable_from(array->base, element->type_decoration)) + { + add_error(type_expectation_error::kind::argument, + element->position()); + } + } + } + name_analysis_visitor::name_analysis_visitor(symbol_bag bag) : error_container(), bag(bag) { @@ -588,6 +613,17 @@ namespace elna::boot } } + void name_analysis_visitor::visit(array_constructor_expression *expression) + { + expression->m_element_type->accept(this); + auto element_type = this->current_type; + for (auto element : expression->elements) + { + element->accept(this); + } + expression->type_decoration = type(std::make_shared(element_type, expression->size)); + } + void name_analysis_visitor::visit(procedure_type_expression *expression) { std::shared_ptr result_type = @@ -617,8 +653,13 @@ namespace elna::boot void name_analysis_visitor::visit(variable_declaration *declaration) { - walking_visitor::visit(declaration); - + declaration->variable_type().accept(this); + auto variable_type = this->current_type; + if (declaration->initializer != nullptr) + { + declaration->initializer->accept(this); + this->current_type = variable_type; + } for (const identifier_definition& variable_identifier : declaration->identifiers) { auto variable_symbol = register_variable(variable_identifier.name, declaration->is_extern, -- cgit v1.2.3