From b2f8be605d2b79d1d4b1995646e7058bec299a22 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 12 Jul 2026 23:17:06 +0200 Subject: Add fail_compilation tests --- boot/semantic.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'boot/semantic.cc') diff --git a/boot/semantic.cc b/boot/semantic.cc index 29925c2..d8a3c41 100644 --- a/boot/semantic.cc +++ b/boot/semantic.cc @@ -35,6 +35,8 @@ namespace elna::boot return "Type '" + identifier + "' not declared"; case kind::already: return "Symbol '" + identifier + "' has been already declared"; + case kind::local_export: + return "Local symbol '" + this->identifier + "' cannot be exported"; default: __builtin_unreachable(); } @@ -906,6 +908,10 @@ namespace elna::boot { type->accept(this); } + for (procedure_declaration *const procedure : unit->procedures) + { + procedure->accept(this); + } } void declaration_visitor::visit(type_declaration *declaration) @@ -919,6 +925,43 @@ namespace elna::boot } } + void declaration_visitor::visit(procedure_declaration *declaration) + { + if (!declaration->body.has_value()) + { + return; + } + for (constant_declaration *const constant : declaration->body.value().constants()) + { + constant->accept(this); + } + for (variable_declaration *const variable : declaration->body.value().variables()) + { + variable->accept(this); + } + } + + void declaration_visitor::visit(variable_declaration *declaration) + { + for (const identifier_definition& variable_identifier : declaration->identifiers) + { + if (variable_identifier.exported) + { + add_error(declaration_error::kind::local_export, + variable_identifier.name, declaration->position()); + } + } + } + + void declaration_visitor::visit(constant_declaration *declaration) + { + if (declaration->identifier.exported) + { + add_error(declaration_error::kind::local_export, + declaration->identifier.name, declaration->position()); + } + } + bool is_base_of(std::shared_ptr base, std::shared_ptr derived) { type current = derived->base; -- cgit v1.2.3