mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
113 lines
2.7 KiB
C++
113 lines
2.7 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;
|
|
|
|
interpreter::tokens::AnyAnnotatedType* node = nullptr;
|
|
};
|
|
|
|
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 = 0;
|
|
};
|
|
|
|
struct Type {
|
|
std::variant<AliasType, AnyType> type;
|
|
};
|
|
|
|
struct Constructor {
|
|
std::string name;
|
|
std::optional<size_t> order; // no order for tuple types
|
|
utils::IdType type_id = 0;
|
|
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;
|
|
interpreter::tokens::TypeclassDefinitionStatement* node;
|
|
|
|
utils::IdType parent_namespace = 0;
|
|
|
|
utils::IdType graph_id_ = 0; // TODO: make safe??
|
|
};
|
|
|
|
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 = 0;
|
|
|
|
utils::ClassInternalsModifier modifier = utils::ClassInternalsModifier::Static;
|
|
std::string type_name;
|
|
|
|
// all nodes have same info
|
|
std::optional<interpreter::tokens::Namespace*> any_node;
|
|
};
|
|
|
|
} // namespace info::definition
|