mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-07 23:48:43 +00:00
fixes , modifier enum refacing, type visitor part
This commit is contained in:
parent
b686fe00fb
commit
c4045e292b
9 changed files with 147 additions and 132 deletions
|
|
@ -15,10 +15,14 @@ void GlobalInfo::NamespaceVisitor::AddImport(definition::Import&& import_info,
|
|||
}
|
||||
|
||||
void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
||||
const std::optional<definition::Namespace::Modifier>& modifier) {
|
||||
std::optional<utils::IsConstModifier> modifier) {
|
||||
definition::Namespace* namespace_info = nullptr;
|
||||
if (modifier.has_value()) {
|
||||
namespace_info = &namespace_stack_.back()->variable_namespaces[name];
|
||||
if (modifier.value() == utils::IsConstModifier::Const) {
|
||||
namespace_info = &namespace_stack_.back()->const_namespaces[name];
|
||||
} else {
|
||||
namespace_info = &namespace_stack_.back()->var_namespaces[name];
|
||||
}
|
||||
namespace_stack_.push_back(namespace_info);
|
||||
|
||||
namespace_info->modifier = modifier;
|
||||
|
|
@ -112,7 +116,8 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(const std::str
|
|||
// TODO: internal types, etc.
|
||||
// TODO: extended constructor names (point separated names)
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
||||
definition::Type&& type_info) {
|
||||
definition::Type&& type_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
size_t id = 0;
|
||||
|
||||
auto type_id_iter = namespace_stack_.back()->types.find(type);
|
||||
|
|
@ -122,8 +127,8 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
|||
namespace_stack_.back()->types[type] = id;
|
||||
global_info_.types_.push_back(std::move(type_info));
|
||||
} else {
|
||||
error_handling::HandleTypecheckError("More then one type with the same name in namespace");
|
||||
}
|
||||
error_handling::HandleTypecheckError("More then one type with the same name in namespace", base_node);
|
||||
} // TODO: typecheck error??
|
||||
|
||||
definition::Type& moved_type_info = global_info_.types_.back();
|
||||
|
||||
|
|
@ -160,7 +165,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
|||
|
||||
constructor_info.name = constructor_name;
|
||||
|
||||
AddConstructor(constructor_name, std::move(constructor_info));
|
||||
AddConstructor(constructor_name, std::move(constructor_info), base_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -170,19 +175,21 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
|||
|
||||
// TODO: link abstract type with let definitions
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& abstract_type,
|
||||
definition::AbstractType&& abstract_type_info) {
|
||||
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();
|
||||
global_info_.name_to_abstract_type_[abstract_type] = id;
|
||||
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");
|
||||
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace", base_node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddTypeclass(const std::string& typeclass,
|
||||
definition::Typeclass&& typeclass_info) {
|
||||
definition::Typeclass&& typeclass_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (!FindTypeclass(typeclass).has_value()) {
|
||||
size_t id = global_info_.typeclasses_.size();
|
||||
global_info_.name_to_typeclass_[typeclass] = id;
|
||||
|
|
@ -190,12 +197,13 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddTypeclass(const std::string& type
|
|||
}
|
||||
|
||||
|
||||
error_handling::HandleTypecheckError("More then one typeclass with the same name in namespace");
|
||||
error_handling::HandleTypecheckError("More then one typeclass with the same name in namespace", base_node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddConstructor(const std::string& constructor,
|
||||
definition::Constructor&& constructor_info) {
|
||||
definition::Constructor&& constructor_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
auto constructor_id_iter = namespace_stack_.back()->constructors.find(constructor);
|
||||
|
||||
if (constructor_id_iter == namespace_stack_.back()->constructors.end()) {
|
||||
|
|
@ -204,7 +212,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddConstructor(const std::string& co
|
|||
global_info_.constructors_.push_back(std::move(constructor_info));
|
||||
}
|
||||
|
||||
error_handling::HandleTypecheckError("More then one constructor with the same name in namespace");
|
||||
error_handling::HandleTypecheckError("More then one constructor with the same name in namespace", base_node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -233,14 +241,22 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindFunction(
|
|||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethod(
|
||||
const std::optional<std::vector<std::string>>& path,
|
||||
const std::string& type,
|
||||
const std::string& name) {
|
||||
const std::string& name,
|
||||
utils::IsConstModifier modifier) {
|
||||
// TODO: remove overhead
|
||||
|
||||
return GlobalInfo::NamespaceVisitor::FindSomething<utils::IdType>(path,
|
||||
[type, name] (definition::Namespace* current_namespace) -> std::optional<utils::IdType> {
|
||||
[type, name, modifier] (definition::Namespace* current_namespace) -> std::optional<utils::IdType> {
|
||||
|
||||
auto variable_namespace_iter = current_namespace->variable_namespaces.find(type);
|
||||
if (variable_namespace_iter == current_namespace->variable_namespaces.end()) {
|
||||
|
||||
auto variable_namespace_iter =
|
||||
(modifier == utils::IsConstModifier::Const
|
||||
? current_namespace->const_namespaces.find(type)
|
||||
: current_namespace->var_namespaces.find(type));
|
||||
if (variable_namespace_iter ==
|
||||
(modifier == utils::IsConstModifier::Const
|
||||
? current_namespace->const_namespaces.end()
|
||||
: current_namespace->var_namespaces.end())) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue