mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-07 07:28:44 +00:00
better global_info API, better const/var/static handling, const typeclass requirements, fixes
This commit is contained in:
parent
047ead6fa3
commit
4f54bb4bd7
15 changed files with 381 additions and 213 deletions
|
|
@ -18,7 +18,7 @@ void GlobalInfo::NamespaceVisitor::AddImport(definition::Import&& import_info,
|
|||
}
|
||||
|
||||
void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
||||
std::optional<utils::IsConstModifier> modifier,
|
||||
utils::ClassInternalsModifier modifier,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (type::ToInternalType(name).has_value()) {
|
||||
error_handling::HandleTypecheckError("Can't define basic type namespace", base_node);
|
||||
|
|
@ -38,7 +38,7 @@ void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
|||
}
|
||||
definition::Namespace* namespace_info = &global_info_.namespaces_[id];
|
||||
|
||||
if (modifier.has_value()) {
|
||||
if (modifier != utils::ClassInternalsModifier::Static) {
|
||||
namespace_info->modifier = modifier;
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
|||
}
|
||||
|
||||
void GlobalInfo::NamespaceVisitor::EnterNamespace(const std::string& name,
|
||||
std::optional<utils::IsConstModifier> modifier) {
|
||||
utils::ClassInternalsModifier modifier) {
|
||||
for (ssize_t i = (ssize_t)namespace_stack_.size() - 1; i >= 0; --i) {
|
||||
auto current_namespaces = ChooseNamespaces(modifier, i);
|
||||
auto namespace_iter = current_namespaces->find(name);
|
||||
|
|
@ -222,6 +222,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& a
|
|||
return id;
|
||||
}
|
||||
|
||||
// TODO: which info needed ??
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddTypeclass(const std::string& typeclass,
|
||||
definition::Typeclass&& typeclass_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
|
|
@ -237,6 +238,12 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddTypeclass(const std::string& type
|
|||
global_info_.name_to_typeclass_[typeclass] = id;
|
||||
global_info_.typeclasses_.push_back(std::move(typeclass_info));
|
||||
|
||||
definition::Typeclass& moved_typeclass_info = global_info_.typeclasses_.back();
|
||||
|
||||
// global_info_.typeclass_graph_.AddTypeclassByNode(moved_typeclass_info.node); // TODO
|
||||
error_handling::HandleInternalError("Typeclasses are not implemented properly yet",
|
||||
"GlobalInfo.NamespaceVisitor.AddTypeclass");
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
@ -282,14 +289,14 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddPartition(const std::vector<std::
|
|||
return id;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindNamespace(const std::optional<std::vector<std::string>>& path) {
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindNamespaceId(const std::optional<std::vector<std::string>>& path) {
|
||||
return FindSomething<utils::IdType>(path,
|
||||
[] (utils::IdType current_namespace) -> std::optional<utils::IdType> {
|
||||
return current_namespace;
|
||||
});
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindFunction(
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindFunctionId(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& name) {
|
||||
return FindSomething<utils::IdType>(path,
|
||||
|
|
@ -304,7 +311,7 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindFunction(
|
|||
});
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethod(
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethodId(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type,
|
||||
const std::string& name,
|
||||
|
|
@ -335,7 +342,7 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethod(
|
|||
});
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindType(
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindTypeId(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type) {
|
||||
return FindSomething<utils::IdType>(path,
|
||||
|
|
@ -350,7 +357,7 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindType(
|
|||
});
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindLocalType(const std::string& type) {
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindLocalTypeId(const std::string& type) {
|
||||
auto type_id_iter = global_info_.namespaces_[namespace_stack_.back()].types.find(type);
|
||||
|
||||
if (type_id_iter != global_info_.namespaces_[namespace_stack_.back()].types.end()) {
|
||||
|
|
@ -360,7 +367,7 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindLocalType(const s
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindAbstractType(const std::string& abstract_type) {
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindAbstractTypeId(const std::string& abstract_type) {
|
||||
auto abstract_type_id_iter = global_info_.name_to_abstract_type_.find(abstract_type);
|
||||
|
||||
if (abstract_type_id_iter != global_info_.name_to_abstract_type_.end()) {
|
||||
|
|
@ -370,7 +377,7 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindAbstractType(cons
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindTypeclass(const std::string& typeclass) {
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindTypeclassId(const std::string& typeclass) {
|
||||
auto typeclass_id_iter = global_info_.name_to_typeclass_.find(typeclass);
|
||||
|
||||
if (typeclass_id_iter != global_info_.name_to_typeclass_.end()) {
|
||||
|
|
@ -380,7 +387,7 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindTypeclass(const s
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindConstructor(
|
||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindConstructorId(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& constructor) {
|
||||
return FindSomething<utils::IdType>(path,
|
||||
|
|
@ -439,17 +446,19 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindNamespaceIn(
|
|||
}
|
||||
|
||||
std::unordered_map<std::string, utils::IdType>*
|
||||
GlobalInfo::NamespaceVisitor::ChooseNamespaces(std::optional<utils::IsConstModifier> modifier,
|
||||
GlobalInfo::NamespaceVisitor::ChooseNamespaces(utils::ClassInternalsModifier modifier,
|
||||
utils::IdType namespace_id) {
|
||||
std::unordered_map<std::string, utils::IdType>* current_namespaces = nullptr;
|
||||
if (modifier.has_value()) {
|
||||
if (modifier.value() == utils::IsConstModifier::Const) {
|
||||
switch (modifier) {
|
||||
case utils::ClassInternalsModifier::Const:
|
||||
current_namespaces = &global_info_.namespaces_[namespace_id].const_namespaces;
|
||||
} else {
|
||||
break;
|
||||
case utils::ClassInternalsModifier::Var:
|
||||
current_namespaces = &global_info_.namespaces_[namespace_id].var_namespaces;
|
||||
}
|
||||
} else {
|
||||
current_namespaces = &global_info_.namespaces_[namespace_id].namespaces;
|
||||
break;
|
||||
case utils::ClassInternalsModifier::Static:
|
||||
current_namespaces = &global_info_.namespaces_[namespace_id].namespaces;
|
||||
break;
|
||||
}
|
||||
|
||||
return current_namespaces;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue