2023-04-29 18:42:30 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <variant>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
// for clangd
|
2023-05-07 19:52:35 +03:00
|
|
|
#include "interpreter_tree.hpp"
|
2023-04-29 18:42:30 +03:00
|
|
|
#include "utils.hpp"
|
|
|
|
|
|
|
|
|
|
namespace interpreter {
|
|
|
|
|
class Node;
|
|
|
|
|
} // namespace interpreter
|
|
|
|
|
|
|
|
|
|
namespace info::definition {
|
|
|
|
|
|
2023-05-04 16:11:25 +03:00
|
|
|
struct Namespace;
|
|
|
|
|
|
2023-04-29 18:42:30 +03:00
|
|
|
struct TypeUsage {
|
|
|
|
|
interpreter::tokens::TypeExpression* node;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Parameter {
|
|
|
|
|
std::string type;
|
2023-05-03 15:03:57 +03:00
|
|
|
std::vector<interpreter::tokens::ParametrizedTypeclass*> typeclass_nodes;
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AbstractType {
|
2023-05-05 16:35:13 +03:00
|
|
|
utils::AbstractTypeModifier modifier;
|
2023-04-29 18:42:30 +03:00
|
|
|
Parameter type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AliasType {
|
2023-05-05 16:35:13 +03:00
|
|
|
utils::AliasModifier modifier;
|
2023-04-29 18:42:30 +03:00
|
|
|
std::vector<std::string> parameters;
|
|
|
|
|
TypeUsage value;
|
|
|
|
|
interpreter::tokens::AliasDefinitionStatement* node = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct AnyType {
|
|
|
|
|
Parameter type;
|
|
|
|
|
std::vector<Parameter> parameters;
|
|
|
|
|
interpreter::tokens::AnyType* value;
|
2023-05-04 16:11:25 +03:00
|
|
|
|
|
|
|
|
Namespace* parent_namespace = nullptr;
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Type {
|
2023-05-02 15:18:08 +03:00
|
|
|
std::variant<AliasType, AnyType> type;
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Constructor {
|
|
|
|
|
std::string name;
|
|
|
|
|
size_t order;
|
|
|
|
|
utils::IdType type_id;
|
2023-05-04 16:11:25 +03:00
|
|
|
std::optional<interpreter::tokens::TupleType*> constructor_tuple_node;
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct FunctionDeclaration {
|
|
|
|
|
std::vector<Parameter> parameters;
|
|
|
|
|
std::vector<interpreter::tokens::AnyType*> argument_types;
|
|
|
|
|
interpreter::tokens::FunctionDeclaration* node = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct FunctionDefinition {
|
|
|
|
|
std::vector<std::string> argument_names;
|
|
|
|
|
interpreter::tokens::FunctionDefinitionStatement* node = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Function {
|
|
|
|
|
size_t argument_count = 0;
|
|
|
|
|
std::optional<FunctionDeclaration> declaration;
|
|
|
|
|
std::optional<FunctionDefinition> definition;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Typeclass {
|
|
|
|
|
std::vector<Parameter> parameters;
|
2023-05-13 16:14:02 +03:00
|
|
|
std::vector<FunctionDeclaration> function_requirements;
|
|
|
|
|
std::vector<FunctionDeclaration> method_requirements;
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Import {
|
|
|
|
|
std::string module_name;
|
|
|
|
|
std::vector<std::string> symbols; // size = 0 => all symbols imported
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Namespace {
|
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> types;
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> functions;
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> constructors;
|
|
|
|
|
std::unordered_map<std::string, Namespace> namespaces;
|
2023-05-05 16:35:13 +03:00
|
|
|
std::unordered_map<std::string, Namespace> var_namespaces;
|
|
|
|
|
std::unordered_map<std::string, Namespace> const_namespaces;
|
2023-04-29 18:42:30 +03:00
|
|
|
|
2023-05-04 16:11:25 +03:00
|
|
|
Namespace* parent_namespace = nullptr;
|
2023-05-02 16:51:47 +03:00
|
|
|
|
2023-05-05 16:35:13 +03:00
|
|
|
std::optional<utils::IsConstModifier> modifier; // modifier => variable namespace
|
2023-04-29 18:42:30 +03:00
|
|
|
std::string type_name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace info::definition
|