diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-08-14 17:22:17 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-08-14 17:22:17 +0200 |
| commit | d696abc97143061bf2abb05922188e12b59306c1 (patch) | |
| tree | df8d2d1799e7036566d02e2201d159634d576481 /boot/evaluator.cc | |
| parent | bf7416a3ef9f0b787dcaebf816f3f3e6e385ff42 (diff) | |
| download | elna-d696abc97143061bf2abb05922188e12b59306c1.tar.gz | |
Use the new .is_a() for literal kind checks in the evaluator
Diffstat (limited to 'boot/evaluator.cc')
| -rw-r--r-- | boot/evaluator.cc | 50 |
1 files changed, 20 insertions, 30 deletions
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<std::pair<std::string, source_position>> non_constant_expression_error::note() const { - return std::visit([](const auto& payload) -> std::optional<std::pair<std::string, source_position>> { - using T = std::decay_t<decltype(payload)>; - - if constexpr (std::is_same_v<T, initializer>) - { - 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<initializer>(this->payload)) + { + return identifier_list_note(std::get<initializer>(this->payload).identifiers); + } + else + { + return std::nullopt; + } } std::optional<type_properties> get_type_properties(const type& subject, const target_info& target) @@ -239,33 +233,29 @@ namespace elna::boot std::optional<constant_value> 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<integer_literal>()) { - return constant_value{ static_cast<literal<integer_literal>&>(subject).value }; + return constant_value{ integer_subject->value }; } - else if (is_primitive_type(decoration, "Float")) + else if (auto *double_subject = subject.is_a<double>()) { - return constant_value{ static_cast<literal<double>&>(subject).value }; + return constant_value{ double_subject->value }; } - else if (is_primitive_type(decoration, "Bool")) + else if (auto *boolean_subject = subject.is_a<bool>()) { - return constant_value{ static_cast<literal<bool>&>(subject).value }; + return constant_value{ boolean_subject->value }; } - else if (is_primitive_type(decoration, "Char")) + else if (auto *character_subject = subject.is_a<unsigned char>()) { - return constant_value{ static_cast<literal<unsigned char>&>(subject).value }; + return constant_value{ character_subject->value }; } - else if (is_primitive_type(decoration, "Pointer")) + else if (auto *pointer_subject = subject.is_a<std::nullptr_t>()) { - 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<std::string>()) { - return constant_value{ static_cast<literal<std::string>&>(subject).value }; + return constant_value{ string_subject->value }; } return std::nullopt; } |
