mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-07 15:38:47 +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
|
|
@ -29,12 +29,12 @@ struct Parameter {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AbstractType {
|
struct AbstractType {
|
||||||
enum { Basic, Abstract } modifier;
|
utils::AbstractTypeModifier modifier;
|
||||||
Parameter type;
|
Parameter type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AliasType {
|
struct AliasType {
|
||||||
enum {Alias, Type, Let} modifier;
|
utils::AliasModifier modifier;
|
||||||
std::vector<std::string> parameters;
|
std::vector<std::string> parameters;
|
||||||
TypeUsage value;
|
TypeUsage value;
|
||||||
interpreter::tokens::AliasDefinitionStatement* node = nullptr;
|
interpreter::tokens::AliasDefinitionStatement* node = nullptr;
|
||||||
|
|
@ -87,17 +87,17 @@ struct Import {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Namespace {
|
struct Namespace {
|
||||||
enum Modifier { Const, Var };
|
|
||||||
|
|
||||||
std::unordered_map<std::string, utils::IdType> types;
|
std::unordered_map<std::string, utils::IdType> types;
|
||||||
std::unordered_map<std::string, utils::IdType> functions;
|
std::unordered_map<std::string, utils::IdType> functions;
|
||||||
std::unordered_map<std::string, utils::IdType> constructors;
|
std::unordered_map<std::string, utils::IdType> constructors;
|
||||||
std::unordered_map<std::string, Namespace> namespaces;
|
std::unordered_map<std::string, Namespace> namespaces;
|
||||||
std::unordered_map<std::string, Namespace> variable_namespaces;
|
std::unordered_map<std::string, Namespace> var_namespaces;
|
||||||
|
std::unordered_map<std::string, Namespace> const_namespaces;
|
||||||
|
|
||||||
Namespace* parent_namespace = nullptr;
|
Namespace* parent_namespace = nullptr;
|
||||||
|
|
||||||
std::optional<Modifier> modifier; // modifier => variable namespace
|
std::optional<utils::IsConstModifier> modifier; // modifier => variable namespace
|
||||||
std::string type_name;
|
std::string type_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public:
|
||||||
void AddImport(definition::Import&& import_info, const std::optional<std::string>& name = std::nullopt);
|
void AddImport(definition::Import&& import_info, const std::optional<std::string>& name = std::nullopt);
|
||||||
|
|
||||||
void AddEnterNamespace(const std::string& name,
|
void AddEnterNamespace(const std::string& name,
|
||||||
const std::optional<definition::Namespace::Modifier>& modifier = std::nullopt);
|
std::optional<utils::IsConstModifier> modifier = std::nullopt);
|
||||||
|
|
||||||
void EnterNamespace(const std::string& name);
|
void EnterNamespace(const std::string& name);
|
||||||
|
|
||||||
|
|
@ -41,15 +41,21 @@ public:
|
||||||
utils::IdType AddFunctionDefinition(const std::string& name,
|
utils::IdType AddFunctionDefinition(const std::string& name,
|
||||||
definition::FunctionDefinition&& function_definition_info);
|
definition::FunctionDefinition&& function_definition_info);
|
||||||
|
|
||||||
utils::IdType AddType(const std::string& type, definition::Type&& type_info);
|
utils::IdType AddType(const std::string& type,
|
||||||
|
definition::Type&& type_info,
|
||||||
|
const interpreter::tokens::BaseNode& base_node);
|
||||||
|
|
||||||
utils::IdType AddAbstractType(const std::string& abstract_type,
|
utils::IdType AddAbstractType(const std::string& abstract_type,
|
||||||
definition::AbstractType&& abstract_type_info);
|
definition::AbstractType&& abstract_type_info,
|
||||||
|
const interpreter::tokens::BaseNode& base_node);
|
||||||
|
|
||||||
utils::IdType AddTypeclass(const std::string& typeclass, definition::Typeclass&& typeclass_info);
|
utils::IdType AddTypeclass(const std::string& typeclass,
|
||||||
|
definition::Typeclass&& typeclass_info,
|
||||||
|
const interpreter::tokens::BaseNode& base_node);
|
||||||
|
|
||||||
utils::IdType AddConstructor(const std::string& constructor,
|
utils::IdType AddConstructor(const std::string& constructor,
|
||||||
definition::Constructor&& constructor_info);
|
definition::Constructor&& constructor_info,
|
||||||
|
const interpreter::tokens::BaseNode& base_node);
|
||||||
|
|
||||||
std::optional<definition::Namespace*> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
std::optional<definition::Namespace*> FindNamespace(const std::optional<std::vector<std::string>>& path);
|
||||||
|
|
||||||
|
|
@ -58,7 +64,8 @@ public:
|
||||||
|
|
||||||
std::optional<utils::IdType> FindMethod(const std::optional<std::vector<std::string>>& path,
|
std::optional<utils::IdType> FindMethod(const std::optional<std::vector<std::string>>& path,
|
||||||
const std::string& type,
|
const std::string& type,
|
||||||
const std::string& name);
|
const std::string& name,
|
||||||
|
utils::IsConstModifier modifier);
|
||||||
|
|
||||||
std::optional<utils::IdType> FindType(const std::optional<std::vector<std::string>>& path,
|
std::optional<utils::IdType> FindType(const std::optional<std::vector<std::string>>& path,
|
||||||
const std::string& type);
|
const std::string& type);
|
||||||
|
|
@ -92,11 +99,13 @@ public:
|
||||||
namespace_stack_({&global_info.global_namespace_}) {}
|
namespace_stack_({&global_info.global_namespace_}) {}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::optional<T> FindSomething(const std::optional<std::vector<std::string>>& path,
|
std::optional<T> FindSomething(
|
||||||
std::function<std::optional<T>(definition::Namespace*)> search_func);
|
const std::optional<std::vector<std::string>>& path,
|
||||||
|
std::function<std::optional<T>(definition::Namespace*)> search_func);
|
||||||
|
|
||||||
std::optional<definition::Namespace*> FindNamespaceIn(definition::Namespace* current_namespace,
|
std::optional<definition::Namespace*> FindNamespaceIn(
|
||||||
const std::vector<std::string>& path);
|
definition::Namespace* current_namespace,
|
||||||
|
const std::vector<std::string>& path);
|
||||||
private:
|
private:
|
||||||
std::vector<definition::Namespace*> namespace_stack_;
|
std::vector<definition::Namespace*> namespace_stack_;
|
||||||
std::vector<std::string> current_path_;
|
std::vector<std::string> current_path_;
|
||||||
|
|
|
||||||
|
|
@ -296,8 +296,7 @@ struct NamespaceSources {
|
||||||
struct Namespace {
|
struct Namespace {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum Modifier { Const, Var };
|
std::optional<utils::IsConstModifier> modifier; // modifier => variable namespace
|
||||||
std::optional<Modifier> modifier; // modifier => variable namespace
|
|
||||||
TypeIdentifier type;
|
TypeIdentifier type;
|
||||||
NamespaceSources scope;
|
NamespaceSources scope;
|
||||||
|
|
||||||
|
|
@ -318,7 +317,7 @@ struct ImportStatement {
|
||||||
struct AliasDefinitionStatement {
|
struct AliasDefinitionStatement {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum {Alias, Type, Let} modifier;
|
utils::AliasModifier modifier;
|
||||||
TypeIdentifier type;
|
TypeIdentifier type;
|
||||||
std::vector<AbstractTypeIdentifier> parameters;
|
std::vector<AbstractTypeIdentifier> parameters;
|
||||||
std::unique_ptr<TypeExpression> value;
|
std::unique_ptr<TypeExpression> value;
|
||||||
|
|
@ -329,8 +328,8 @@ struct AliasDefinitionStatement {
|
||||||
struct VariableDefinitionStatement {
|
struct VariableDefinitionStatement {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum { Var, Const } modifier;
|
utils::IsConstModifier modifier;
|
||||||
enum { Move, Assign } assignment_modifier;
|
utils::AssignmentModifier assignment_modifier;
|
||||||
AnyName name;
|
AnyName name;
|
||||||
SuperExpression value;
|
SuperExpression value;
|
||||||
};
|
};
|
||||||
|
|
@ -358,7 +357,7 @@ struct FunctionDefinitionStatement {
|
||||||
struct TypeDefinitionStatement {
|
struct TypeDefinitionStatement {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum { Struct, Class } modifier;
|
utils::ClassModifier modifier;
|
||||||
std::unique_ptr<TypeDefinition> definition;
|
std::unique_ptr<TypeDefinition> definition;
|
||||||
AnyType value;
|
AnyType value;
|
||||||
|
|
||||||
|
|
@ -368,7 +367,7 @@ struct TypeDefinitionStatement {
|
||||||
struct AbstractTypeDefinitionStatement {
|
struct AbstractTypeDefinitionStatement {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum { Basic, Abstract } modifier;
|
utils::AbstractTypeModifier modifier;
|
||||||
std::unique_ptr<AnnotatedType> type;
|
std::unique_ptr<AnnotatedType> type;
|
||||||
|
|
||||||
utils::IdType type_graph_id_;
|
utils::IdType type_graph_id_;
|
||||||
|
|
@ -389,7 +388,7 @@ struct TypeclassDefinitionStatement {
|
||||||
struct FunctionDefinition {
|
struct FunctionDefinition {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum { Operator, Function } modifier;
|
utils::FunctionTypeModifier modifier;
|
||||||
ExtendedName name;
|
ExtendedName name;
|
||||||
std::vector<ExtendedName> arguments;
|
std::vector<ExtendedName> arguments;
|
||||||
};
|
};
|
||||||
|
|
@ -514,7 +513,7 @@ struct UnaryOperatorExpression {
|
||||||
struct ReferenceExpression {
|
struct ReferenceExpression {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::vector<utils::ReferenceType> references;
|
std::vector<utils::ReferenceModifier> references;
|
||||||
std::unique_ptr<ScopedStatement> expression;
|
std::unique_ptr<ScopedStatement> expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -558,9 +557,8 @@ struct ReturnExpression {
|
||||||
struct TypeConstructorParameter {
|
struct TypeConstructorParameter {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
enum AssignmentModifier { Move, Assign };
|
|
||||||
std::optional<ExtendedName> name;
|
std::optional<ExtendedName> name;
|
||||||
std::optional<AssignmentModifier> asignment_modifier;
|
std::optional<utils::AssignmentModifier> asignment_modifier;
|
||||||
SubExpression value;
|
SubExpression value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -663,7 +661,7 @@ struct TypeExpression {
|
||||||
struct ExtendedScopedAnyType {
|
struct ExtendedScopedAnyType {
|
||||||
BaseNode base;
|
BaseNode base;
|
||||||
|
|
||||||
std::vector<utils::ReferenceType> references;
|
std::vector<utils::ReferenceModifier> references;
|
||||||
AnyType type;
|
AnyType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ class TypeManager;
|
||||||
class AbstractType { // later will be found in context
|
class AbstractType { // later will be found in context
|
||||||
public:
|
public:
|
||||||
AbstractType() = default;
|
AbstractType() = default;
|
||||||
AbstractType(const std::string& name,
|
AbstractType(utils::AbstractTypeModifier modifier,
|
||||||
const std::vector<utils::IdType>& requirements) : name_(name) {
|
const std::string& name,
|
||||||
|
const std::vector<utils::IdType>& requirements) : modifier_(modifier), name_(name) {
|
||||||
for (auto& typeclass : requirements) {
|
for (auto& typeclass : requirements) {
|
||||||
requirements_.insert(typeclass);
|
requirements_.insert(typeclass);
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +32,7 @@ public:
|
||||||
bool operator<(const AbstractType& type) const;
|
bool operator<(const AbstractType& type) const;
|
||||||
bool operator>(const AbstractType& type) const;
|
bool operator>(const AbstractType& type) const;
|
||||||
private:
|
private:
|
||||||
|
utils::AbstractTypeModifier modifier_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::unordered_set<utils::IdType> requirements_; // TODO: all typeclasses from tree
|
std::unordered_set<utils::IdType> requirements_; // TODO: all typeclasses from tree
|
||||||
};
|
};
|
||||||
|
|
@ -135,7 +137,7 @@ private:
|
||||||
class ReferenceToType {
|
class ReferenceToType {
|
||||||
public:
|
public:
|
||||||
ReferenceToType() = default;
|
ReferenceToType() = default;
|
||||||
ReferenceToType(const std::vector<utils::ReferenceType>& references,
|
ReferenceToType(const std::vector<utils::ReferenceModifier>& references,
|
||||||
utils::IdType type,
|
utils::IdType type,
|
||||||
TypeManager* type_manager)
|
TypeManager* type_manager)
|
||||||
: references_(references), type_(type), type_manager_(type_manager) {}
|
: references_(references), type_(type), type_manager_(type_manager) {}
|
||||||
|
|
@ -146,7 +148,7 @@ public:
|
||||||
bool operator>(const ReferenceToType& type) const;
|
bool operator>(const ReferenceToType& type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<utils::ReferenceType> references_;
|
std::vector<utils::ReferenceModifier> references_;
|
||||||
utils::IdType type_;
|
utils::IdType type_;
|
||||||
TypeManager* type_manager_ = nullptr;
|
TypeManager* type_manager_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,13 @@ using std::size_t;
|
||||||
|
|
||||||
using IdType = size_t;
|
using IdType = size_t;
|
||||||
|
|
||||||
enum class ReferenceType { Reference = 0, UniqueReference = 1 };
|
enum class ReferenceModifier { Reference = 0, UniqueReference = 1 };
|
||||||
|
enum class IsConstModifier { Const = 0, Var = 1 };
|
||||||
|
enum class ClassModifier { Struct = 0, Class = 1 };
|
||||||
|
enum class AssignmentModifier { Assign = 0, Move = 1 };
|
||||||
|
enum class AliasModifier { Alias = 0, Type = 1, Let = 2 };
|
||||||
|
enum class AbstractTypeModifier { Basic = 0, Abstract = 1 };
|
||||||
|
enum class FunctionTypeModifier { Function = 0, Operator = 1 };
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Storage {
|
class Storage {
|
||||||
|
|
|
||||||
|
|
@ -95,9 +95,9 @@ void BuildVisitor::Visit(Namespace* node) {
|
||||||
if (child_count > 3) { // "namespace", ["var"/"const",] type, scope
|
if (child_count > 3) { // "namespace", ["var"/"const",] type, scope
|
||||||
std::string modifier = parse_node.NthChild(1).GetValue();
|
std::string modifier = parse_node.NthChild(1).GetValue();
|
||||||
if (modifier == "const") {
|
if (modifier == "const") {
|
||||||
node->modifier = Namespace::Const;
|
node->modifier = utils::IsConstModifier::Const;
|
||||||
} else if (modifier == "var") {
|
} 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();
|
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||||
if (modifier == "alias") {
|
if (modifier == "alias") {
|
||||||
node->modifier = AliasDefinitionStatement::Alias;
|
node->modifier = utils::AliasModifier::Alias;
|
||||||
} else if (modifier == "type") {
|
} else if (modifier == "type") {
|
||||||
node->modifier = AliasDefinitionStatement::Type;
|
node->modifier = utils::AliasModifier::Type;
|
||||||
} else if (modifier == "let") {
|
} else if (modifier == "let") {
|
||||||
node->modifier = AliasDefinitionStatement::Let;
|
node->modifier = utils::AliasModifier::Let;
|
||||||
}
|
}
|
||||||
|
|
||||||
node->type = parse_node.ChildByFieldName("type").GetValue();
|
node->type = parse_node.ChildByFieldName("type").GetValue();
|
||||||
|
|
@ -182,9 +182,9 @@ void BuildVisitor::Visit(VariableDefinitionStatement* node) {
|
||||||
|
|
||||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||||
if (modifier == "const") {
|
if (modifier == "const") {
|
||||||
node->modifier = VariableDefinitionStatement::Const;
|
node->modifier = utils::IsConstModifier::Const;
|
||||||
} else if (modifier == "var") {
|
} else if (modifier == "var") {
|
||||||
node->modifier = VariableDefinitionStatement::Var;
|
node->modifier = utils::IsConstModifier::Var;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("name");
|
current_node_ = parse_node.ChildByFieldName("name");
|
||||||
|
|
@ -195,9 +195,9 @@ void BuildVisitor::Visit(VariableDefinitionStatement* node) {
|
||||||
|
|
||||||
std::string assignment_modifier = parse_node.NthChild(2).GetValue();
|
std::string assignment_modifier = parse_node.NthChild(2).GetValue();
|
||||||
if (assignment_modifier == "=") {
|
if (assignment_modifier == "=") {
|
||||||
node->assignment_modifier = VariableDefinitionStatement::Assign;
|
node->assignment_modifier = utils::AssignmentModifier::Assign;
|
||||||
} else if (assignment_modifier == "<-") {
|
} else if (assignment_modifier == "<-") {
|
||||||
node->assignment_modifier = VariableDefinitionStatement::Move;
|
node->assignment_modifier = utils::AssignmentModifier::Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node;
|
current_node_ = parse_node;
|
||||||
|
|
@ -252,9 +252,9 @@ void BuildVisitor::Visit(TypeDefinitionStatement* node) {
|
||||||
|
|
||||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||||
if (modifier == "class") {
|
if (modifier == "class") {
|
||||||
node->modifier = TypeDefinitionStatement::Class;
|
node->modifier = utils::ClassModifier::Class;
|
||||||
} else if (modifier == "struct") {
|
} else if (modifier == "struct") {
|
||||||
node->modifier = TypeDefinitionStatement::Struct;
|
node->modifier = utils::ClassModifier::Struct;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("definition");
|
current_node_ = parse_node.ChildByFieldName("definition");
|
||||||
|
|
@ -274,9 +274,9 @@ void BuildVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
||||||
|
|
||||||
std::string modifier = parse_node.NthChild(0).GetValue();
|
std::string modifier = parse_node.NthChild(0).GetValue();
|
||||||
if (modifier == "basic") {
|
if (modifier == "basic") {
|
||||||
node->modifier = AbstractTypeDefinitionStatement::Basic;
|
node->modifier = utils::AbstractTypeModifier::Basic;
|
||||||
} else if (modifier == "abstract") {
|
} else if (modifier == "abstract") {
|
||||||
node->modifier = AbstractTypeDefinitionStatement::Abstract;
|
node->modifier = utils::AbstractTypeModifier::Abstract;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_node_ = parse_node.ChildByFieldName("type");
|
current_node_ = parse_node.ChildByFieldName("type");
|
||||||
|
|
@ -397,9 +397,9 @@ void BuildVisitor::Visit(FunctionDefinition* node) {
|
||||||
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
node->name.name = parse_node.ChildByFieldName("name").GetValue();
|
||||||
|
|
||||||
if (parse_node.NthChild(0).GetValue() == "(") {
|
if (parse_node.NthChild(0).GetValue() == "(") {
|
||||||
node->modifier = FunctionDefinition::Operator;
|
node->modifier = utils::FunctionTypeModifier::Operator;
|
||||||
} else {
|
} else {
|
||||||
node->modifier = FunctionDefinition::Function;
|
node->modifier = utils::FunctionTypeModifier::Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t child_count = parse_node.NamedChildCount();
|
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) {
|
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||||
std::string reference = parse_node.NthChild(i).GetValue();
|
std::string reference = parse_node.NthChild(i).GetValue();
|
||||||
if (reference == "~") {
|
if (reference == "~") {
|
||||||
node->references[i] = utils::ReferenceType::Reference;
|
node->references[i] = utils::ReferenceModifier::Reference;
|
||||||
} else if (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();
|
std::string assignment_modifier = current_node_.NextSibling().GetValue();
|
||||||
if (assignment_modifier == "=") {
|
if (assignment_modifier == "=") {
|
||||||
node->asignment_modifier = TypeConstructorParameter::Assign;
|
node->asignment_modifier = utils::AssignmentModifier::Assign;
|
||||||
} else if (assignment_modifier == "<-") {
|
} 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) {
|
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||||
std::string reference = parse_node.NthChild(i).GetValue();
|
std::string reference = parse_node.NthChild(i).GetValue();
|
||||||
if (reference == "~") {
|
if (reference == "~") {
|
||||||
node->references[i] = utils::ReferenceType::Reference;
|
node->references[i] = utils::ReferenceModifier::Reference;
|
||||||
} else if (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) {
|
void FindSymbolsVisitor::Visit(Namespace* node) {
|
||||||
std::optional<info::definition::Namespace::Modifier> modifier;
|
namespace_visitor_.AddEnterNamespace(node->type, node->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);
|
|
||||||
Visitor::Visit(&node->scope);
|
Visitor::Visit(&node->scope);
|
||||||
namespace_visitor_.ExitNamespace();
|
namespace_visitor_.ExitNamespace();
|
||||||
}
|
}
|
||||||
|
|
@ -51,17 +39,7 @@ void FindSymbolsVisitor::Visit(AliasDefinitionStatement* node) {
|
||||||
|
|
||||||
info::definition::AliasType alias_info;
|
info::definition::AliasType alias_info;
|
||||||
|
|
||||||
switch (node->modifier) {
|
alias_info.modifier = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: deduce parameter requirements
|
// TODO: deduce parameter requirements
|
||||||
|
|
||||||
|
|
@ -71,7 +49,7 @@ void FindSymbolsVisitor::Visit(AliasDefinitionStatement* node) {
|
||||||
|
|
||||||
info.type = std::move(alias_info);
|
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;
|
is_in_statement_ = false;
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +128,7 @@ void FindSymbolsVisitor::Visit(TypeDefinitionStatement* node) {
|
||||||
|
|
||||||
info.type = std::move(any_type_info);
|
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;
|
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_));
|
info.type = std::move(std::any_cast<info::definition::Parameter>(current_info_));
|
||||||
current_info_.reset();
|
current_info_.reset();
|
||||||
|
|
||||||
switch (node->modifier) {
|
info.modifier = node->modifier;
|
||||||
case interpreter::AbstractTypeDefinitionStatement::Basic:
|
|
||||||
info.modifier = info::definition::AbstractType::Basic;
|
|
||||||
break;
|
|
||||||
case interpreter::AbstractTypeDefinitionStatement::Abstract:
|
|
||||||
info.modifier = info::definition::AbstractType::Abstract;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string type = info.type.type;
|
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;
|
is_in_statement_ = false;
|
||||||
}
|
}
|
||||||
|
|
@ -201,7 +172,7 @@ void FindSymbolsVisitor::Visit(TypeclassDefinitionStatement* node) {
|
||||||
current_info_.reset();
|
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;
|
is_in_statement_ = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,14 @@ void GlobalInfo::NamespaceVisitor::AddImport(definition::Import&& import_info,
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalInfo::NamespaceVisitor::AddEnterNamespace(const std::string& name,
|
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;
|
definition::Namespace* namespace_info = nullptr;
|
||||||
if (modifier.has_value()) {
|
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_stack_.push_back(namespace_info);
|
||||||
|
|
||||||
namespace_info->modifier = modifier;
|
namespace_info->modifier = modifier;
|
||||||
|
|
@ -112,7 +116,8 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(const std::str
|
||||||
// TODO: internal types, etc.
|
// TODO: internal types, etc.
|
||||||
// TODO: extended constructor names (point separated names)
|
// TODO: extended constructor names (point separated names)
|
||||||
utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
|
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;
|
size_t id = 0;
|
||||||
|
|
||||||
auto type_id_iter = namespace_stack_.back()->types.find(type);
|
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;
|
namespace_stack_.back()->types[type] = id;
|
||||||
global_info_.types_.push_back(std::move(type_info));
|
global_info_.types_.push_back(std::move(type_info));
|
||||||
} else {
|
} 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();
|
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;
|
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
|
// TODO: link abstract type with let definitions
|
||||||
utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& abstract_type,
|
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()) {
|
if (!FindAbstractType(abstract_type).has_value()) {
|
||||||
size_t id = global_info_.abstract_types_.size();
|
size_t id = global_info_.abstract_types_.size();
|
||||||
global_info_.name_to_abstract_type_[abstract_type] = id;
|
global_info_.name_to_abstract_type_[abstract_type] = id;
|
||||||
global_info_.abstract_types_.push_back(std::move(abstract_type_info));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::IdType GlobalInfo::NamespaceVisitor::AddTypeclass(const std::string& typeclass,
|
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()) {
|
if (!FindTypeclass(typeclass).has_value()) {
|
||||||
size_t id = global_info_.typeclasses_.size();
|
size_t id = global_info_.typeclasses_.size();
|
||||||
global_info_.name_to_typeclass_[typeclass] = id;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::IdType GlobalInfo::NamespaceVisitor::AddConstructor(const std::string& constructor,
|
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);
|
auto constructor_id_iter = namespace_stack_.back()->constructors.find(constructor);
|
||||||
|
|
||||||
if (constructor_id_iter == namespace_stack_.back()->constructors.end()) {
|
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));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,14 +241,22 @@ std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindFunction(
|
||||||
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethod(
|
std::optional<utils::IdType> GlobalInfo::NamespaceVisitor::FindMethod(
|
||||||
const std::optional<std::vector<std::string>>& path,
|
const std::optional<std::vector<std::string>>& path,
|
||||||
const std::string& type,
|
const std::string& type,
|
||||||
const std::string& name) {
|
const std::string& name,
|
||||||
|
utils::IsConstModifier modifier) {
|
||||||
// TODO: remove overhead
|
// TODO: remove overhead
|
||||||
|
|
||||||
return GlobalInfo::NamespaceVisitor::FindSomething<utils::IdType>(path,
|
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;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,31 +41,40 @@ void TypeCheckVisitor::Visit(NamespaceSources* node) {
|
||||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
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()) {
|
if (node->modifier.has_value()) {
|
||||||
// TODO
|
bool is_const = node->modifier.value() == utils::IsConstModifier::Const;
|
||||||
if (node->link_typeclass_id_.has_value()) {
|
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
if (node->link_typeclass_id_.has_value()) { // ??
|
if (node->link_typeclass_id_.has_value()) { // ??
|
||||||
error_handling::HandleTypecheckError("Typeclass can't have not variable namespace", node->base);
|
error_handling::HandleTypecheckError("Typeclass can't have not variable namespace", node->base);
|
||||||
}
|
}
|
||||||
|
context_manager_.EnterContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace_visitor_.EnterNamespace(node->type);
|
namespace_visitor_.EnterNamespace(node->type);
|
||||||
|
|
||||||
Visit(&node->scope);
|
Visit(&node->scope);
|
||||||
|
|
||||||
namespace_visitor_.ExitNamespace();
|
namespace_visitor_.ExitNamespace();
|
||||||
|
context_manager_.ExitContext();
|
||||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,22 +90,27 @@ void TypeCheckVisitor::Visit(AliasDefinitionStatement* node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: parameter requirments
|
context_manager_.EnterContext();
|
||||||
|
|
||||||
for (auto& parameter : node->parameters) {
|
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_);
|
context_manager_.DefineLocalAbstractType(parameter, current_type_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Visit(node->value.get());
|
Visit(node->value.get());
|
||||||
|
|
||||||
|
context_manager_.ExitContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove variable on move, etc.
|
// TODO: remove variable on move
|
||||||
void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
||||||
is_in_statement_ = true;
|
is_in_statement_ = true;
|
||||||
|
|
||||||
Visitor::Visit(node->value);
|
Visitor::Visit(node->value);
|
||||||
// current_type from value automatically passed to name definitions
|
// 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);
|
Visitor::Visit(node->name);
|
||||||
is_const_definition_ = std::nullopt;
|
is_const_definition_ = std::nullopt;
|
||||||
|
|
||||||
|
|
@ -109,7 +123,6 @@ void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
|
||||||
bool was_in_statement = is_in_statement_;
|
bool was_in_statement = is_in_statement_;
|
||||||
is_in_statement_ = true;
|
is_in_statement_ = true;
|
||||||
|
|
||||||
// check declaration correctness ??
|
|
||||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||||
|
|
||||||
if (!was_in_statement) {
|
if (!was_in_statement) {
|
||||||
|
|
@ -139,21 +152,22 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||||
requirements.push_back(typeclass->typeclass_id_);
|
requirements.push_back(typeclass->typeclass_id_);
|
||||||
}
|
}
|
||||||
// TODO: add recursive typeclasses from typeclass tree
|
// 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_)) {
|
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) {
|
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
|
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);
|
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_;
|
utils::IdType return_type = current_type_;
|
||||||
|
|
||||||
Visitor::Visit(node->value);
|
Visitor::Visit(node->value);
|
||||||
|
|
@ -168,11 +182,9 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
||||||
is_in_statement_ = false;
|
is_in_statement_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO ??
|
|
||||||
void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
|
void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
|
||||||
is_in_statement_ = true;
|
is_in_statement_ = true;
|
||||||
|
|
||||||
// check definition correctness ??
|
|
||||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||||
|
|
||||||
is_in_statement_ = false;
|
is_in_statement_ = false;
|
||||||
|
|
@ -181,7 +193,7 @@ void TypeCheckVisitor::Visit(TypeDefinitionStatement* node) {
|
||||||
void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
||||||
is_in_statement_ = true;
|
is_in_statement_ = true;
|
||||||
|
|
||||||
// TODO: basic types ??
|
// basic types ??
|
||||||
|
|
||||||
std::vector<utils::IdType> requirements;
|
std::vector<utils::IdType> requirements;
|
||||||
requirements.reserve(node->type->typeclasses.size());
|
requirements.reserve(node->type->typeclasses.size());
|
||||||
|
|
@ -189,9 +201,10 @@ void TypeCheckVisitor::Visit(AbstractTypeDefinitionStatement* node) {
|
||||||
requirements.push_back(typeclass->typeclass_id_);
|
requirements.push_back(typeclass->typeclass_id_);
|
||||||
}
|
}
|
||||||
// TODO: add recursive typeclasses from typeclass tree
|
// 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_)) {
|
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);
|
current_type_ = context_manager_.AddType(info::type::InternalType::Unit);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue