aboutsummaryrefslogtreecommitdiff
path: root/boot/name_analysis.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/name_analysis.cc')
-rw-r--r--boot/name_analysis.cc48
1 files changed, 44 insertions, 4 deletions
diff --git a/boot/name_analysis.cc b/boot/name_analysis.cc
index 5ad2a75..c82f211 100644
--- a/boot/name_analysis.cc
+++ b/boot/name_analysis.cc
@@ -1447,12 +1447,24 @@ namespace elna::boot
void declaration_visitor::visit(variable_declaration *declaration)
{
- const type variable_type = resolve_type(declaration->variable_type());
+ type variable_type;
std::optional<constant_value> computed;
if (declaration->initializer != nullptr)
{
declaration->initializer->accept(this);
+ if (declaration->variable_type == nullptr)
+ {
+ variable_type = declaration->initializer->type_decoration;
+ if (declaration->is_const)
+ {
+ variable_type = type(std::make_shared<constant_type>(variable_type));
+ }
+ }
+ else
+ {
+ variable_type = resolve_type(*declaration->variable_type);
+ }
computed = this->constant_evaluator.evaluate(*declaration->initializer);
if (!computed.has_value())
@@ -1461,13 +1473,21 @@ namespace elna::boot
non_constant_expression_error::initializer{ extract_identifiers(declaration->identifiers) });
}
}
- else if (!declaration->is_extern && resolve_aliases(variable_type).get<constant_type>() != nullptr)
+ else
{
+ if (declaration->variable_type != nullptr)
+ {
+ variable_type = resolve_type(*declaration->variable_type);
+ }
+ if (!declaration->is_extern && (declaration->variable_type == nullptr
+ || resolve_aliases(variable_type).get<constant_type>() != nullptr))
+ {
const source_position position_span = source_position(
declaration->identifiers.front().id().position().start(),
declaration->identifiers.back().id().position().end());
add_error<declaration_format_error>(position_span,
declaration_format_error::not_initialized{ extract_identifiers(declaration->identifiers) });
+ }
}
for (const auto& variable_identifier : declaration->identifiers)
{
@@ -1567,19 +1587,39 @@ namespace elna::boot
{
if (!this->bag.is_global())
{
- const type variable_type = resolve_type(declaration->variable_type());
+ type variable_type;
if (declaration->initializer != nullptr)
{
declaration->initializer->accept(this);
+ if (declaration->variable_type == nullptr)
+ {
+ variable_type = declaration->initializer->type_decoration;
+ if (declaration->is_const)
+ {
+ variable_type = type(std::make_shared<constant_type>(variable_type));
+ }
+ }
+ else
+ {
+ variable_type = resolve_type(*declaration->variable_type);
+ }
}
- else if (resolve_aliases(variable_type).get<constant_type>() != nullptr)
+ else
{
+ if (declaration->variable_type != nullptr)
+ {
+ variable_type = resolve_type(*declaration->variable_type);
+ }
+ if (declaration->variable_type == nullptr
+ || resolve_aliases(variable_type).get<constant_type>() != nullptr)
+ {
const source_position position_span = source_position(
declaration->identifiers.front().id().position().start(),
declaration->identifiers.back().id().position().end());
add_error<declaration_format_error>(position_span,
declaration_format_error::not_initialized{ extract_identifiers(declaration->identifiers) });
+ }
}
for (const auto& variable_identifier : declaration->identifiers)
{