From 1289dda8386f1f003313a5f6faad9e2f80dda235 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Mon, 24 Apr 2023 21:51:20 +0300 Subject: [PATCH] going to fix grammar --- include/symbols_info.hpp | 8 +++++++- src/type_check_visitor.cpp | 29 +++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/symbols_info.hpp b/include/symbols_info.hpp index b7e48b2..645e4d2 100644 --- a/include/symbols_info.hpp +++ b/include/symbols_info.hpp @@ -79,7 +79,13 @@ struct AnyTypeInfo { interpreter::tokens::AnyType* value; }; -struct TypeInfo { std::variant type; }; +struct TypeInfo { std::variant type; }; + +struct ConstructorInfo { + std::string name; + size_t order; + utils::IdType type_id; +}; struct FunctionDeclarationInfo { std::vector parameters; diff --git a/src/type_check_visitor.cpp b/src/type_check_visitor.cpp index 2af3584..da56801 100644 --- a/src/type_check_visitor.cpp +++ b/src/type_check_visitor.cpp @@ -392,18 +392,28 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) { info::type::FunctionType type_value = std::get(context_manager_.GetType(current_type_)); - if (type_value.argument_types.size() != node->arguments.size()) { - error_handling::HandleTypecheckError("Mismatched argument count in function call expression"); - } + size_t argument_num = 0; + size_t paramater_num = 0; for (size_t i = 0; i < node->arguments.size(); ++i) { Visitor::Visit(node->arguments[i]); - if (std::holds_alternative(node->arguments[i])) { - } else if (std::holds_alternative(node->arguments[i])) { + if (std::holds_alternative(node->arguments[i])) { + // TODO + ++paramater_num; + } else if (std::holds_alternative(node->arguments[i])) { + if (type_value.argument_types.size() <= argument_num) { + error_handling::HandleTypecheckError("Mismatched argument count in function call expression"); + } + + context_manager_.AddTypeRequirement(current_type_, type_value.argument_types[argument_num]); + ++argument_num; } else { // error } - context_manager_.AddTypeRequirement(current_type_, type_value.argument_types[i]); + } + + if (type_value.argument_types.size() != argument_num) { + error_handling::HandleTypecheckError("Mismatched argument count in function call expression"); } current_type_ = type_value.return_type; @@ -581,9 +591,12 @@ void TypeCheckVisitor::Visit(VariantName* node) { } void TypeCheckVisitor::Visit(AnnotatedName* node) { - context_manager_.DefineVariable(node->name, current_type_); + utils::IdType type = current_type_; + + context_manager_.DefineVariable(node->name, type); if (node->type.has_value()) { - // TODO: ?? check, that types are equal, add type requirement ?? + Visitor::Visit(node->type.value()); + context_manager_.EqualTypes(type, current_type_); } }