diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-09-24 00:39:51 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-09-24 00:39:51 +0200 |
| commit | f7b035a505e86ad916a43ab1dc1a662a6066b011 (patch) | |
| tree | a54369ae8ad56352d148c4583ab568f7d4869d30 /boot/evaluator.cc | |
| parent | 74e75e41fe12f19e5365a3152ffafa1a29376240 (diff) | |
| download | elna-f7b035a505e86ad916a43ab1dc1a662a6066b011.tar.gz | |
Move module heading to the top
Diffstat (limited to 'boot/evaluator.cc')
| -rw-r--r-- | boot/evaluator.cc | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/boot/evaluator.cc b/boot/evaluator.cc index 0085c62..6cf287c 100644 --- a/boot/evaluator.cc +++ b/boot/evaluator.cc @@ -66,7 +66,7 @@ namespace elna::boot std::optional<type_properties> get_type_properties(const type& subject, const target_info& target) { - auto resolved = resolve_underlying_type(subject); + const type resolved = resolve_underlying_type(subject); if (resolved.get<enumeration_type>() != nullptr) { @@ -78,7 +78,7 @@ namespace elna::boot return erased.empty() ? std::nullopt : get_type_properties(erased, target); } - else if (auto resolved_primitive = resolved.get<primitive_type>()) + else if (const auto resolved_primitive = resolved.get<primitive_type>()) { return resolved_primitive->properties; } @@ -93,7 +93,7 @@ namespace elna::boot { return target.pointer_properties; } - else if (auto array = resolved.get<array_type>()) + else if (const auto array = resolved.get<array_type>()) { if (auto element = get_type_properties(array->base, target)) { @@ -103,7 +103,7 @@ namespace elna::boot }; } } - else if (auto record = resolved.get<record_type>()) + else if (const auto record = resolved.get<record_type>()) { auto record_layout = layout_record(record, target); if (record_layout.has_value()) @@ -212,7 +212,7 @@ namespace elna::boot { return evaluate_traits(*traits); } - else if (auto *record_constructor = subject.is_record_constructor()) + else if (const auto *record_constructor = subject.is_record_constructor()) { ordered_map<constant_value> aggregate; @@ -227,7 +227,7 @@ namespace elna::boot } return constant_value{ constant_aggregate<ordered_map>{ std::move(aggregate) } }; } - else if (auto *array_constructor = subject.is_array_constructor()) + else if (const auto *array_constructor = subject.is_array_constructor()) { std::vector<constant_value> elements; for (expression *element : array_constructor->elements) @@ -275,13 +275,13 @@ namespace elna::boot std::optional<constant_value> evaluator::evaluate_named(named_expression& subject) { - auto symbol = this->bag.lookup(subject.name); + const std::shared_ptr<info> symbol = this->bag.lookup(subject.name); if (symbol == nullptr) { return std::nullopt; } - auto variable = symbol->is_variable(); + const std::shared_ptr<variable_info> variable = symbol->is_variable(); if (variable == nullptr || resolve_aliases(variable->symbol).get<constant_type>() == nullptr) @@ -315,17 +315,17 @@ namespace elna::boot // reading the type decoration set by name analysis. if (auto *base_designator = subject.base().is_designator()) { - if (auto *base_name = base_designator->is_named()) + if (const auto *base_name = base_designator->is_named()) { - auto symbol = this->bag.lookup(base_name->name); + const std::shared_ptr<info> symbol = this->bag.lookup(base_name->name); if (symbol != nullptr) { - if (auto type_symbol = symbol->is_type()) + if (const auto type_symbol = symbol->is_type()) { - if (auto enumeration = resolve_underlying_type(type_symbol->symbol).get<enumeration_type>()) + if (const auto enumeration = resolve_underlying_type(type_symbol->symbol).get<enumeration_type>()) { - auto member_iterator = std::ranges::find(enumeration->members, subject.field().name()); + const auto member_iterator = std::ranges::find(enumeration->members, subject.field().name()); if (member_iterator == enumeration->members.end()) { @@ -344,7 +344,7 @@ namespace elna::boot { if (auto *record = std::get_if<constant_aggregate<ordered_map>>(&base.value())) { - auto field_iterator = (*record)->find(subject.field().name()); + const auto field_iterator = (*record)->find(subject.field().name()); return field_iterator != std::cend(**record) ? std::make_optional(field_iterator->second) @@ -355,7 +355,7 @@ namespace elna::boot { return constant_value{ integer_literal::from((*vector)->size()) }; } - else if (auto *string_value = std::get_if<std::string>(&base.value()); subject.field() == "length") + else if (const auto *string_value = std::get_if<std::string>(&base.value()); subject.field() == "length") { return constant_value{ integer_literal::from(string_value->size()) }; } @@ -370,7 +370,7 @@ namespace elna::boot { return std::nullopt; } - auto& index_literal = std::get<integer_literal>(evaluated_index.value()); + const integer_literal& index_literal = std::get<integer_literal>(evaluated_index.value()); return index_literal < 0 ? std::nullopt : index_literal.try_to<std::size_t>(); } @@ -389,8 +389,8 @@ namespace elna::boot { return std::nullopt; } - auto slice_begin = std::next((*array)->begin(), static_cast<std::ptrdiff_t>(start_index.value() - 1)); - auto slice_end = std::next((*array)->begin(), static_cast<std::ptrdiff_t>(end_index.value())); + const auto slice_begin = std::next((*array)->begin(), static_cast<std::ptrdiff_t>(start_index.value() - 1)); + const auto slice_end = std::next((*array)->begin(), static_cast<std::ptrdiff_t>(end_index.value())); return constant_value{ constant_aggregate<std::vector>{ std::vector<constant_value>(slice_begin, slice_end) } @@ -687,7 +687,7 @@ namespace elna::boot } return std::visit([&rhs, operation = subject.operation()](auto&& lhs_value) { using T = std::decay_t<decltype(lhs_value)>; - auto rhs_value = std::get<T>(rhs.value()); + const T rhs_value = std::get<T>(rhs.value()); return evaluate_operation<T>(operation, lhs_value, rhs_value); }, lhs.value()); @@ -921,13 +921,11 @@ namespace elna::boot { return source_expression; } - if (const auto *address = std::get_if<integer_literal>(&source_expression)) + // Only the null pointer has a constant representation. + else if (const auto *address = std::get_if<integer_literal>(&source_expression); + *address == std::ptrdiff_t{ 0 }) { - // Only the null pointer has a constant representation. - if (*address == std::ptrdiff_t{ 0 }) - { - return constant_value{ nullptr }; - } + return constant_value{ nullptr }; } return std::nullopt; } @@ -1056,7 +1054,7 @@ namespace elna::boot { return constant_value{ float_literal::from(std::numeric_limits<double>::min()) }; } - if (auto enumeration = resolved.get<enumeration_type>()) + if (const auto enumeration = resolved.get<enumeration_type>()) { return constant_value{ integer_literal::from<std::size_t>(1) }; } @@ -1101,22 +1099,22 @@ namespace elna::boot { return constant_value{ float_literal::from(std::numeric_limits<double>::max()) }; } - if (auto enumeration = resolved.get<enumeration_type>()) + if (const auto enumeration = resolved.get<enumeration_type>()) { return constant_value{ integer_literal::from(enumeration->members.size()) }; } } else if (subject.name.name() == "offset") { - auto *field = subject.arguments.at(1)->is_named(); - auto record = erase_generic(subject.types.front()).get<record_type>(); + const named_expression *field = subject.arguments.at(1)->is_named(); + const std::shared_ptr<record_type> record = erase_generic(subject.types.front()).get<record_type>(); if (field == nullptr || record == nullptr) { return std::nullopt; } if (auto record_layout = layout_record(record, this->target)) { - auto field_search = record_layout.value().offset_map.find(field->name); + const auto field_search = record_layout.value().offset_map.find(field->name); if (field_search != std::cend(record_layout.value().offset_map)) { |
