aboutsummaryrefslogtreecommitdiff
path: root/boot/semantic.cc
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-14 01:45:58 +0200
committerEugen Wissner <belka@caraus.de>2026-07-14 01:45:58 +0200
commit51e2f98e33ae10fc3052335cc6847bc93d0784fa (patch)
tree7588effe2778d38d19adbf83cf23b5429df93691 /boot/semantic.cc
parent8ceb48a4e60b8ff89f28372da4f66cd152e2e0fe (diff)
downloadelna-51e2f98e33ae10fc3052335cc6847bc93d0784fa.tar.gz
Add static array initializer
Diffstat (limited to 'boot/semantic.cc')
-rw-r--r--boot/semantic.cc45
1 files changed, 43 insertions, 2 deletions
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<array_type>();
+
+ if (array == nullptr)
+ {
+ add_error<type_expectation_error>(type_expectation_error::kind::result, expression->position());
+ return;
+ }
+ if (expression->elements.size() > array->size)
+ {
+ add_error<argument_count_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>(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<array_type>(element_type, expression->size));
+ }
+
void name_analysis_visitor::visit(procedure_type_expression *expression)
{
std::shared_ptr<procedure_type> 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,