lang_2023/include/definitions.hpp

106 lines
2.5 KiB
C++

#pragma once
#include <string>
#include <variant>
#include <vector>
#include <optional>
#include <unordered_map>
#include <memory>
// for clangd
#include "interpreter_tree.hpp"
#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 {
utils::AbstractTypeModifier modifier;
Parameter type;
};
struct AliasType {
utils::AliasModifier 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;
utils::ClassModifier modifier;
utils::IdType parent_namespace;
};
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> function_requirements;
std::vector<FunctionDeclaration> method_requirements;
};
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, utils::IdType> namespaces;
std::unordered_map<std::string, utils::IdType> var_namespaces;
std::unordered_map<std::string, utils::IdType> const_namespaces;
utils::IdType parent_namespace;
std::optional<utils::IsConstModifier> modifier; // modifier => variable namespace
std::string type_name;
};
} // namespace info::definition