mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-29 10:18:46 +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
|
|
@ -95,9 +95,9 @@ void BuildVisitor::Visit(Namespace* node) {
|
|||
if (child_count > 3) { // "namespace", ["var"/"const",] type, scope
|
||||
std::string modifier = parse_node.NthChild(1).GetValue();
|
||||
if (modifier == "const") {
|
||||
node->modifier = Namespace::Const;
|
||||
node->modifier = utils::IsConstModifier::Const;
|
||||
} else if (modifier == "var") {
|
||||
node->modifier = Namespace::Var;
|
||||
node->modifier = utils::IsConstModifier::Var;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,11 +149,11 @@ void BuildVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
|
||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||
if (modifier == "alias") {
|
||||
node->modifier = AliasDefinitionStatement::Alias;
|
||||
node->modifier = utils::AliasModifier::Alias;
|
||||
} else if (modifier == "type") {
|
||||
node->modifier = AliasDefinitionStatement::Type;
|
||||
node->modifier = utils::AliasModifier::Type;
|
||||
} else if (modifier == "let") {
|
||||
node->modifier = AliasDefinitionStatement::Let;
|
||||
node->modifier = utils::AliasModifier::Let;
|
||||
}
|
||||
|
||||
node->type = parse_node.ChildByFieldName("type").GetValue();
|
||||
|
|
@ -182,9 +182,9 @@ void BuildVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
|
||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||
if (modifier == "const") {
|
||||
node->modifier = VariableDefinitionStatement::Const;
|
||||
node->modifier = utils::IsConstModifier::Const;
|
||||
} else if (modifier == "var") {
|
||||
node->modifier = VariableDefinitionStatement::Var;
|
||||
node->modifier = utils::IsConstModifier::Var;
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("name");
|
||||
|
|
@ -195,9 +195,9 @@ void BuildVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
|
||||
std::string assignment_modifier = parse_node.NthChild(2).GetValue();
|
||||
if (assignment_modifier == "=") {
|
||||
node->assignment_modifier = VariableDefinitionStatement::Assign;
|
||||
node->assignment_modifier = utils::AssignmentModifier::Assign;
|
||||
} else if (assignment_modifier == "<-") {
|
||||
node->assignment_modifier = VariableDefinitionStatement::Move;
|
||||
node->assignment_modifier = utils::AssignmentModifier::Move;
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
|
|
@ -252,9 +252,9 @@ void BuildVisitor::Visit(TypeDefinitionStatement* node) {
|
|||
|
||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||
if (modifier == "class") {
|
||||
node->modifier = TypeDefinitionStatement::Class;
|
||||
node->modifier = utils::ClassModifier::Class;
|
||||
} else if (modifier == "struct") {
|
||||
node->modifier = TypeDefinitionStatement::Struct;
|
||||
node->modifier = utils::ClassModifier::Struct;
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("definition");
|
||||
|
|
@ -274,9 +274,9 @@ void BuildVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
|||
|
||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||
if (modifier == "basic") {
|
||||
node->modifier = AbstractTypeDefinitionStatement::Basic;
|
||||
node->modifier = utils::AbstractTypeModifier::Basic;
|
||||
} else if (modifier == "abstract") {
|
||||
node->modifier = AbstractTypeDefinitionStatement::Abstract;
|
||||
node->modifier = utils::AbstractTypeModifier::Abstract;
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("type");
|
||||
|
|
@ -397,9 +397,9 @@ void BuildVisitor::Visit(FunctionDefinition* node) {
|
|||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
||||
|
||||
if (parse_node.NthChild(0).GetValue() == "(") {
|
||||
node->modifier = FunctionDefinition::Operator;
|
||||
node->modifier = utils::FunctionTypeModifier::Operator;
|
||||
} else {
|
||||
node->modifier = FunctionDefinition::Function;
|
||||
node->modifier = utils::FunctionTypeModifier::Function;
|
||||
}
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
|
@ -939,9 +939,9 @@ void BuildVisitor::Visit(ReferenceExpression* node) {
|
|||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
std::string reference = parse_node.NthChild(i).GetValue();
|
||||
if (reference == "~") {
|
||||
node->references[i] = utils::ReferenceType::Reference;
|
||||
node->references[i] = utils::ReferenceModifier::Reference;
|
||||
} else if (reference == "@") {
|
||||
node->references[i] = utils::ReferenceType::UniqueReference;
|
||||
node->references[i] = utils::ReferenceModifier::UniqueReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1083,9 +1083,9 @@ void BuildVisitor::Visit(TypeConstructorParameter* node) {
|
|||
|
||||
std::string assignment_modifier = current_node_.NextSibling().GetValue();
|
||||
if (assignment_modifier == "=") {
|
||||
node->asignment_modifier = TypeConstructorParameter::Assign;
|
||||
node->asignment_modifier = utils::AssignmentModifier::Assign;
|
||||
} else if (assignment_modifier == "<-") {
|
||||
node->asignment_modifier = TypeConstructorParameter::Move;
|
||||
node->asignment_modifier = utils::AssignmentModifier::Move;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1445,9 +1445,9 @@ void BuildVisitor::Visit(ExtendedScopedAnyType* node) {
|
|||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
std::string reference = parse_node.NthChild(i).GetValue();
|
||||
if (reference == "~") {
|
||||
node->references[i] = utils::ReferenceType::Reference;
|
||||
node->references[i] = utils::ReferenceModifier::Reference;
|
||||
} else if (reference == "@") {
|
||||
node->references[i] = utils::ReferenceType::UniqueReference;
|
||||
node->references[i] = utils::ReferenceModifier::UniqueReference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,19 +13,7 @@ void FindSymbolsVisitor::Visit(Partition* node) {
|
|||
}
|
||||
|
||||
void FindSymbolsVisitor::Visit(Namespace* node) {
|
||||
std::optional<info::definition::Namespace::Modifier> modifier;
|
||||
if (node->modifier.has_value()) {
|
||||
switch (node->modifier.value()) {
|
||||
case interpreter::Namespace::Var:
|
||||
modifier = info::definition::Namespace::Var;
|
||||
break;
|
||||
case interpreter::Namespace::Const:
|
||||
modifier = info::definition::Namespace::Const;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
namespace_visitor_.AddEnterNamespace(node->type, modifier);
|
||||
namespace_visitor_.AddEnterNamespace(node->type, node->modifier);
|
||||
Visitor::Visit(&node->scope);
|
||||
namespace_visitor_.ExitNamespace();
|
||||
}
|
||||
|
|
@ -51,17 +39,7 @@ void FindSymbolsVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
|
||||
info::definition::AliasType alias_info;
|
||||
|
||||
switch (node->modifier) {
|
||||
case interpreter::AliasDefinitionStatement::Alias:
|
||||
alias_info.modifier = info::definition::AliasType::Alias;
|
||||
break;
|
||||
case interpreter::AliasDefinitionStatement::Type:
|
||||
alias_info.modifier = info::definition::AliasType::Type;
|
||||
break;
|
||||
case interpreter::AliasDefinitionStatement::Let:
|
||||
alias_info.modifier = info::definition::AliasType::Let;
|
||||
break;
|
||||
}
|
||||
alias_info.modifier = node->modifier;
|
||||
|
||||
// TODO: deduce parameter requirements
|
||||
|
||||
|
|
@ -71,7 +49,7 @@ void FindSymbolsVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
|
||||
info.type = std::move(alias_info);
|
||||
|
||||
node->type_id_ = namespace_visitor_.AddType(node->type, std::move(info));
|
||||
node->type_id_ = namespace_visitor_.AddType(node->type, std::move(info), node->base);
|
||||
|
||||
is_in_statement_ = false;
|
||||
}
|
||||
|
|
@ -150,7 +128,7 @@ void FindSymbolsVisitor::Visit(TypeDefinitionStatement* node) {
|
|||
|
||||
info.type = std::move(any_type_info);
|
||||
|
||||
node->type_id_ = namespace_visitor_.AddType(type, std::move(info));
|
||||
node->type_id_ = namespace_visitor_.AddType(type, std::move(info), node->base);
|
||||
|
||||
is_in_statement_ = false;
|
||||
}
|
||||
|
|
@ -164,18 +142,11 @@ void FindSymbolsVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
|||
info.type = std::move(std::any_cast<info::definition::Parameter>(current_info_));
|
||||
current_info_.reset();
|
||||
|
||||
switch (node->modifier) {
|
||||
case interpreter::AbstractTypeDefinitionStatement::Basic:
|
||||
info.modifier = info::definition::AbstractType::Basic;
|
||||
break;
|
||||
case interpreter::AbstractTypeDefinitionStatement::Abstract:
|
||||
info.modifier = info::definition::AbstractType::Abstract;
|
||||
break;
|
||||
}
|
||||
info.modifier = node->modifier;
|
||||
|
||||
std::string type = info.type.type;
|
||||
|
||||
node->type_id_ = namespace_visitor_.AddAbstractType(type, std::move(info));
|
||||
node->type_id_ = namespace_visitor_.AddAbstractType(type, std::move(info), node->base);
|
||||
|
||||
is_in_statement_ = false;
|
||||
}
|
||||
|
|
@ -201,7 +172,7 @@ void FindSymbolsVisitor::Visit(TypeclassDefinitionStatement* node) {
|
|||
current_info_.reset();
|
||||
}
|
||||
|
||||
node->typeclass_id_ = namespace_visitor_.AddTypeclass(definition->type.get()->type, std::move(info));
|
||||
node->typeclass_id_ = namespace_visitor_.AddTypeclass(definition->type.get()->type, std::move(info), node->base);
|
||||
|
||||
is_in_statement_ = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,31 +41,40 @@ void TypeCheckVisitor::Visit(NamespaceSources* node) {
|
|||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(Namespace* node) {
|
||||
void TypeCheckVisitor::Visit(Namespace* node) { // TODO: two var namespces for class: const and var
|
||||
if (node->modifier.has_value()) {
|
||||
// TODO
|
||||
if (node->link_typeclass_id_.has_value()) {
|
||||
bool is_const = node->modifier.value() == utils::IsConstModifier::Const;
|
||||
|
||||
if (node->link_typeclass_id_.has_value()) { // TODO: think about typeclass
|
||||
|
||||
std::vector<utils::IdType> requirements {node->link_typeclass_id_.value()};
|
||||
utils::IdType abstract_type = context_manager_.AddType(info::type::AbstractType(utils::AbstractTypeModifier::Abstract, node->type, requirements));
|
||||
|
||||
context_manager_.EnterVariableContext("self",
|
||||
abstract_type,
|
||||
is_const); // TODO: different name ??
|
||||
context_manager_.DefineLocalAbstractType(node->type, abstract_type);
|
||||
} else if (node->link_type_id_.has_value()) {
|
||||
Visitor::Visit(*namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(node->link_type_id_.value()).value().value); // handle error?
|
||||
|
||||
context_manager_.EnterVariableContext(
|
||||
"self", // TODO: different name ??
|
||||
context_manager_.AddType(
|
||||
info::type::DefinedType(node->link_type_id_.value(), current_type_, context_manager_.GetTypeManager())),
|
||||
is_const);
|
||||
}
|
||||
|
||||
if (node->link_type_id_.has_value()) {
|
||||
|
||||
}
|
||||
// Visit(node->link_type_id_);
|
||||
|
||||
// context_manager_.EnterVariableContext(node->name.value().name,
|
||||
// context_manager_.AddType(info::type::DefinedType {node->type_id_.value()}));
|
||||
} else {
|
||||
if (node->link_typeclass_id_.has_value()) { // ??
|
||||
error_handling::HandleTypecheckError("Typeclass can't have not variable namespace", node->base);
|
||||
}
|
||||
context_manager_.EnterContext();
|
||||
}
|
||||
|
||||
namespace_visitor_.EnterNamespace(node->type);
|
||||
|
||||
Visit(&node->scope);
|
||||
|
||||
namespace_visitor_.ExitNamespace();
|
||||
context_manager_.ExitContext();
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||
}
|
||||
|
||||
|
|
@ -81,22 +90,27 @@ void TypeCheckVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: parameter requirments
|
||||
context_manager_.EnterContext();
|
||||
|
||||
for (auto& parameter : node->parameters) {
|
||||
current_type_ = context_manager_.AddType(info::type::AbstractType(parameter, /*TODO*/{}));
|
||||
current_type_ = context_manager_.AddType(info::type::AbstractType(utils::AbstractTypeModifier::Abstract,
|
||||
parameter,
|
||||
/*TODO*/{}));
|
||||
context_manager_.DefineLocalAbstractType(parameter, current_type_);
|
||||
}
|
||||
|
||||
Visit(node->value.get());
|
||||
|
||||
context_manager_.ExitContext();
|
||||
}
|
||||
|
||||
// TODO: remove variable on move, etc.
|
||||
// TODO: remove variable on move
|
||||
void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
Visitor::Visit(node->value);
|
||||
// current_type from value automatically passed to name definitions
|
||||
is_const_definition_ = (node->assignment_modifier == VariableDefinitionStatement::Const);
|
||||
is_const_definition_ = (node->modifier == utils::IsConstModifier::Const);
|
||||
Visitor::Visit(node->name);
|
||||
is_const_definition_ = std::nullopt;
|
||||
|
||||
|
|
@ -109,7 +123,6 @@ void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
|
|||
bool was_in_statement = is_in_statement_;
|
||||
is_in_statement_ = true;
|
||||
|
||||
// check declaration correctness ??
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||
|
||||
if (!was_in_statement) {
|
||||
|
|
@ -139,21 +152,22 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
requirements.push_back(typeclass->typeclass_id_);
|
||||
}
|
||||
// TODO: add recursive typeclasses from typeclass tree
|
||||
current_type_ = context_manager_.AddType(info::type::AbstractType(parameter.type, requirements)); // TODO: move requirements
|
||||
current_type_ = context_manager_.AddType(info::type::AbstractType(utils::AbstractTypeModifier::Abstract,
|
||||
parameter.type,
|
||||
requirements));
|
||||
if (!context_manager_.DefineLocalAbstractType(parameter.type, current_type_)) {
|
||||
error_handling::HandleTypecheckError("Can't define function parameter type: type redefinition", node->base);
|
||||
error_handling::HandleTypecheckError("Can't define function parameter type: abstract type redefinition", node->base);
|
||||
}
|
||||
}
|
||||
|
||||
// Visit(node->definition.get()); // ??
|
||||
for (size_t i = 0; i < node->definition->arguments.size(); ++i) {
|
||||
Visitor::Visit(*declaration.argument_types[i]); // TODO: ConstructAnyType
|
||||
Visitor::Visit(*declaration.argument_types[i]);
|
||||
if (!context_manager_.DefineVariable(node->definition->arguments[i].name, current_type_, true)) { // TODO: watch to reference
|
||||
error_handling::HandleTypecheckError("Can't define function argument variable: name redefinition", node->base);
|
||||
}
|
||||
}
|
||||
|
||||
Visitor::Visit(*declaration.argument_types.back()); // TODO: ConstructAnyType
|
||||
Visitor::Visit(*declaration.argument_types.back());
|
||||
utils::IdType return_type = current_type_;
|
||||
|
||||
Visitor::Visit(node->value);
|
||||
|
|
@ -168,11 +182,9 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
is_in_statement_ = false;
|
||||
}
|
||||
|
||||
// TODO ??
|
||||
void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
// check definition correctness ??
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||
|
||||
is_in_statement_ = false;
|
||||
|
|
@ -181,7 +193,7 @@ void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
|
|||
void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
|
||||
// TODO: basic types ??
|
||||
// basic types ??
|
||||
|
||||
std::vector<utils::IdType> requirements;
|
||||
requirements.reserve(node->type->typeclasses.size());
|
||||
|
|
@ -189,9 +201,10 @@ void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
|||
requirements.push_back(typeclass->typeclass_id_);
|
||||
}
|
||||
// TODO: add recursive typeclasses from typeclass tree
|
||||
current_type_ = context_manager_.AddType(info::type::AbstractType(node->type->type, requirements));
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::AbstractType(node->modifier, node->type->type, requirements));
|
||||
if (!context_manager_.DefineLocalAbstractType(node->type->type, current_type_)) {
|
||||
error_handling::HandleTypecheckError("Can't define basic/bastract type: type redefinition", node->base);
|
||||
error_handling::HandleTypecheckError("Can't define basic/bastract type: abstract type redefinition", node->base);
|
||||
}
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue