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-05-16 12:43:55 +03:00
|
|
|
|
|
|
|
|
interpreter::tokens::AnyAnnotatedType* node = nullptr;
|
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-13 18:53:54 +03:00
|
|
|
utils::ClassModifier modifier;
|
2023-05-04 16:11:25 +03:00
|
|
|
|
2023-05-17 17:57:56 +03:00
|
|
|
utils::IdType parent_namespace = 0;
|
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;
|
2023-05-17 17:57:56 +03:00
|
|
|
std::optional<size_t> order; // no order for tuple types
|
|
|
|
|
utils::IdType type_id = 0;
|
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 22:40:33 +03:00
|
|
|
interpreter::tokens::TypeclassDefinitionStatement* node;
|
2023-05-14 13:05:46 +03:00
|
|
|
|
2023-05-17 17:57:56 +03:00
|
|
|
utils::IdType parent_namespace = 0;
|
2023-05-16 12:43:55 +03:00
|
|
|
|
2023-05-17 17:57:56 +03:00
|
|
|
utils::IdType graph_id_ = 0; // TODO: make safe??
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Import {
|
|
|
|
|
std::string module_name;
|
2023-05-16 12:43:55 +03:00
|
|
|
std::vector<std::string> symbols; // size == 0 => all symbols imported
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
2023-05-13 18:53:54 +03:00
|
|
|
std::unordered_map<std::string, utils::IdType> namespaces;
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> var_namespaces;
|
|
|
|
|
std::unordered_map<std::string, utils::IdType> const_namespaces;
|
2023-04-29 18:42:30 +03:00
|
|
|
|
2023-05-17 17:57:56 +03:00
|
|
|
utils::IdType parent_namespace = 0;
|
2023-05-02 16:51:47 +03:00
|
|
|
|
2023-05-14 13:05:46 +03:00
|
|
|
utils::ClassInternalsModifier modifier = utils::ClassInternalsModifier::Static;
|
2023-04-29 18:42:30 +03:00
|
|
|
std::string type_name;
|
2023-05-14 13:05:46 +03:00
|
|
|
|
2023-05-16 12:43:55 +03:00
|
|
|
// all nodes have same info
|
|
|
|
|
std::optional<interpreter::tokens::Namespace*> any_node;
|
2023-04-29 18:42:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace info::definition
|