type_check_visitor first iteration, value, execution_visitor started

This commit is contained in:
ProgramSnail 2023-05-07 19:52:35 +03:00
parent 173d50672a
commit 890bd90eba
22 changed files with 481 additions and 452 deletions

View file

@ -47,7 +47,8 @@ void GlobalInfo::NamespaceVisitor::EnterNamespace(const std::string& name) {
}
}
error_handling::HandleInternalError("Can't find namespace", "GlobalInfo.NamespaceVisitor.EnterNamespace");
error_handling::HandleInternalError("Can't find namespace",
"GlobalInfo.NamespaceVisitor.EnterNamespace");
}
void GlobalInfo::NamespaceVisitor::ExitNamespace() {
@ -67,8 +68,10 @@ void GlobalInfo::NamespaceVisitor::ToGlobalNamespace() {
namespace_stack_.push_back(&global_info_.global_namespace_);
}
utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(const std::string& name,
definition::FunctionDeclaration&& function_declaration_info) {
utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(
const std::string& name,
definition::FunctionDeclaration&& function_declaration_info) {
size_t id = 0;
auto function_id_iter = namespace_stack_.back()->functions.find(name);
@ -77,12 +80,13 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(const std::st
id = global_info_.functions_.size();
namespace_stack_.back()->functions[name] = id;
global_info_.functions_.emplace_back();
global_info_.functions_.back().argument_count = function_declaration_info.argument_types.size();
global_info_.functions_.back().argument_count = function_declaration_info.argument_types.size(); // add return type
global_info_.functions_.back().declaration = std::move(function_declaration_info);
} else {
id = function_id_iter->second;
if (global_info_.functions_.back().argument_count != function_declaration_info.argument_types.size()) {
error_handling::HandleInternalError("Not same argument count in function definition and declaration", "GlobalInfo");
error_handling::HandleInternalError("Not same argument count in function definition and declaration",
"GlobalInfo.NamespaceVisitor. AddFunctionDeclaration");
}
global_info_.functions_[id].declaration = std::move(function_declaration_info);
}
@ -100,11 +104,11 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(const std::str
id = global_info_.functions_.size();
namespace_stack_.back()->functions[name] = id;
global_info_.functions_.emplace_back();
global_info_.functions_.back().argument_count = function_definition_info.argument_names.size();
global_info_.functions_.back().argument_count = function_definition_info.argument_names.size() + 1;
global_info_.functions_.back().definition = std::move(function_definition_info);
} else {
id = function_id_iter->second;
if (global_info_.functions_.back().argument_count != function_definition_info.argument_names.size()) {
if (global_info_.functions_.back().argument_count != function_definition_info.argument_names.size() + 1) {
error_handling::HandleInternalError("Not same argument count in function definition and declaration", "GlobalInfo");
}
global_info_.functions_[id].definition = std::move(function_definition_info);
@ -178,12 +182,15 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& a
definition::AbstractType&& abstract_type_info,
const interpreter::tokens::BaseNode& base_node) {
if (!FindAbstractType(abstract_type).has_value()) {
size_t id = global_info_.abstract_types_.size();
utils::IdType id = global_info_.abstract_types_.size();
global_info_.name_to_abstract_type_[abstract_type] = id;
global_info_.abstract_types_.push_back(std::move(abstract_type_info));
return id;
}
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace", base_node);
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace",
base_node);
return 0;
}
@ -341,6 +348,8 @@ std::optional<T> GlobalInfo::NamespaceVisitor::FindSomething(
if (!maybe_namespace.has_value()) {
continue;
}
current_namespace = maybe_namespace.value();
} else {
current_namespace = namespace_stack_[i];
}