mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-07 15:38:47 +00:00
abstract types typecheck, fixes
This commit is contained in:
parent
9aeba7b0de
commit
c433448952
9 changed files with 143 additions and 94 deletions
|
|
@ -22,7 +22,7 @@ void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
|||
std::optional<interpreter::tokens::Namespace*> node,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (type::ToInternalType(name).has_value()) {
|
||||
error_handling::HandleTypecheckError("Can't define basic type namespace", base_node);
|
||||
error_handling::HandleNamesError("Can't define basic type namespace", base_node);
|
||||
}
|
||||
|
||||
auto current_namespaces = ChooseNamespaces(modifier, namespace_stack_.back());
|
||||
|
|
@ -36,12 +36,16 @@ void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
|||
global_info_.namespaces_.emplace_back();
|
||||
|
||||
global_info_.namespaces_.back().modifier = modifier;
|
||||
global_info_.namespaces_.back().node = node;
|
||||
} else {
|
||||
id = namespace_iter->second;
|
||||
}
|
||||
|
||||
definition::Namespace* namespace_info = &global_info_.namespaces_[id];
|
||||
|
||||
if (!namespace_info->any_node.has_value()) { // ??
|
||||
namespace_info->any_node = node;
|
||||
}
|
||||
|
||||
namespace_info->parent_namespace = namespace_stack_.back();
|
||||
|
||||
namespace_info->type_name = name;
|
||||
|
|
@ -99,12 +103,12 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(
|
|||
} else {
|
||||
id = function_id_iter->second;
|
||||
if (global_info_.functions_[id].argument_count != function_declaration_info.argument_types.size()) {
|
||||
error_handling::HandleTypecheckError("Function declaration: not same argument count in function definition and declaration", base_node);
|
||||
error_handling::HandleNamesError("Function declaration: not same argument count in function definition and declaration", base_node);
|
||||
}
|
||||
}
|
||||
|
||||
if (global_info_.functions_[id].declaration.has_value()) {
|
||||
error_handling::HandleTypecheckError("Second function declaration", base_node);
|
||||
error_handling::HandleNamesError("Second function declaration", base_node);
|
||||
}
|
||||
global_info_.functions_[id].declaration = std::move(function_declaration_info);
|
||||
|
||||
|
|
@ -126,12 +130,12 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(
|
|||
} else {
|
||||
id = function_id_iter->second;
|
||||
if (global_info_.functions_[id].argument_count != function_definition_info.argument_names.size() + 1) {
|
||||
error_handling::HandleTypecheckError("Function definition: not same argument count in function definition and declaration", base_node);
|
||||
error_handling::HandleNamesError("Function definition: not same argument count in function definition and declaration", base_node);
|
||||
}
|
||||
}
|
||||
|
||||
if (global_info_.functions_[id].definition.has_value()) {
|
||||
error_handling::HandleTypecheckError("Second function definition", base_node);
|
||||
error_handling::HandleNamesError("Second function definition", base_node);
|
||||
}
|
||||
global_info_.functions_[id].definition = std::move(function_definition_info);
|
||||
|
||||
|
|
@ -144,7 +148,7 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
|||
definition::Type&& type_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (type::ToInternalType(type).has_value()) {
|
||||
error_handling::HandleTypecheckError("Can't redefine basic type", base_node);
|
||||
error_handling::HandleNamesError("Can't redefine basic type", base_node);
|
||||
}
|
||||
|
||||
utils::IdType id = 0;
|
||||
|
|
@ -156,8 +160,8 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
|||
global_info_.namespaces_[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", base_node);
|
||||
} // TODO: typecheck error??
|
||||
error_handling::HandleNamesError("More then one type with the same name in namespace", base_node);
|
||||
}
|
||||
|
||||
definition::Type& moved_type_info = global_info_.types_.back();
|
||||
|
||||
|
|
@ -207,12 +211,11 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& a
|
|||
definition::AbstractType&& abstract_type_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (type::ToInternalType(abstract_type).has_value()) {
|
||||
error_handling::HandleTypecheckError("Can't redefine basic type as abstract type", base_node);
|
||||
error_handling::HandleNamesError("Can't redefine basic type as abstract type", base_node);
|
||||
}
|
||||
|
||||
if (FindAbstractType(abstract_type).has_value()) {
|
||||
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace",
|
||||
base_node);
|
||||
error_handling::HandleNamesError("More then one abstract type with the same name in namespace", base_node);
|
||||
}
|
||||
|
||||
utils::IdType id = global_info_.abstract_types_.size();
|
||||
|
|
@ -227,23 +230,17 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddTypeclass(const std::string& type
|
|||
definition::Typeclass&& typeclass_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (type::ToInternalType(typeclass).has_value()) {
|
||||
error_handling::HandleTypecheckError("Can't redefine basic type as typeclass", base_node);
|
||||
error_handling::HandleNamesError("Can't redefine basic type as typeclass", base_node);
|
||||
}
|
||||
|
||||
if (FindTypeclass(typeclass).has_value()) {
|
||||
error_handling::HandleTypecheckError("More then one typeclass with the same name in namespace", base_node);
|
||||
error_handling::HandleNamesError("More then one typeclass with the same name", base_node);
|
||||
}
|
||||
|
||||
utils::IdType id = global_info_.typeclasses_.size();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -251,13 +248,13 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddConstructor(const std::string& co
|
|||
definition::Constructor&& constructor_info,
|
||||
const interpreter::tokens::BaseNode& base_node) {
|
||||
if (type::ToInternalType(constructor).has_value()) {
|
||||
error_handling::HandleTypecheckError("Can't redefine basic type as constructor", base_node);
|
||||
error_handling::HandleNamesError("Can't redefine basic type as constructor", base_node);
|
||||
}
|
||||
|
||||
auto constructor_id_iter = global_info_.namespaces_[namespace_stack_.back()].constructors.find(constructor);
|
||||
|
||||
if (constructor_id_iter != global_info_.namespaces_[namespace_stack_.back()].constructors.end()) {
|
||||
error_handling::HandleTypecheckError("More then one constructor with the same name in namespace", base_node);
|
||||
error_handling::HandleNamesError("More then one constructor with the same name in namespace", base_node);
|
||||
}
|
||||
|
||||
utils::IdType id = global_info_.constructors_.size();
|
||||
|
|
@ -316,8 +313,6 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethodId(
|
|||
const std::string& type,
|
||||
const std::string& name,
|
||||
utils::IsConstModifier modifier) {
|
||||
// TODO: remove overhead
|
||||
|
||||
return GlobalInfo::NamespaceVisitor::FindSomething<utils::IdType>(path,
|
||||
[type, name, modifier, this] (utils::IdType current_namespace) -> std::optional<utils::IdType> {
|
||||
|
||||
|
|
@ -471,13 +466,12 @@ std::optional<utils::IdType> GlobalInfo::AddTypeclassToGraph(utils::IdType typec
|
|||
definition::Namespace* parent_namespace = &GetNamespaceInfo(typeclass_info->parent_namespace);
|
||||
|
||||
std::string name = typeclass_info->node->definition->type->type;
|
||||
std::vector<TypeclassGraph::ParametrizedTypeclass> dependencies;
|
||||
std::vector<std::string> dependencies;
|
||||
std::vector<std::pair<std::string, std::pair<utils::ClassInternalsModifier, interpreter::tokens::FunctionDeclaration*>>> function_declarations;
|
||||
std::vector<std::pair<std::string, interpreter::tokens::FunctionDefinitionStatement*>> function_definitions;
|
||||
|
||||
for (auto& dependency_node : typeclass_info->node->definition->type->typeclasses) {
|
||||
TypeclassGraph::ParametrizedTypeclass dependency;
|
||||
dependency.typeclass = dependency_node->typeclass;
|
||||
std::string dependency = dependency_node->typeclass;
|
||||
if (dependency_node->parameters.size() > 0) {
|
||||
error_handling::HandleInternalError("Paramtrized typeclass requirements are not implemented yet",
|
||||
"TypeclassGraph.AddTypeclassByNode");
|
||||
|
|
@ -494,23 +488,21 @@ std::optional<utils::IdType> GlobalInfo::AddTypeclassToGraph(utils::IdType typec
|
|||
}
|
||||
|
||||
auto const_namespace_iter = parent_namespace->const_namespaces.find(name);
|
||||
if (namespace_iter != parent_namespace->const_namespaces.end()) {
|
||||
CollectFunctionInfo(namespace_iter->second,
|
||||
if (const_namespace_iter != parent_namespace->const_namespaces.end()) {
|
||||
CollectFunctionInfo(const_namespace_iter->second,
|
||||
utils::ClassInternalsModifier::Const,
|
||||
function_declarations,
|
||||
function_definitions);
|
||||
}
|
||||
|
||||
auto var_namespace_iter = parent_namespace->var_namespaces.find(name);
|
||||
if (namespace_iter != parent_namespace->var_namespaces.end()) {
|
||||
CollectFunctionInfo(namespace_iter->second,
|
||||
if (var_namespace_iter != parent_namespace->var_namespaces.end()) {
|
||||
CollectFunctionInfo(var_namespace_iter->second,
|
||||
utils::ClassInternalsModifier::Var,
|
||||
function_declarations,
|
||||
function_definitions);
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
return typeclass_graph_.AddTypeclass(name,
|
||||
typeclass_info->node,
|
||||
dependencies,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue