mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-09 08:28:43 +00:00
link_symbols_visitor improvements
This commit is contained in:
parent
496d3819d9
commit
0dc8880c58
5 changed files with 33 additions and 6 deletions
|
|
@ -50,6 +50,7 @@ void LinkSymbolsVisitor::Visit(Namespace* node) {
|
|||
// Type
|
||||
|
||||
// TODO: link internal stages
|
||||
// TODO: find constructors ?
|
||||
void LinkSymbolsVisitor::Visit(TypeExpression* node) { // TODO: check
|
||||
std::vector<std::string> path;
|
||||
path.reserve(node->path.size());
|
||||
|
|
@ -58,12 +59,31 @@ void LinkSymbolsVisitor::Visit(TypeExpression* node) { // TODO: check
|
|||
path.push_back(NameFromTypeSubExpression(path_type));
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> maybe_type = namespace_visitor_.FindType(path, NameFromTypeSubExpression(node->type));
|
||||
node->type_id_ = namespace_visitor_.FindType(path, NameFromTypeSubExpression(node->type));
|
||||
node->type_id_ = namespace_visitor_.FindType(path, NameFromTypeSubExpression(node->type));
|
||||
|
||||
if (maybe_type.has_value()) {
|
||||
node->type_id_ = maybe_type.value();
|
||||
} else {
|
||||
error_handling::HandleTypecheckError("Type not found");
|
||||
if (!node->type_id_.has_value() && !node->constructor_id_.has_value()) {
|
||||
error_handling::HandleTypecheckError("Type or constructor not found");
|
||||
}
|
||||
|
||||
std::optional<info::definition::Namespace*> maybe_type_namespace = namespace_visitor_.FindNamespace(path);
|
||||
if (maybe_type_namespace.has_value()) {
|
||||
info::definition::Namespace* type_namespace = maybe_type_namespace.value();
|
||||
|
||||
for (ssize_t i = (ssize_t)node->path.size(); i >= 0; --i) {
|
||||
info::definition::Namespace* parent_namespace = type_namespace->parent_namespace;
|
||||
|
||||
auto maybe_type = parent_namespace->types.find(type_namespace->type_name); // TODO: make method ??
|
||||
if (maybe_type.has_value()) {
|
||||
node->path[i]->
|
||||
}
|
||||
|
||||
if (parent_namespace == nullptr) {
|
||||
error_handling::HandleInternalError("Parent namespace is null in type expression", "LinkSymbolsVisitor");
|
||||
}
|
||||
|
||||
type_namespace = parent_namespace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue