lang_2023/include/definitions.hpp
2023-05-04 16:11:25 +03:00

104 lines
2.3 KiB
C++

#pragma once
#include "interpreter_tree.hpp"
#include <string>
#include <variant>
#include <vector>
#include <optional>
#include <unordered_map>
#include <memory>
// for clangd
#include "utils.hpp"
namespace interpreter {
class Node;
} // namespace interpreter
namespace info::definition {
struct Namespace;
struct TypeUsage {
interpreter::tokens::TypeExpression* node;
};
struct Parameter {
std::string type;
std::vector<interpreter::tokens::ParametrizedTypeclass*> typeclass_nodes;
};
struct AbstractType {
enum { Basic, Abstract } modifier;
Parameter type;
};
struct AliasType {
enum {Alias, Type, Let} modifier;
std::vector<std::string> parameters;
TypeUsage value;
interpreter::tokens::AliasDefinitionStatement* node = nullptr;
};
struct AnyType {
Parameter type;
std::vector<Parameter> parameters;
interpreter::tokens::AnyType* value;
Namespace* parent_namespace = nullptr;
};
struct Type {
std::variant<AliasType, AnyType> type;
};
struct Constructor {
std::string name;
size_t order;
utils::IdType type_id;
std::optional<interpreter::tokens::TupleType*> constructor_tuple_node;
};
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;
std::vector<FunctionDeclaration> requirements;
};
struct Import {
std::string module_name;
std::vector<std::string> symbols; // size = 0 => all symbols imported
};
struct Namespace {
enum Modifier { Const, Var };
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;
std::unordered_map<std::string, Namespace> variable_namespaces;
Namespace* parent_namespace = nullptr;
std::optional<Modifier> modifier; // modifier => variable namespace
std::string type_name;
};
} // namespace info::definition