mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
operator typecheck refactoring
This commit is contained in:
parent
78de51f6f2
commit
5167986ddf
1 changed files with 35 additions and 52 deletions
|
|
@ -574,42 +574,12 @@ void TypeCheckVisitor::Visit(BinaryOperatorExpression* node) {
|
|||
auto maybe_operator_id = namespace_visitor_.FindFunction(std::nullopt, node->operator_name);
|
||||
const info::definition::Function* operator_info = nullptr;
|
||||
|
||||
bool is_method = false;
|
||||
|
||||
if (maybe_operator_id.has_value()) {
|
||||
operator_info = &namespace_visitor_.GetGlobalInfo()->GetFunctionInfo(maybe_operator_id.value());
|
||||
|
||||
if (!operator_info->declaration.has_value()) {
|
||||
error_handling::HandleTypecheckError("Operator declaration not found", node->base);
|
||||
}
|
||||
|
||||
if (!operator_info->definition.has_value()) { // TODO: builtin, etc.
|
||||
error_handling::HandleTypecheckError("Operator definition not found", node->base);
|
||||
}
|
||||
|
||||
if (operator_info->argument_count != 3) { // 2 + return type
|
||||
error_handling::HandleTypecheckError("Operator wrong argument count", node->base);
|
||||
}
|
||||
|
||||
if (operator_info->declaration->parameters.size() > 0) {
|
||||
error_handling::HandleTypecheckError("Operator with parameters", node->base);
|
||||
}
|
||||
|
||||
Visitor::Visit(*operator_info->declaration.value().argument_types[0]);
|
||||
utils::IdType left_expression_type = current_type_; // TODO: type in context of deduced types
|
||||
|
||||
Visitor::Visit(node->left_expression);
|
||||
if (!context_manager_.AddTypeRequirement(current_type_, left_expression_type)) {
|
||||
error_handling::HandleTypecheckError("Operator left expression has wrong type", node->base);
|
||||
}
|
||||
|
||||
Visitor::Visit(*operator_info->declaration.value().argument_types[1]);
|
||||
utils::IdType right_expression_type = current_type_; // TODO: type in context of deduced types
|
||||
|
||||
Visitor::Visit(node->right_expression);
|
||||
if (!context_manager_.AddTypeRequirement(current_type_, right_expression_type)) {
|
||||
error_handling::HandleTypecheckError("Operator right expression has wrong type", node->base);
|
||||
}
|
||||
is_method = false;
|
||||
} else {
|
||||
|
||||
Visitor::Visit(node->left_expression);
|
||||
auto maybe_left_type = context_manager_.GetType<info::type::DefinedType>(current_type_);
|
||||
|
||||
|
|
@ -648,30 +618,43 @@ void TypeCheckVisitor::Visit(BinaryOperatorExpression* node) {
|
|||
}
|
||||
|
||||
operator_info = &namespace_visitor_.GetGlobalInfo()->GetFunctionInfo(maybe_operator_id.value());
|
||||
is_method = true;
|
||||
}
|
||||
|
||||
if (!operator_info->declaration.has_value()) {
|
||||
error_handling::HandleTypecheckError("Operator declaration not found", node->base);
|
||||
if (!operator_info->declaration.has_value()) {
|
||||
error_handling::HandleTypecheckError("Operator declaration not found", node->base);
|
||||
}
|
||||
|
||||
if (!operator_info->definition.has_value()) { // TODO: builtin, etc.
|
||||
error_handling::HandleTypecheckError("Operator definition not found", node->base);
|
||||
}
|
||||
|
||||
if (operator_info->argument_count != (is_method ? 2 : 3)) { // 2 + return type
|
||||
error_handling::HandleTypecheckError("Operator wrong argument count", node->base);
|
||||
}
|
||||
|
||||
if (operator_info->declaration->parameters.size() > 0) {
|
||||
error_handling::HandleTypecheckError("Operator with parameters", node->base);
|
||||
}
|
||||
|
||||
if (!is_method) {
|
||||
|
||||
Visitor::Visit(*operator_info->declaration.value().argument_types[0]);
|
||||
utils::IdType left_expression_type = current_type_; // TODO: type in context of deduced types
|
||||
|
||||
Visitor::Visit(node->left_expression);
|
||||
if (!context_manager_.AddTypeRequirement(current_type_, left_expression_type)) {
|
||||
error_handling::HandleTypecheckError("Operator left expression has wrong type", node->base);
|
||||
}
|
||||
|
||||
if (!operator_info->definition.has_value()) { // TODO: builtin, etc.
|
||||
error_handling::HandleTypecheckError("Operator definition not found", node->base);
|
||||
}
|
||||
}
|
||||
|
||||
if (operator_info->argument_count != 2) { // argument + return type
|
||||
error_handling::HandleTypecheckError("Operator wrong argument count", node->base);
|
||||
}
|
||||
Visitor::Visit(*operator_info->declaration.value().argument_types[is_method ? 0 : 1]);
|
||||
utils::IdType right_expression_type = current_type_; // TODO: type in context of deduced types
|
||||
|
||||
if (operator_info->declaration->parameters.size() > 0) {
|
||||
error_handling::HandleTypecheckError("Operator with parameters", node->base);
|
||||
}
|
||||
|
||||
Visitor::Visit(*operator_info->declaration.value().argument_types[9]);
|
||||
utils::IdType right_expression_type = current_type_; // TODO: type in context of deduced types
|
||||
|
||||
Visitor::Visit(node->right_expression);
|
||||
if (!context_manager_.AddTypeRequirement(current_type_, right_expression_type)) {
|
||||
error_handling::HandleTypecheckError("Operator right expression has wrong type", node->base);
|
||||
}
|
||||
Visitor::Visit(node->right_expression);
|
||||
if (!context_manager_.AddTypeRequirement(current_type_, right_expression_type)) {
|
||||
error_handling::HandleTypecheckError("Operator right expression has wrong type", node->base);
|
||||
}
|
||||
|
||||
node->function_id_ = maybe_operator_id.value(); // IMPORTANT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue