From d696abc97143061bf2abb05922188e12b59306c1 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 14 Aug 2026 17:22:17 +0200 Subject: Use the new .is_a() for literal kind checks in the evaluator --- boot/evaluator.cc | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'boot/evaluator.cc') diff --git a/boot/evaluator.cc b/boot/evaluator.cc index d8d9ddc..07b2953 100644 --- a/boot/evaluator.cc +++ b/boot/evaluator.cc @@ -53,20 +53,14 @@ namespace elna::boot std::optional> non_constant_expression_error::note() const { - return std::visit([](const auto& payload) -> std::optional> { - using T = std::decay_t; - - if constexpr (std::is_same_v) - { - auto position_span = source_position(payload.identifiers.front().position().start(), - payload.identifiers.back().position().end()); - return std::make_pair(join(payload.identifiers), position_span); - } - else - { - return std::nullopt; - } - }, this->payload); + if (std::holds_alternative(this->payload)) + { + return identifier_list_note(std::get(this->payload).identifiers); + } + else + { + return std::nullopt; + } } std::optional get_type_properties(const type& subject, const target_info& target) @@ -239,33 +233,29 @@ namespace elna::boot std::optional evaluator::evaluate_literal(literal_expression& subject) { - // The type decoration here is trustable since the name analysis derives - // the decoration from literal's own value. - type const decoration = subject.type_decoration; - - if (is_primitive_type(decoration, "Int") || is_primitive_type(decoration, "Word")) + if (auto *integer_subject = subject.is_a()) { - return constant_value{ static_cast&>(subject).value }; + return constant_value{ integer_subject->value }; } - else if (is_primitive_type(decoration, "Float")) + else if (auto *double_subject = subject.is_a()) { - return constant_value{ static_cast&>(subject).value }; + return constant_value{ double_subject->value }; } - else if (is_primitive_type(decoration, "Bool")) + else if (auto *boolean_subject = subject.is_a()) { - return constant_value{ static_cast&>(subject).value }; + return constant_value{ boolean_subject->value }; } - else if (is_primitive_type(decoration, "Char")) + else if (auto *character_subject = subject.is_a()) { - return constant_value{ static_cast&>(subject).value }; + return constant_value{ character_subject->value }; } - else if (is_primitive_type(decoration, "Pointer")) + else if (auto *pointer_subject = subject.is_a()) { - return constant_value{ std::nullptr_t{} }; + return constant_value{ pointer_subject->value }; } - else if (is_string_type(decoration)) + else if (auto *string_subject = subject.is_a()) { - return constant_value{ static_cast&>(subject).value }; + return constant_value{ string_subject->value }; } return std::nullopt; } -- cgit v1.2.3