mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-26 16:58:45 +00:00
type_check_visitor first iteration, value, execution_visitor started
This commit is contained in:
parent
173d50672a
commit
890bd90eba
22 changed files with 481 additions and 452 deletions
|
|
@ -487,6 +487,7 @@ void BuildVisitor::Visit(TypeConstructorPattern* node) {
|
|||
auto parse_node = current_node_;
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("constructor");
|
||||
node->constructor = std::make_unique<TypeExpression>();
|
||||
Visit(node->constructor.get());
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
|
@ -988,8 +989,6 @@ void BuildVisitor::Visit(FunctionCallExpression* node) {
|
|||
if (child_count > excluded_child_count) {
|
||||
bool parameters_ended = false;
|
||||
|
||||
node->arguments.resize(child_count - excluded_child_count);
|
||||
|
||||
for (size_t i = 0; i + excluded_child_count < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + excluded_child_count);
|
||||
|
||||
|
|
@ -1499,12 +1498,7 @@ void BuildVisitor::Visit(ParametrizedType* node) {
|
|||
void BuildVisitor::Visit(ExtendedName* node) {
|
||||
SetPosition(node->base, current_node_);
|
||||
|
||||
size_t child_count = current_node_.NamedChildCount();
|
||||
if (child_count > 1) {
|
||||
node->name = current_node_.GetValue();
|
||||
} else {
|
||||
node->name = current_node_.NthNamedChild(0).GetValue();
|
||||
}
|
||||
node->name = current_node_.GetValue();
|
||||
}
|
||||
|
||||
// void BuildVisitor::Visit(AnyIdentifier* node) { // std::string
|
||||
|
|
|
|||
0
src/execute_visitor.cpp
Normal file
0
src/execute_visitor.cpp
Normal file
|
|
@ -47,7 +47,8 @@ void GlobalInfo::NamespaceVisitor::EnterNamespace(const std::string& name) {
|
|||
}
|
||||
}
|
||||
|
||||
error_handling::HandleInternalError("Can't find namespace", "GlobalInfo.NamespaceVisitor.EnterNamespace");
|
||||
error_handling::HandleInternalError("Can't find namespace",
|
||||
"GlobalInfo.NamespaceVisitor.EnterNamespace");
|
||||
}
|
||||
|
||||
void GlobalInfo::NamespaceVisitor::ExitNamespace() {
|
||||
|
|
@ -67,8 +68,10 @@ void GlobalInfo::NamespaceVisitor::ToGlobalNamespace() {
|
|||
namespace_stack_.push_back(&global_info_.global_namespace_);
|
||||
}
|
||||
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(const std::string& name,
|
||||
definition::FunctionDeclaration&& function_declaration_info) {
|
||||
utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(
|
||||
const std::string& name,
|
||||
definition::FunctionDeclaration&& function_declaration_info) {
|
||||
|
||||
size_t id = 0;
|
||||
|
||||
auto function_id_iter = namespace_stack_.back()->functions.find(name);
|
||||
|
|
@ -77,12 +80,13 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDeclaration(const std::st
|
|||
id = global_info_.functions_.size();
|
||||
namespace_stack_.back()->functions[name] = id;
|
||||
global_info_.functions_.emplace_back();
|
||||
global_info_.functions_.back().argument_count = function_declaration_info.argument_types.size();
|
||||
global_info_.functions_.back().argument_count = function_declaration_info.argument_types.size(); // add return type
|
||||
global_info_.functions_.back().declaration = std::move(function_declaration_info);
|
||||
} else {
|
||||
id = function_id_iter->second;
|
||||
if (global_info_.functions_.back().argument_count != function_declaration_info.argument_types.size()) {
|
||||
error_handling::HandleInternalError("Not same argument count in function definition and declaration", "GlobalInfo");
|
||||
error_handling::HandleInternalError("Not same argument count in function definition and declaration",
|
||||
"GlobalInfo.NamespaceVisitor. AddFunctionDeclaration");
|
||||
}
|
||||
global_info_.functions_[id].declaration = std::move(function_declaration_info);
|
||||
}
|
||||
|
|
@ -100,11 +104,11 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddFunctionDefinition(const std::str
|
|||
id = global_info_.functions_.size();
|
||||
namespace_stack_.back()->functions[name] = id;
|
||||
global_info_.functions_.emplace_back();
|
||||
global_info_.functions_.back().argument_count = function_definition_info.argument_names.size();
|
||||
global_info_.functions_.back().argument_count = function_definition_info.argument_names.size() + 1;
|
||||
global_info_.functions_.back().definition = std::move(function_definition_info);
|
||||
} else {
|
||||
id = function_id_iter->second;
|
||||
if (global_info_.functions_.back().argument_count != function_definition_info.argument_names.size()) {
|
||||
if (global_info_.functions_.back().argument_count != function_definition_info.argument_names.size() + 1) {
|
||||
error_handling::HandleInternalError("Not same argument count in function definition and declaration", "GlobalInfo");
|
||||
}
|
||||
global_info_.functions_[id].definition = std::move(function_definition_info);
|
||||
|
|
@ -178,12 +182,15 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddAbstractType(const std::string& a
|
|||
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();
|
||||
utils::IdType 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));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace", base_node);
|
||||
error_handling::HandleTypecheckError("More then one abstract type with the same name in namespace",
|
||||
base_node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -341,6 +348,8 @@ std::optional<T> GlobalInfo::NamespaceVisitor::FindSomething(
|
|||
if (!maybe_namespace.has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
current_namespace = maybe_namespace.value();
|
||||
} else {
|
||||
current_namespace = namespace_stack_[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,9 +50,14 @@ void LinkSymbolsVisitor::Visit(TypeExpression* node) { // TODO: check
|
|||
node->type_id_ = namespace_visitor_.FindType(path, node->type.type);
|
||||
node->constructor_id_ = namespace_visitor_.FindConstructor(path, node->type.type);
|
||||
|
||||
// if (!node->type_id_.has_value() && !node->constructor_id_.has_value()) { // TODO: check, that not bastract types
|
||||
// error_handling::HandleTypecheckError("Type or constructor not found", node->base);
|
||||
// }
|
||||
if (path.size() == 0 && namespace_visitor_.FindAbstractType(node->type.type).has_value()) { // TODO
|
||||
// abstract / basic / TODO: local abstract type
|
||||
return;
|
||||
}
|
||||
|
||||
if (!node->type_id_.has_value() && !node->constructor_id_.has_value()) { // TODO: check, that not bastract types
|
||||
error_handling::HandleTypecheckError("Type or constructor not found", node->base);
|
||||
}
|
||||
|
||||
if (node->constructor_id_.has_value()) {
|
||||
utils::IdType constructor_type_id = namespace_visitor_.GetGlobalInfo()->GetConstructorInfo(node->constructor_id_.value()).type_id;
|
||||
|
|
|
|||
|
|
@ -47,15 +47,21 @@ int main(int argc, char** argv) { // TODO, only test version
|
|||
info::TypeInfoContextManager context_manager;
|
||||
|
||||
interpreter::BuildVisitor build_visitor(parse_tree);
|
||||
// interpreter::PrintVisitor print_visitor(std::cout);
|
||||
interpreter::PrintVisitor print_visitor(std::cout);
|
||||
interpreter::FindSymbolsVisitor find_symbols_visitor(global_info);
|
||||
interpreter::LinkSymbolsVisitor link_symbols_visitor(global_info);
|
||||
interpreter::TypeCheckVisitor type_check_visitor(global_info, context_manager);
|
||||
interpreter::TypedPrintVisitor typed_print_visitor(std::cout, context_manager);
|
||||
|
||||
build_visitor.VisitSourceFile(source_file.get());
|
||||
|
||||
std::cout << "\n---------------------------------- Untyped -------------------------------------\n\n";
|
||||
print_visitor.VisitSourceFile(source_file.get());
|
||||
|
||||
find_symbols_visitor.VisitSourceFile(source_file.get());
|
||||
link_symbols_visitor.VisitSourceFile(source_file.get());
|
||||
type_check_visitor.VisitSourceFile(source_file.get());
|
||||
|
||||
std::cout << "\n---------------------------------- Typed -------------------------------------\n\n";
|
||||
typed_print_visitor.VisitSourceFile(source_file.get());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,8 +52,6 @@ void TypeCheckVisitor::Visit(NamespaceSources* node) {
|
|||
|
||||
void TypeCheckVisitor::Visit(Namespace* node) { // TODO: two var namespces for class: const and var
|
||||
if (node->modifier.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()};
|
||||
|
|
@ -65,10 +63,10 @@ void TypeCheckVisitor::Visit(Namespace* node) { // TODO: two var namespces for c
|
|||
abstract_type);
|
||||
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?
|
||||
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 ??
|
||||
"self", // TODO: different name
|
||||
context_manager_.AddType(
|
||||
info::type::DefinedType(node->link_type_id_.value(), current_type_, context_manager_.GetTypeManager()),
|
||||
IsConstModifierToValueType(node->modifier.value())));
|
||||
|
|
@ -147,6 +145,20 @@ void TypeCheckVisitor::Visit(FunctionDeclaration* node) {
|
|||
bool was_in_statement = is_in_statement_;
|
||||
is_in_statement_ = true;
|
||||
|
||||
context_manager_.EnterContext();
|
||||
for (auto& parameter : node->parameters) { // declaration correctness check // TODO: needed??
|
||||
std::vector<utils::IdType> requirements;
|
||||
// TODO:
|
||||
current_type_ = context_manager_.AddType(
|
||||
info::type::AbstractType(utils::AbstractTypeModifier::Abstract,
|
||||
parameter->type,
|
||||
requirements), // TODO: typeclasses-requirements
|
||||
utils::ValueType::Tmp);
|
||||
context_manager_.DefineLocalAbstractType(parameter->type, current_type_);
|
||||
}
|
||||
Visit(node->type.get());
|
||||
context_manager_.ExitContext();
|
||||
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
if (!was_in_statement) {
|
||||
|
|
@ -196,7 +208,7 @@ void TypeCheckVisitor::Visit(FunctionDefinitionStatement* node) {
|
|||
Visitor::Visit(*declaration.argument_types.back());
|
||||
utils::IdType return_type = current_type_;
|
||||
|
||||
Visitor::Visit(node->value);
|
||||
// Visitor::Visit(node->value);
|
||||
if (!context_manager_.EqualTypes(return_type, current_type_)) {
|
||||
error_handling::HandleTypecheckError("Wrong function return type", node->base);
|
||||
}
|
||||
|
|
@ -298,7 +310,7 @@ void TypeCheckVisitor::Visit(TypeConstructorPattern* node) { // TODO: match name
|
|||
CollectTypeExpressionContext(*node->constructor, context);
|
||||
|
||||
// TODO: handle alias types
|
||||
const std::optional<info::definition::AnyType>& maybe_type_info =
|
||||
std::optional<info::definition::AnyType*> maybe_type_info =
|
||||
namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(type_id);
|
||||
|
||||
if (!maybe_type_info.has_value()) { // TODO
|
||||
|
|
@ -306,7 +318,7 @@ void TypeCheckVisitor::Visit(TypeConstructorPattern* node) { // TODO: match name
|
|||
"TypeCheckVisitor.TypeConstructorPattern");
|
||||
}
|
||||
|
||||
const info::definition::AnyType& type_info = maybe_type_info.value();
|
||||
info::definition::AnyType& type_info = *maybe_type_info.value();
|
||||
|
||||
if (constructor_info.constructor_tuple_node.has_value()) {
|
||||
|
||||
|
|
@ -495,8 +507,8 @@ void TypeCheckVisitor::Visit(ForLoop* node) {
|
|||
|
||||
context_manager_.EnterContext();
|
||||
|
||||
current_type_ = context_manager_.AddType(maybe_interval_type.value()->GetElementsType(),
|
||||
utils::IsConstModifierToValueType(node->variable_modifier));
|
||||
current_type_ = context_manager_.ToModifiedType(maybe_interval_type.value()->GetElementsType(),
|
||||
utils::IsConstModifierToValueType(node->variable_modifier));
|
||||
|
||||
is_const_definition_ = node->variable_modifier;
|
||||
Visitor::Visit(node->variable); // type passed to variable definition throught current_type_
|
||||
|
|
@ -625,7 +637,7 @@ void TypeCheckVisitor::Visit(BinaryOperatorExpression* node) {
|
|||
|
||||
auto maybe_left_type_info = namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(maybe_left_type.value()->GetTypeId());
|
||||
|
||||
std::string left_type_name = maybe_left_type_info.value().type.type;
|
||||
std::string left_type_name = maybe_left_type_info.value()->type.type;
|
||||
|
||||
auto maybe_const_operator_id = namespace_visitor_.FindMethod(std::nullopt,
|
||||
left_type_name,
|
||||
|
|
@ -780,7 +792,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
|||
|
||||
utils::IdType type_id = maybe_expression_type.value()->GetTypeId();
|
||||
|
||||
const std::optional<info::definition::AnyType>& maybe_type_info = namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(type_id);
|
||||
std::optional<info::definition::AnyType*> maybe_type_info = namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(type_id);
|
||||
|
||||
if (!maybe_type_info.has_value()) {
|
||||
error_handling::HandleInternalError("Functions/Methods implemented only for AnyType",
|
||||
|
|
@ -788,7 +800,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
|||
}
|
||||
|
||||
// TODO: better decision ??
|
||||
std::optional<utils::IdType> maybe_const_function_id = maybe_type_info.value().parent_namespace->const_namespaces.at(maybe_type_info->type.type).functions[node->name.name];
|
||||
std::optional<utils::IdType> maybe_const_function_id = maybe_type_info.value()->parent_namespace->const_namespaces.at(maybe_type_info.value()->type.type).functions[node->name.name];
|
||||
|
||||
utils::ValueType expression_value_type = context_manager_.GetValueType(current_type_);
|
||||
|
||||
|
|
@ -799,7 +811,7 @@ void TypeCheckVisitor::Visit(FunctionCallExpression* node) {
|
|||
|
||||
if (expression_value_type == utils::ValueType::Var || expression_value_type == utils::ValueType::Tmp) {
|
||||
// TODO: choose expression value types
|
||||
maybe_function_id = maybe_type_info.value().parent_namespace->var_namespaces.at(maybe_type_info->type.type).functions[node->name.name];
|
||||
maybe_function_id = maybe_type_info.value()->parent_namespace->var_namespaces.at(maybe_type_info.value()->type.type).functions[node->name.name];
|
||||
}
|
||||
|
||||
if (maybe_const_function_id.has_value() && maybe_function_id.has_value()) { // TODO: handle on link_types stage
|
||||
|
|
@ -899,7 +911,7 @@ void TypeCheckVisitor::Visit(VariantExpression* node) {
|
|||
|
||||
// TODO: deal with expression tuple types, etc, ??
|
||||
std::vector<std::pair<std::optional<std::string>, utils::IdType>> constructor_fields {{std::nullopt, current_type_}};
|
||||
constructors.emplace_back(std::nullopt, constructor_fields, context_manager_.GetTypeManager());
|
||||
constructors.push_back(info::type::TupleType(std::nullopt, constructor_fields, context_manager_.GetTypeManager()));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -937,14 +949,14 @@ void TypeCheckVisitor::Visit(TypeConstructor* node) {
|
|||
CollectTypeExpressionContext(*node->constructor, context);
|
||||
|
||||
// TODO: handle alias types
|
||||
const std::optional<info::definition::AnyType>& maybe_type_info =
|
||||
std::optional<info::definition::AnyType*> maybe_type_info =
|
||||
namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(type_id);
|
||||
|
||||
if (!maybe_type_info.has_value()) { // TODO
|
||||
error_handling::HandleInternalError("Implemented only for AnyType", "TypeCheckVisitor.TypeConstructor");
|
||||
}
|
||||
|
||||
const info::definition::AnyType& type_info = maybe_type_info.value();
|
||||
info::definition::AnyType& type_info = *maybe_type_info.value();
|
||||
|
||||
if (constructor_info.constructor_tuple_node.has_value()) {
|
||||
|
||||
|
|
@ -1215,7 +1227,11 @@ void TypeCheckVisitor::Visit(TupleType* node) {
|
|||
fields.reserve(node->entities.size());
|
||||
for (auto& entity : node->entities) {
|
||||
Visit(entity.second.get());
|
||||
fields.emplace_back(entity.first, current_type_);
|
||||
if (entity.first.has_value()) {
|
||||
fields.push_back({entity.first.value().name, current_type_});
|
||||
} else {
|
||||
fields.push_back({std::nullopt, current_type_});
|
||||
}
|
||||
}
|
||||
|
||||
current_type_ = context_manager_.AddType(
|
||||
|
|
@ -1232,14 +1248,14 @@ void TypeCheckVisitor::Visit(VariantType* node) {
|
|||
for (auto& constructor : node->constructors) {
|
||||
if (std::holds_alternative<Constructor>(constructor)) {
|
||||
std::vector<std::pair<std::optional<std::string>, utils::IdType>> constructor_fields;
|
||||
constructors.emplace_back(std::get<Constructor>(constructor), constructor_fields, context_manager_.GetTypeManager());
|
||||
constructors.push_back(info::type::TupleType(std::get<Constructor>(constructor), constructor_fields, context_manager_.GetTypeManager()));
|
||||
} else if (std::holds_alternative<std::unique_ptr<TupleType>>(constructor)) {
|
||||
Visit(std::get<std::unique_ptr<TupleType>>(constructor).get());
|
||||
std::optional<TupleType*> maybe_constructor = context_manager_.GetType<TupleType>(current_type_);
|
||||
std::optional<info::type::TupleType*> maybe_constructor = context_manager_.GetType<info::type::TupleType>(current_type_);
|
||||
if (!maybe_constructor.has_value()) {
|
||||
error_handling::HandleInternalError("Entity of VariantType is not TupleType", "TypeCheckVisitor.VariantType");
|
||||
}
|
||||
constructors.emplace_back(maybe_constructor.value());
|
||||
constructors.push_back(*maybe_constructor.value());
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
|
@ -1256,20 +1272,23 @@ void TypeCheckVisitor::Visit(TypeExpression* node) {
|
|||
std::unordered_map<std::string, utils::IdType> context;
|
||||
CollectTypeExpressionContext(*node, context);
|
||||
|
||||
const std::optional<info::definition::AnyType>& maybe_type_info =
|
||||
namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(node->type.type_id_.value());
|
||||
|
||||
if (!maybe_type_info.has_value()) { // TODO: add alias, abstract, ... types
|
||||
error_handling::HandleInternalError("No any type found", "TypeCheckVisitor.TypeExpression");
|
||||
}
|
||||
|
||||
std::optional<utils::IdType> maybe_local_abstract_type = context_manager_.GetLocalAbstractType(node->type.type);
|
||||
if (node->path.size() == 0 && maybe_local_abstract_type.has_value()) {
|
||||
current_type_ = maybe_local_abstract_type.value();
|
||||
}
|
||||
} else if (node->type.type_id_.has_value()) { // TODO: chack that names are different (always true ??)
|
||||
|
||||
Visitor::Visit(*maybe_type_info.value().value);
|
||||
current_type_ = TypeInContext(current_type_, context);
|
||||
std::optional<info::definition::AnyType*> maybe_type_info =
|
||||
namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(node->type.type_id_.value());
|
||||
|
||||
if (!maybe_type_info.has_value()) { // TODO: add alias, abstract, ... types
|
||||
error_handling::HandleInternalError("No AnyType found", "TypeCheckVisitor.TypeExpression");
|
||||
}
|
||||
|
||||
Visitor::Visit(*maybe_type_info.value()->value);
|
||||
current_type_ = TypeInContext(current_type_, context);
|
||||
} else {
|
||||
error_handling::HandleTypecheckError("Type not found", node->base);
|
||||
}
|
||||
|
||||
if (node->array_size.has_value()) {
|
||||
current_type_ = context_manager_.AddType(
|
||||
|
|
@ -1330,6 +1349,12 @@ void TypeCheckVisitor::Visit(CharLiteral* node) {
|
|||
node->base.type_ = current_type_;
|
||||
}
|
||||
|
||||
void TypeCheckVisitor::Visit(UnitLiteral* node) {
|
||||
current_type_ = context_manager_.AddType(info::type::InternalType::Unit, utils::ValueType::Tmp);
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
void TypeCheckVisitor::CollectTypeContext(const ParametrizedType& type,
|
||||
|
|
@ -1338,14 +1363,14 @@ void TypeCheckVisitor::CollectTypeContext(const ParametrizedType& type,
|
|||
return;
|
||||
}
|
||||
|
||||
const std::optional<info::definition::AnyType>& maybe_type_info =
|
||||
std::optional<info::definition::AnyType*> maybe_type_info =
|
||||
namespace_visitor_.GetGlobalInfo()->GetTypeInfo<info::definition::AnyType>(type.type_id_.value());
|
||||
|
||||
if (!maybe_type_info.has_value()) {
|
||||
error_handling::HandleInternalError("Wrong type id", "TypeCheckVisitor.CollectTypeContext");
|
||||
}
|
||||
|
||||
const info::definition::AnyType& type_info = maybe_type_info.value();
|
||||
info::definition::AnyType& type_info = *maybe_type_info.value();
|
||||
|
||||
if (type_info.parameters.size() != type.parameters.size()) {
|
||||
error_handling::HandleTypecheckError("Wrong type parameters count", type.base);
|
||||
|
|
@ -1372,7 +1397,7 @@ void TypeCheckVisitor::CollectTypeExpressionContext(const TypeExpression& type_e
|
|||
|
||||
utils::IdType TypeCheckVisitor::TypeInContext(utils::IdType type,
|
||||
const std::unordered_map<std::string, utils::IdType>& context) {
|
||||
info::type::Type type_in_context = info::type::Type(context_manager_.GetAnyType(type));
|
||||
info::type::Type type_in_context = *context_manager_.GetAnyType(type);
|
||||
type_in_context.InContext(context);
|
||||
return context_manager_.AddType(std::move(type_in_context), utils::ValueType::Tmp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -466,42 +466,5 @@ std::string Type::GetTypeName() const {
|
|||
return ""; // ??
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<typename T>
|
||||
utils::IdType TypeManager::AddType(T&& type, utils::ValueType value_type) {
|
||||
types_.emplace_back({std::forward(type), value_type});
|
||||
return types_.size() - 1;
|
||||
}
|
||||
|
||||
utils::IdType TypeManager::AddAnyType(Type&& type, utils::ValueType value_type) {
|
||||
types_.push_back({std::move(type), value_type});
|
||||
return types_.size() - 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T*> TypeManager::GetType(utils::IdType type_id) {
|
||||
if (!std::holds_alternative<T>(types_.at(type_id).second)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return &std::get<T>(types_.at(type_id).second);
|
||||
}
|
||||
|
||||
Type* TypeManager::GetAnyType(utils::IdType type_id) {
|
||||
return &types_.at(type_id).first;
|
||||
}
|
||||
|
||||
utils::ValueType TypeManager::GetValueType(utils::IdType type_id) {
|
||||
return types_.at(type_id).second;
|
||||
}
|
||||
|
||||
bool TypeManager::EqualTypes(utils::IdType first_type, utils::IdType second_type) {
|
||||
return GetAnyType(first_type)->Same(*GetAnyType(second_type));
|
||||
}
|
||||
|
||||
bool TypeManager::AddTypeRequirement(utils::IdType type, utils::IdType requrement) {
|
||||
return *GetAnyType(requrement) < *GetAnyType(type);
|
||||
}
|
||||
|
||||
} // namespace info::type
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue