This commit is contained in:
ProgramSnail 2023-05-02 16:16:55 +03:00
parent 648f78afa3
commit 496d3819d9
6 changed files with 71 additions and 16 deletions

View file

@ -1,8 +1,6 @@
// for clangd
#include "../include/find_symbols_visitor.hpp"
// TODO
namespace interpreter {
// Sources -----------------

View file

@ -167,7 +167,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& a
if (!FindAbstractType(abstract_type).has_value()) {
size_t id = global_info_.abstract_types_.size();
global_info_.name_to_abstract_type_[abstract_type] = id;
global_info_.abstract_types_.push_b(ack(std::move(abstract_type_info));
global_info_.abstract_types_.push_back(std::move(abstract_type_info));
}
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace");
@ -261,6 +261,16 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindType(
});
}
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindLocalType(const std::string& type) {
auto type_id_iter = namespace_stack_.back()->types.find(type);
if (type_id_iter != namespace_stack_.back()->types.end()) {
return type_id_iter->second;
}
return std::nullopt;
}
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindAbstractType(const std::string& abstract_type) {
auto abstract_type_id_iter = global_info_.name_to_abstract_type_.find(abstract_type);

View file

@ -1,6 +1,7 @@
// for clangd
#include "../include/link_symbols_visitor.hpp"
#include "../include/error_handling.hpp"
#include <optional>
namespace interpreter {
@ -20,8 +21,13 @@ const std::string& NameFromTypeSubExpression(const TypeSubExpression& type) {
void LinkSymbolsVisitor::Visit(Namespace* node) {
// Visitor::Visit(&node->type); // not needed
auto maybe_type = namespace_visitor_.FindType(std::nullopt, node->type); // TODO: find only in local namespace
auto maybe_typeclass = namespace_visitor_.FindType(std::nullopt, node->type); // TODO: find only if in global namespace
std::optional<utils::IdType> maybe_type = namespace_visitor_.FindLocalType(node->type);
std::optional<utils::IdType> maybe_typeclass;
if (namespace_visitor_.GetCurrentPath().size() == 0) {
maybe_typeclass = namespace_visitor_.FindTypeclass(node->type);
}
if (maybe_type.has_value() && maybe_typeclass.has_value()) {
error_handling::HandleTypecheckError("Ambigious namespace name (typeclass or type)");
}