fixes, build_visitor TupleType and VariantType fix

This commit is contained in:
ProgramSnail 2023-05-17 17:57:56 +03:00
parent 692f7ea3ec
commit b723fd6a65
12 changed files with 321 additions and 241 deletions

View file

@ -167,42 +167,56 @@ utils::IdType GlobalInfo::NamespaceVisitor::AddType(const std::string& type,
definition::Type& moved_type_info = global_info_.types_.back();
// TODO: constructors for tuple types, function types (??), array types (??), ...
if (!std::holds_alternative<definition::AnyType>(moved_type_info.type)) {
error_handling::HandleInternalError("Not AnyType constructor search is not implemented yet",
"GlobalInfo.NamespaceVisitor.AddType");
}
if (std::holds_alternative<definition::AnyType>(moved_type_info.type)) {
definition::AnyType& any_type_info = std::get<definition::AnyType>(moved_type_info.type);
if (std::holds_alternative<std::unique_ptr<interpreter::tokens::VariantType>>(*any_type_info.value)) {
interpreter::tokens::VariantType& variant_type_info = *std::get<std::unique_ptr<interpreter::tokens::VariantType>>(*any_type_info.value);
for (size_t i = 0; i < variant_type_info.constructors.size(); ++i) {
std::string constructor_name;
definition::Constructor constructor_info;
definition::AnyType& any_type_info = std::get<definition::AnyType>(moved_type_info.type);
if (std::holds_alternative<std::unique_ptr<interpreter::tokens::VariantType>>(*any_type_info.value)) {
interpreter::tokens::VariantType& variant_type_info = *std::get<std::unique_ptr<interpreter::tokens::VariantType>>(*any_type_info.value);
for (size_t i = 0; i < variant_type_info.constructors.size(); ++i) {
std::string constructor_name;
definition::Constructor constructor_info;
constructor_info.type_id = id;
constructor_info.order = i;
constructor_info.type_id = id;
constructor_info.order = i;
if (std::holds_alternative<interpreter::tokens::Constructor>(variant_type_info.constructors[i])) {
constructor_name = std::get<interpreter::tokens::Constructor>(variant_type_info.constructors[i]);
} else if (std::holds_alternative<
std::unique_ptr<interpreter::tokens::TupleType>>(variant_type_info.constructors[i])) {
constructor_info.constructor_tuple_node =
std::get<std::unique_ptr<interpreter::tokens::TupleType>>(variant_type_info.constructors[i]).get();
if (std::holds_alternative<interpreter::tokens::Constructor>(variant_type_info.constructors[i])) {
constructor_name = std::get<interpreter::tokens::Constructor>(variant_type_info.constructors[i]);
} else if (std::holds_alternative<
std::unique_ptr<interpreter::tokens::TupleType>>(variant_type_info.constructors[i])) {
constructor_info.constructor_tuple_node =
std::get<std::unique_ptr<interpreter::tokens::TupleType>>(variant_type_info.constructors[i]).get();
auto maybe_constructor_name = constructor_info.constructor_tuple_node.value()->type;
auto maybe_constructor_name = constructor_info.constructor_tuple_node.value()->type;
if (maybe_constructor_name.has_value()) {
constructor_name = maybe_constructor_name.value();
} else {
constructor_name = type;
}
if (maybe_constructor_name.has_value()) {
constructor_name = maybe_constructor_name.value();
} else {
// error
constructor_name = type;
}
constructor_info.name = constructor_name;
AddConstructor(constructor_name, std::move(constructor_info), base_node);
} else {
error_handling::HandleInternalError("Unexprected VariantType constructor node type",
"GlobalInfo.NamespaceVisitor.AddType");
}
constructor_info.name = constructor_name;
AddConstructor(constructor_name, std::move(constructor_info), base_node);
}
} else if (std::holds_alternative<std::unique_ptr<interpreter::tokens::TupleType>>(*any_type_info.value)) {
definition::Constructor constructor_info;
constructor_info.type_id = id;
// constructor_info.order = std::nullopt;
constructor_info.name = type;
constructor_info.constructor_tuple_node = std::get<std::unique_ptr<interpreter::tokens::TupleType>>(*any_type_info.value).get();
AddConstructor(type, std::move(constructor_info), base_node);
} else {
// TODO: constructors for function types (??), array types (??), ...
error_handling::HandleInternalError("Not VariantType constructor search is not implemented yet",
"GlobalInfo.NamespaceVisitor.AddType");
}
return id;