mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
better class interloop
This commit is contained in:
parent
c433448952
commit
a1d9e6b190
4 changed files with 66 additions and 20 deletions
|
|
@ -213,6 +213,45 @@ public:
|
|||
return &global_info_.namespaces_[GetCurrentNamespaceId()];
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GetCurrentNamespaceTypeId() {
|
||||
if (!GetCurrentNamespace()->any_node.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return GetCurrentNamespace()->any_node.value()->link_type_id_;
|
||||
}
|
||||
|
||||
std::optional<definition::Type*> GetCurrentNamespaceAnyType() {
|
||||
std::optional<utils::IdType> id = GetCurrentNamespaceTypeId();
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetAnyTypeInfo(id.value());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> GetCurrentNamespaceType() {
|
||||
std::optional<utils::IdType> id = GetCurrentNamespaceTypeId();
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return global_info_.GetTypeInfo<T>(id.value());
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GetCurrentNamespaceTypeclassId() {
|
||||
if (!GetCurrentNamespace()->any_node.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return GetCurrentNamespace()->any_node.value()->link_typeclass_id_;
|
||||
}
|
||||
|
||||
std::optional<definition::Typeclass*> GetCurrentNamespaceTypeclass() {
|
||||
std::optional<utils::IdType> id = GetCurrentNamespaceTypeclassId();
|
||||
if (!id.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &global_info_.GetTypeclassInfo(id.value());
|
||||
}
|
||||
|
||||
bool IsInGlobalNamespace() {
|
||||
return namespace_stack_.size() == 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
// for clangd
|
||||
#include "interpreter_tree.hpp"
|
||||
#include "typeclass_graph.hpp"
|
||||
#include "types.hpp"
|
||||
#include "contexts.hpp"
|
||||
#include "utils.hpp"
|
||||
|
|
@ -17,7 +18,10 @@ class TypeCheckVisitor : public Visitor {
|
|||
public:
|
||||
explicit TypeCheckVisitor(info::GlobalInfo& global_info,
|
||||
info::ContextManager<info::type::Type, info::type::TypeManager>& context_manager)
|
||||
: namespace_visitor_(global_info.CreateVisitor()), context_manager_(context_manager) {}
|
||||
: namespace_visitor_(global_info.CreateVisitor()),
|
||||
global_info_(global_info),
|
||||
typeclass_graph_(*global_info.GetTypeclassGraph()),
|
||||
context_manager_(context_manager) {}
|
||||
|
||||
private:
|
||||
// Sources -----------------
|
||||
|
|
@ -138,6 +142,8 @@ private:
|
|||
|
||||
private:
|
||||
info::GlobalInfo::NamespaceVisitor namespace_visitor_;
|
||||
info::GlobalInfo& global_info_;
|
||||
info::TypeclassGraph& typeclass_graph_;
|
||||
info::ContextManager<info::type::Type, info::type::TypeManager>& context_manager_;
|
||||
|
||||
std::unordered_set<utils::IdType> type_namespaces_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue