diff options
Diffstat (limited to 'boot/evaluator.cc')
| -rw-r--r-- | boot/evaluator.cc | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/boot/evaluator.cc b/boot/evaluator.cc index 1acadd3..b7edd3a 100644 --- a/boot/evaluator.cc +++ b/boot/evaluator.cc @@ -86,7 +86,7 @@ namespace elna::boot std::optional<constant_value> evaluator::evaluate_literal(literal_expression& subject) { - type decoration = subject.type_decoration; + type const decoration = subject.type_decoration; if (is_primitive_type(decoration, "Int")) { @@ -171,16 +171,16 @@ namespace elna::boot } if (subject.operation() == unary_operator::negation) { - return std::visit([](auto v) -> std::optional<constant_value> { - using T = std::decay_t<decltype(v)>; + return std::visit([](auto value) -> std::optional<constant_value> { + using T = std::decay_t<decltype(value)>; if constexpr (std::is_same_v<T, bool>) { - return constant_value{ !v }; + return constant_value{ !value }; } else if constexpr (std::is_integral_v<T>) { - return constant_value{ ~v }; + return constant_value{ ~value }; } return std::nullopt; }, operand.value()); @@ -232,16 +232,17 @@ namespace elna::boot } template<typename T> - static std::optional<constant_value> evaluate_operation(binary_operator op, T lhs, T rhs) + static std::optional<constant_value> evaluate_operation(binary_operator operation, T lhs, T rhs) { if constexpr (std::is_same_v<T, std::nullptr_t> || std::is_same_v<T, compound_constant>) { - switch (op) + switch (operation) { - case binary_operator::equals: + using enum binary_operator; + case equals: return constant_value{ true }; - case binary_operator::not_equals: + case not_equals: return constant_value{ false }; default: return std::nullopt; @@ -249,36 +250,37 @@ namespace elna::boot } else { - switch (op) + switch (operation) { - case binary_operator::sum: + using enum binary_operator; + case sum: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { - if (auto r = add_overflow(lhs, rhs)) + if (auto result = add_overflow(lhs, rhs)) { - return constant_value{ *r }; + return constant_value{ *result }; } } return std::nullopt; - case binary_operator::subtraction: + case subtraction: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { - if (auto r = sub_overflow(lhs, rhs)) + if (auto result = sub_overflow(lhs, rhs)) { - return constant_value{ *r }; + return constant_value{ *result }; } } return std::nullopt; - case binary_operator::multiplication: + case multiplication: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { - if (auto r = mul_overflow(lhs, rhs)) + if (auto result = mul_overflow(lhs, rhs)) { - return constant_value{ *r }; + return constant_value{ *result }; } } return std::nullopt; - case binary_operator::division: + case division: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { if (rhs != static_cast<T>(0)) @@ -287,7 +289,7 @@ namespace elna::boot } } return std::nullopt; - case binary_operator::remainder: + case remainder: if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) { if (rhs != static_cast<T>(0)) @@ -296,25 +298,25 @@ namespace elna::boot } } return std::nullopt; - case binary_operator::disjunction: + case disjunction: if constexpr (std::is_integral_v<T>) { return constant_value{ lhs | rhs }; } return std::nullopt; - case binary_operator::conjunction: + case conjunction: if constexpr (std::is_integral_v<T>) { return constant_value{ lhs & rhs }; } return std::nullopt; - case binary_operator::exclusive_disjunction: + case exclusive_disjunction: if constexpr (std::is_integral_v<T>) { return constant_value{ lhs ^ rhs }; } return std::nullopt; - case binary_operator::shift_left: + case shift_left: if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) { if (rhs < 0 || static_cast<std::make_unsigned_t<T>>(rhs) >= std::numeric_limits<T>::digits) @@ -324,35 +326,35 @@ namespace elna::boot return constant_value{ lhs << rhs }; } return std::nullopt; - case binary_operator::shift_right: + case shift_right: if constexpr (std::is_integral_v<T>) { return constant_value{ lhs >> rhs }; } return std::nullopt; - case binary_operator::equals: + case equals: return constant_value{ lhs == rhs }; - case binary_operator::not_equals: + case not_equals: return constant_value{ lhs != rhs }; - case binary_operator::less: + case less: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { return constant_value{ lhs < rhs }; } return std::nullopt; - case binary_operator::greater: + case greater: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { return constant_value{ lhs > rhs }; } return std::nullopt; - case binary_operator::less_equal: + case less_equal: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { return constant_value{ lhs <= rhs }; } return std::nullopt; - case binary_operator::greater_equal: + case greater_equal: if constexpr (std::is_arithmetic_v<T> && !std::is_same_v<T, bool>) { return constant_value{ lhs >= rhs }; @@ -373,7 +375,7 @@ namespace elna::boot { return std::nullopt; } - return std::visit([this, &rhs, operation = subject.operation()](auto&& lhs_value) { + 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()); @@ -395,7 +397,7 @@ namespace elna::boot std::optional<std::size_t> evaluator::evaluate_traits_size(const type& subject) { - type resolved = resolve_underlying_type(subject); + type const resolved = resolve_underlying_type(subject); if (is_primitive_type(resolved, "Int")) { @@ -413,11 +415,8 @@ namespace elna::boot { return target.float_size; } - else if (is_primitive_type(resolved, "Pointer")) - { - return target.pointer_size; - } - else if (resolved.get<pointer_type>() != nullptr) + else if (is_primitive_type(resolved, "Pointer") + || resolved.get<pointer_type>() != nullptr) { return target.pointer_size; } @@ -433,7 +432,7 @@ namespace elna::boot std::optional<std::size_t> evaluator::evaluate_traits_alignment(const type& subject) { - type resolved = resolve_underlying_type(subject); + type const resolved = resolve_underlying_type(subject); if (is_primitive_type(resolved, "Int")) { @@ -521,7 +520,7 @@ namespace elna::boot } else if (subject.name.name() == "min") { - type resolved = resolve_underlying_type(subject.types.front()); + type const resolved = resolve_underlying_type(subject.types.front()); if (is_primitive_type(resolved, "Int")) { @@ -542,7 +541,7 @@ namespace elna::boot } else if (subject.name.name() == "max") { - type resolved = resolve_underlying_type(subject.types.front()); + type const resolved = resolve_underlying_type(subject.types.front()); if (is_primitive_type(resolved, "Int")) { @@ -554,7 +553,7 @@ namespace elna::boot } if (is_primitive_type(resolved, "Char")) { - return constant_value{ static_cast<unsigned char>(255) }; + return constant_value{ std::numeric_limits<unsigned char>::max() }; } if (auto enumeration = resolved.get<enumeration_type>()) { |
