diff options
Diffstat (limited to 'boot/type_check.cc')
| -rw-r--r-- | boot/type_check.cc | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/boot/type_check.cc b/boot/type_check.cc index d9f3071..c5fb062 100644 --- a/boot/type_check.cc +++ b/boot/type_check.cc @@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see #include "elna/boot/type_check.h" #include <algorithm> +#include <utility> namespace elna::boot { @@ -33,7 +34,7 @@ namespace elna::boot type_mismatch_error::type_mismatch_error(const source_position position, type expected, type actual) - : error(position), expected(expected), actual(actual) + : error(position), expected(std::move(expected)), actual(std::move(actual)) { } @@ -45,7 +46,7 @@ namespace elna::boot constant_assignment_error::constant_assignment_error(const source_position position, type assignee) - : error(position), assignee(assignee) + : error(position), assignee(std::move(assignee)) { } @@ -57,15 +58,15 @@ namespace elna::boot field_not_found_error::field_not_found_error(const identifier& field_name, type composite_type) - : error(field_name.position()), field_name(field_name.name()), composite_type(composite_type) + : error(field_name.position()), field_name(field_name.name()), composite_type(std::move(composite_type)) { } std::string field_not_found_error::what() const { - type resolved = resolve_underlying_type(composite_type); - bool is_enum = resolved.get<enumeration_type>() != nullptr; - bool is_record = resolved.get<record_type>() != nullptr; + type const resolved = resolve_underlying_type(composite_type); + bool const is_enum = resolved.get<enumeration_type>() != nullptr; + bool const is_record = resolved.get<record_type>() != nullptr; if (is_enum || is_record) { @@ -87,16 +88,16 @@ namespace elna::boot duplicate_member_error::duplicate_member_error(const boot::identifier& member_name, type aggregate, std::optional<source_position> original, std::optional<std::string> base_name) - : error(member_name.position()), member_name(member_name.name()), aggregate(aggregate), - original(original), base_name(base_name) + : error(member_name.position()), member_name(member_name.name()), aggregate(std::move(aggregate)), + original(original), base_name(std::move(base_name)) { } std::string duplicate_member_error::what() const { - type resolved = resolve_underlying_type(aggregate); - bool is_enum = resolved.get<enumeration_type>() != nullptr; - std::string kind = is_enum ? "member" : "field"; + type const resolved = resolve_underlying_type(aggregate); + bool const is_enum = resolved.get<enumeration_type>() != nullptr; + std::string const kind = is_enum ? "member" : "field"; std::string message = is_enum ? "Enumeration" : "Record"; if (auto alias = aggregate.get<alias_type>()) @@ -142,7 +143,7 @@ namespace elna::boot return_error::return_error(const std::string& identifier, const source_position position, type return_type) - : error(position), identifier(identifier), return_type(return_type) + : error(position), identifier(identifier), return_type(std::move(return_type)) { } @@ -159,7 +160,7 @@ namespace elna::boot } base_type_error::base_type_error(type actual, const source_position position) - : error(position), actual(actual) + : error(position), actual(std::move(actual)) { } @@ -190,7 +191,7 @@ namespace elna::boot unsupported_trait_type_error::unsupported_trait_type_error(const identifier& trait, type actual) - : error(trait.position()), actual(actual), trait_name(trait.name()) + : error(trait.position()), actual(std::move(actual)), trait_name(trait.name()) { } @@ -201,22 +202,23 @@ namespace elna::boot } unary_operation_error::unary_operation_error(const source_position position, - type actual, unary_operator op) - : error(position), actual(actual), op(op) + type actual, unary_operator operation) + : error(position), actual(std::move(actual)), op(operation) { } - char unary_operation_error::unary_operator_symbol(unary_operator op) + char unary_operation_error::unary_operator_symbol(unary_operator operation) { - switch (op) + switch (operation) { - case unary_operator::reference: + using enum unary_operator; + case reference: return '@'; - case unary_operator::negation: + case negation: return '~'; - case unary_operator::minus: + case minus: return '-'; - case unary_operator::plus: + case plus: return '+'; } __builtin_unreachable(); @@ -261,10 +263,10 @@ namespace elna::boot return false; } - bool type_analysis_visitor::check_unresolved_symbol(std::shared_ptr<alias_type> alias, + bool type_analysis_visitor::check_unresolved_symbol(const std::shared_ptr<alias_type>& alias, std::vector<std::string>& alias_path) { - if (std::find(std::cbegin(alias_path), std::cend(alias_path), alias->name) != std::cend(alias_path)) + if (std::ranges::find(alias_path, alias->name) != std::cend(alias_path)) { return false; } @@ -295,7 +297,7 @@ namespace elna::boot return false; } - assign_check::verdict assign_check::guard_const_laundering() + assign_check::verdict assign_check::guard_const_laundering() const { if (!is_primitive_type(ctx.aliased_assignee, "Pointer")) { @@ -314,12 +316,12 @@ namespace elna::boot return verdict::pass; } - assign_check::verdict assign_check::check_exact_match() + assign_check::verdict assign_check::check_exact_match() const { return ctx.resolved_assignee == ctx.resolved_assignment ? verdict::accept : verdict::pass; } - assign_check::verdict assign_check::check_pointer_hatch() + assign_check::verdict assign_check::check_pointer_hatch() const { if (is_primitive_type(ctx.resolved_assignee, "Pointer") && is_any_pointer_type(ctx.resolved_assignment)) @@ -334,7 +336,7 @@ namespace elna::boot return verdict::pass; } - assign_check::verdict assign_check::check_pointer_conversion() + assign_check::verdict assign_check::check_pointer_conversion() const { auto assignee_ptr = ctx.resolved_assignee.get<pointer_type>(); auto assignment_ptr = ctx.resolved_assignment.get<pointer_type>(); @@ -394,7 +396,7 @@ namespace elna::boot } type_analysis_visitor::type_analysis_visitor(symbol_bag bag, const target_info& target) - : error_container(), bag(bag), target(target) + : bag(std::move(bag)), target(target) { } @@ -412,8 +414,8 @@ namespace elna::boot { if (declaration->body.value().return_expression != nullptr) { - expression *return_expr = declaration->body.value().return_expression; - type return_type = this->current_procedure->symbol.return_type.proper_type; + const expression *return_expr = declaration->body.value().return_expression; + type const return_type = this->current_procedure->symbol.return_type.proper_type; if (!return_type.empty()) { @@ -475,12 +477,12 @@ namespace elna::boot } // Record const variable initializers so later declarations // can chain through them. - for (const auto& id : declaration->identifiers) + for (const auto& identifier : declaration->identifiers) { - if (auto var = this->bag.lookup(id.name())->is_variable(); + if (auto var = this->bag.lookup(identifier.name())->is_variable(); resolve_aliases(var->symbol).get<constant_type>() != nullptr) { - this->evaluated_initializers[id.name()] = declaration->initializer; + this->evaluated_initializers[identifier.name()] = declaration->initializer; } } for (const identifier_definition& variable_identifier : declaration->identifiers) @@ -498,11 +500,11 @@ namespace elna::boot void type_analysis_visitor::visit(case_statement *statement) { walking_visitor::visit(statement); - type condition_type = resolve_underlying_type(statement->condition().type_decoration); + type const condition_type = resolve_underlying_type(statement->condition().type_decoration); for (const switch_case& case_block : statement->cases) { - for (expression *const case_label : case_block.labels) + for (const expression *case_label : case_block.labels) { if (!is_assignable_from(condition_type, case_label->type_decoration)) { @@ -532,7 +534,7 @@ namespace elna::boot { if (expression->base.has_value()) { - type base_type = resolve_underlying_type(this->bag.lookup(expression->base.value().name())->is_type()->symbol); + type const base_type = resolve_underlying_type(this->bag.lookup(expression->base.value().name())->is_type()->symbol); if (base_type.get<record_type>() == nullptr) { add_error<base_type_error>(base_type, expression->position()); @@ -617,7 +619,7 @@ namespace elna::boot expression->position()); return; } - for (auto element : expression->elements) + for (auto *element : expression->elements) { if (!is_assignable_from(array->base, element->type_decoration)) { @@ -631,33 +633,33 @@ namespace elna::boot { walking_visitor::visit(expression); - auto op = expression->operation(); - type resolved = resolve_underlying_type(expression->operand().type_decoration); + auto operation = expression->operation(); + type const resolved = resolve_underlying_type(expression->operand().type_decoration); - if (op == unary_operator::plus) + if (operation == unary_operator::plus) { if (!is_numeric_type(resolved)) { add_error<unary_operation_error>(expression->position(), - expression->operand().type_decoration, op); + expression->operand().type_decoration, operation); } } - else if (op == unary_operator::minus) + else if (operation == unary_operator::minus) { if (!is_primitive_type(resolved, "Int") && !is_primitive_type(resolved, "Float")) { add_error<unary_operation_error>(expression->position(), - expression->operand().type_decoration, op); + expression->operand().type_decoration, operation); } } - else if (op == unary_operator::negation) + else if (operation == unary_operator::negation) { if (!is_primitive_type(resolved, "Bool") && !is_integral_type(resolved)) { add_error<unary_operation_error>(expression->position(), - expression->operand().type_decoration, op); + expression->operand().type_decoration, operation); } } } |
