2023-04-07 12:13:31 +03:00
|
|
|
// for clangd
|
|
|
|
|
#include "../include/find_symbols_visitor.hpp"
|
|
|
|
|
|
|
|
|
|
namespace interpreter {
|
|
|
|
|
|
|
|
|
|
// Sources -----------------
|
|
|
|
|
void FindSymbolsVisitor::Visit(SourceFile* node) {
|
|
|
|
|
for (auto& statement : node->statements) {
|
|
|
|
|
if (std::holds_alternative<Partition>(statement)) {
|
|
|
|
|
Visit(&std::get<Partition>(statement));
|
|
|
|
|
} else if (std::holds_alternative<SourceStatement>(statement)) {
|
|
|
|
|
Visitor::Visit(std::get<SourceStatement>(statement));
|
|
|
|
|
} else {
|
|
|
|
|
// error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(Sources* node) {
|
|
|
|
|
for (auto& statement : node->statements) {
|
|
|
|
|
Visitor::Visit(statement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Namespaces, partitions -----------------
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(Partition* node) {
|
|
|
|
|
// TODO
|
|
|
|
|
Visit(node->scope.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(Namespace* node) {
|
|
|
|
|
if (std::holds_alternative<std::unique_ptr<DefinedAnnotatedName>>(node->name)) {
|
|
|
|
|
Visit(std::get<std::unique_ptr<DefinedAnnotatedName>>(node->name).get());
|
|
|
|
|
auto info = std::move(std::any_cast<std::pair<std::string, std::string>>(current_info_));
|
|
|
|
|
global_info_.AddEnterNamespace(info.first, info.second);
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
} else if (std::holds_alternative<std::unique_ptr<DefinedType>>(node->name)) {
|
|
|
|
|
Visit(std::get<std::unique_ptr<DefinedType>>(node->name).get());
|
|
|
|
|
auto info = std::move(std::any_cast<std::string>(current_info_));
|
|
|
|
|
global_info_.AddEnterNamespace(std::nullopt, info);
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
} else {
|
|
|
|
|
// error
|
|
|
|
|
}
|
|
|
|
|
Visit(node->scope.get());
|
|
|
|
|
global_info_.ExitNamespace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Definitions -----------------
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(ImportStatement* node) {
|
|
|
|
|
info::ImportInfo info;
|
|
|
|
|
info.module_name = node->module_name;
|
|
|
|
|
for (auto& symbol : node->symbols) {
|
|
|
|
|
Visitor::Visit(symbol);
|
2023-04-08 15:06:51 +03:00
|
|
|
info.symbols.push_back(std::move(std::any_cast<std::string>(current_info_))); // TODO: expressions
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
global_info_.AddImport(std::move(info));
|
|
|
|
|
// TODO: what if inside usage definition, global_info_.AddImport(std::move(info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(UsageDefinition* node) {
|
|
|
|
|
global_info_.AddUsageForNextImport(node->name);
|
|
|
|
|
Visit(node->import_statement.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <-- current position
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(AliasDefinition* node) {
|
|
|
|
|
info::TypeInfo info;
|
|
|
|
|
|
|
|
|
|
Visit(node->type.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto type_info = std::move(
|
|
|
|
|
std::any_cast<std::pair<std::string, std::vector<std::string>>>(current_info_));
|
2023-04-07 12:13:31 +03:00
|
|
|
current_info_.reset();
|
|
|
|
|
|
|
|
|
|
Visit(node->value.get());
|
|
|
|
|
auto value_info = std::move(std::any_cast<info::TypeUsageInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
|
|
|
|
|
info::AliasTypeInfo alias_info;
|
|
|
|
|
alias_info.isAnotherType = false;
|
|
|
|
|
alias_info.params = std::move(type_info.second);
|
|
|
|
|
alias_info.value = std::move(value_info);
|
|
|
|
|
info.type = std::move(alias_info);
|
|
|
|
|
|
|
|
|
|
global_info_.AddType(type_info.first, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// void FindSymbolsVisitor::Visit(VariableDefinition* node) { // TODO: decide
|
|
|
|
|
// out_ << "(Variable " << (node->is_const ? "const" : "var") << ' ';
|
|
|
|
|
// Visit(&node->name);
|
|
|
|
|
// out_ << " = ";
|
|
|
|
|
// Visitor::Visit(node->value);
|
|
|
|
|
// out_ << ")\n";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(FunctionDeclaration* node) {
|
|
|
|
|
info::FunctionDeclarationInfo info;
|
|
|
|
|
for (auto& parameter : node->parameters) {
|
|
|
|
|
Visit(parameter.get());
|
|
|
|
|
auto param_info = std::move(std::any_cast<info::ParameterInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.params.push_back(std::move(param_info));
|
|
|
|
|
}
|
|
|
|
|
for (auto& argument_type : node->argument_types) {
|
|
|
|
|
Visitor::Visit(argument_type);
|
|
|
|
|
auto type_info = std::move(std::any_cast<info::TypeUsageInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.arg_types.push_back(std::move(type_info));
|
|
|
|
|
}
|
|
|
|
|
global_info_.AddFunctionDeclaration(node->name, std::move(info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(FunctionDefinition* node) {
|
|
|
|
|
info::FunctionDefinitionInfo info;
|
|
|
|
|
|
|
|
|
|
Visit(node->name.get());
|
|
|
|
|
auto name_info = std::move(
|
2023-04-08 15:06:51 +03:00
|
|
|
std::any_cast<info::SymbolDefinitionInfo>(current_info_));
|
2023-04-07 12:13:31 +03:00
|
|
|
current_info_.reset();
|
|
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
info.params = std::move(name_info.params);
|
|
|
|
|
info.arg_names = std::move(name_info.arg_names);
|
2023-04-07 12:13:31 +03:00
|
|
|
info.expression = &node->value;
|
|
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
global_info_.AddFunctionDefinition(name_info.name, std::move(info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(AliasTypeDefinition* node) { // TODO: unite with AliasDefinition
|
|
|
|
|
info::TypeInfo info;
|
|
|
|
|
|
|
|
|
|
Visit(node->type.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto type_info = std::move(
|
|
|
|
|
std::any_cast<std::pair<std::string, std::vector<std::string>>>(current_info_));
|
2023-04-07 12:13:31 +03:00
|
|
|
current_info_.reset();
|
|
|
|
|
|
|
|
|
|
Visit(node->value.get());
|
|
|
|
|
auto value_info = std::move(std::any_cast<info::TypeUsageInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
|
|
|
|
|
info::AliasTypeInfo alias_info;
|
|
|
|
|
alias_info.isAnotherType = true;
|
|
|
|
|
alias_info.params = std::move(type_info.second);
|
|
|
|
|
alias_info.value = std::move(value_info);
|
|
|
|
|
|
|
|
|
|
info.type = std::move(alias_info);
|
|
|
|
|
|
|
|
|
|
global_info_.AddType(type_info.first, std::move(info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(TypeDefinition* node) {
|
|
|
|
|
info::TypeInfo info;
|
|
|
|
|
|
|
|
|
|
Visit(node->type.get());
|
|
|
|
|
auto type_info = std::move(
|
2023-04-08 15:06:51 +03:00
|
|
|
std::any_cast<info::SymbolDefinitionInfo>(current_info_));
|
2023-04-07 12:13:31 +03:00
|
|
|
current_info_.reset();
|
|
|
|
|
|
|
|
|
|
Visitor::Visit(node->value);
|
2023-04-08 15:06:51 +03:00
|
|
|
auto value_info = std::move(std::any_cast<info::AnyTypeVariant>(current_info_));
|
2023-04-07 12:13:31 +03:00
|
|
|
current_info_.reset();
|
|
|
|
|
|
|
|
|
|
info::AnyTypeInfo any_type_info;
|
2023-04-08 15:06:51 +03:00
|
|
|
any_type_info.params = std::move(type_info.params);
|
|
|
|
|
any_type_info.arg_names = std::move(type_info.arg_names);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
|
|
|
|
switch (value_info.index()) {
|
|
|
|
|
case 0:
|
|
|
|
|
any_type_info.info =
|
|
|
|
|
std::make_unique<info::VariantTypeInfo>(
|
|
|
|
|
std::move(std::get<info::VariantTypeInfo>(value_info)));
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
any_type_info.info =
|
|
|
|
|
std::make_unique<info::TupleTypeInfo>(
|
|
|
|
|
std::move(std::get<info::TupleTypeInfo>(value_info)));
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
any_type_info.info =
|
|
|
|
|
std::make_unique<info::BuiltInTypeInfo>(
|
|
|
|
|
std::move(std::get<info::BuiltInTypeInfo>(value_info)));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// error
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.type = std::move(any_type_info);
|
|
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
global_info_.AddType(type_info.name, std::move(info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(TypeclassDefinition* node) {
|
|
|
|
|
info::TypeclassInfo info;
|
|
|
|
|
|
|
|
|
|
Visit(node->typeclass.get());
|
|
|
|
|
auto typeclass_info = std::move(
|
2023-04-08 15:06:51 +03:00
|
|
|
std::any_cast<info::SymbolDefinitionInfo>(current_info_));
|
2023-04-07 12:13:31 +03:00
|
|
|
current_info_.reset();
|
2023-04-08 15:06:51 +03:00
|
|
|
info.params = std::move(typeclass_info.params);
|
|
|
|
|
info.arg_names = std::move(typeclass_info.arg_names);
|
2023-04-07 12:13:31 +03:00
|
|
|
|
|
|
|
|
for (auto& requirement : node->requirements) {
|
|
|
|
|
Visit(requirement.get());
|
|
|
|
|
auto requrement_info = std::move(std::any_cast<info::FunctionDeclarationInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.requirements.push_back(std::move(requrement_info));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
global_info_.AddTypeclass(typeclass_info.name, std::move(info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Definition parts
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(DefinedName* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info::SymbolDefinitionInfo info;
|
|
|
|
|
|
|
|
|
|
info.name = node->name;
|
2023-04-07 12:13:31 +03:00
|
|
|
for (auto& parameter : node->parameters) {
|
|
|
|
|
Visit(parameter.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto param_info = std::move(std::any_cast<info::ParameterInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.params.push_back(std::move(param_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
for (auto& argument : node->arguments) {
|
|
|
|
|
Visit(argument.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto argument_info = std::move(std::any_cast<std::string>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.arg_names.push_back(std::move(argument_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
2023-04-08 15:06:51 +03:00
|
|
|
|
|
|
|
|
current_info_ = std::move(info);
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
void FindSymbolsVisitor::Visit(DefinedAnnotatedName* node) { // TODO: remove
|
|
|
|
|
// Visit(&node->name);
|
2023-04-07 12:13:31 +03:00
|
|
|
if (std::holds_alternative<std::unique_ptr<DefinedType>>(node->type)) {
|
|
|
|
|
Visit(std::get<std::unique_ptr<DefinedType>>(node->type).get());
|
|
|
|
|
} else if (std::holds_alternative<std::unique_ptr<DefinedTypeclass>>(node->type)) {
|
|
|
|
|
Visit(std::get<std::unique_ptr<DefinedTypeclass>>(node->type).get());
|
|
|
|
|
} else {
|
|
|
|
|
// no annotation
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(DefinedType* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info::SymbolDefinitionInfo info;
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
Visit(node->type.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
info.name = /*...*/; // TODO
|
2023-04-07 12:13:31 +03:00
|
|
|
for (auto& parameter : node->parameters) {
|
|
|
|
|
Visit(parameter.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto param_info = std::move(std::any_cast<info::ParameterInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.params.push_back(std::move(param_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
for (auto& argument : node->arguments) {
|
|
|
|
|
Visit(argument.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto argument_info = std::move(std::any_cast<std::string>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.arg_names.push_back(std::move(argument_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
2023-04-08 15:06:51 +03:00
|
|
|
|
|
|
|
|
current_info_ = std::move(info);
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(DefinedTypeclass* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info::SymbolDefinitionInfo info;
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
Visit(node->typeclass.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
info.name = /*...*/; // TODO
|
2023-04-07 12:13:31 +03:00
|
|
|
for (auto& parameter : node->parameters) {
|
|
|
|
|
Visit(parameter.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto param_info = std::move(std::any_cast<info::ParameterInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.params.push_back(std::move(param_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
for (auto& argument : node->arguments) {
|
|
|
|
|
Visit(argument.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto argument_info = std::move(std::any_cast<std::string>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.arg_names.push_back(std::move(argument_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
2023-04-08 15:06:51 +03:00
|
|
|
|
|
|
|
|
current_info_ = std::move(info);
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(DefinitionParameter* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info::ParameterInfo info;
|
|
|
|
|
|
|
|
|
|
info.name = node->type;
|
2023-04-07 12:13:31 +03:00
|
|
|
for (auto& typeclass : node->typeclasses) {
|
|
|
|
|
Visit(typeclass.get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto typeclass_info = std::move(std::any_cast</*...*/>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.param_names.push_back(std::move(typeclass_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
2023-04-08 15:06:51 +03:00
|
|
|
|
|
|
|
|
current_info_ = std::move(info);
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(DefinitionArgument* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
std::string info; // TODO: add type
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
info = node->name;
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
// for (auto& type : node->types) {
|
|
|
|
|
// Visit(type.get());
|
|
|
|
|
// auto argument_info = std::move(std::any_cast<std::string>(current_info_));
|
|
|
|
|
// current_info_.reset();
|
|
|
|
|
// info.types.push_back(std::move(argument_info));
|
|
|
|
|
// }
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
current_info_ = std::move(info);
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
// Statements, expressions, blocks, etc. -----------------
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
// Name
|
2023-04-07 12:13:31 +03:00
|
|
|
|
2023-04-08 15:06:51 +03:00
|
|
|
// void FindSymbolsVisitor::Visit(NameSuperExpression* node) {
|
|
|
|
|
// for (auto& variable_namespace : node->namespaces) {
|
|
|
|
|
// Visitor::Visit(variable_namespace);
|
|
|
|
|
// }
|
|
|
|
|
// for (size_t i = 0; i < node->expressions.size(); ++i) {
|
|
|
|
|
// Visitor::Visit(node->expressions[i]);
|
|
|
|
|
// if (i + 1 < node->expressions.size()) {
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// void FindSymbolsVisitor::Visit(NameExpression* node) {
|
|
|
|
|
// for (auto& variable_namespace : node->namespaces) {
|
|
|
|
|
// Visitor::Visit(variable_namespace);
|
|
|
|
|
// }
|
|
|
|
|
// for (size_t i = 0; i < node->names.size(); ++i) {
|
|
|
|
|
// Visit(&node->names[i]);
|
|
|
|
|
// if (i + 1 < node->names.size()) {
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// void FindSymbolsVisitor::Visit(TupleName* node) {
|
|
|
|
|
// for (auto& name : node->names) {
|
|
|
|
|
// Visit(name.get());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// void FindSymbolsVisitor::Visit(VariantName* node) {
|
|
|
|
|
// for (auto& name : node->names) {
|
|
|
|
|
// Visit(name.get());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// void FindSymbolsVisitor::Visit(AnnotatedName* node) {
|
|
|
|
|
// Visit(&node->name);
|
|
|
|
|
// if (node->type.has_value()) {
|
|
|
|
|
// Visit(node->type.value().get());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-04-07 12:13:31 +03:00
|
|
|
|
|
|
|
|
// Type
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(TupleType* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info::TupleTypeInfo info;
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
if (node->type.has_value()) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info.name = node->type.value();
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
for (auto& entity : node->entities) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info.fields.emplace_back();
|
2023-04-07 12:13:31 +03:00
|
|
|
if (entity.first.has_value()) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info.fields.back().first = entity.first.value();
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
Visitor::Visit(entity.second);
|
2023-04-08 15:06:51 +03:00
|
|
|
auto entity_type_info = std::move(std::any_cast<info::AnyTypeInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.fields.back().second = std::move(entity_type_info);
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
2023-04-08 15:06:51 +03:00
|
|
|
|
|
|
|
|
current_info_ = info::AnyTypeVariant(std::move(info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(VariantType* node) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info::VariantTypeInfo info;
|
|
|
|
|
|
2023-04-07 12:13:31 +03:00
|
|
|
if (node->type.has_value()) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info.name = node->type.value();ParametrizedType
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
for (auto& constructor : node->constructors) {
|
|
|
|
|
if (std::holds_alternative<TypeIdentifierDefinition>(constructor)) {
|
2023-04-08 15:06:51 +03:00
|
|
|
info.constructors.push_back(std::get<TypeIdentifierDefinition>(constructor));
|
2023-04-07 12:13:31 +03:00
|
|
|
} else if (std::holds_alternative<std::unique_ptr<TupleType>>(constructor)) {
|
|
|
|
|
Visit(std::get<std::unique_ptr<TupleType>>(constructor).get());
|
2023-04-08 15:06:51 +03:00
|
|
|
auto constructor_tuple_info = std::move(std::any_cast<info::TupleTypeInfo>(current_info_));
|
|
|
|
|
current_info_.reset();
|
|
|
|
|
info.constructors.push_back(std::move(constructor_tuple_info));
|
2023-04-07 12:13:31 +03:00
|
|
|
} else {
|
|
|
|
|
// error
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-08 15:06:51 +03:00
|
|
|
|
|
|
|
|
current_info_ = info::AnyTypeVariant(std::move(info));
|
2023-04-07 12:13:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(AnnotatedType* node) {
|
|
|
|
|
Visit(node->type_expression.get());
|
|
|
|
|
if (!node->annotations.empty()) {
|
|
|
|
|
}
|
|
|
|
|
for (auto& annotation : node->annotations) {
|
|
|
|
|
Visit(annotation.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(ParametrizedType* node) {
|
|
|
|
|
Visit(node->type_expression.get());
|
|
|
|
|
for (auto& parameter : node->parameters) {
|
|
|
|
|
Visitor::Visit(parameter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(TypeExpression* node) {
|
|
|
|
|
for (auto& type_namespace : node->namespaces) {
|
|
|
|
|
Visitor::Visit(type_namespace);
|
|
|
|
|
}
|
|
|
|
|
Visit(&node->type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Typeclass
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(AnnotatedTypeclass* node) {
|
|
|
|
|
Visit(node->typeclass_expression.get());
|
|
|
|
|
if (!node->annotations.empty()) {
|
|
|
|
|
}
|
|
|
|
|
for (auto& annotation : node->annotations) {
|
|
|
|
|
Visit(annotation.get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(ParametrizedTypeclass* node) {
|
|
|
|
|
Visit(node->typeclass_expression.get());
|
|
|
|
|
for (auto& paramater : node->parameters) {
|
|
|
|
|
Visitor::Visit(paramater);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindSymbolsVisitor::Visit(TypeclassExpression* node) {
|
|
|
|
|
for (auto& typeclass_namespace : node->namespaces) {
|
|
|
|
|
Visitor::Visit(typeclass_namespace);
|
|
|
|
|
}
|
|
|
|
|
Visit(&node->typeclass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace interpreter
|