mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
find_symbols_visitor, global_info fixed
This commit is contained in:
parent
4d0b527416
commit
a512a92f92
9 changed files with 289 additions and 277 deletions
98
include/definitions.hpp
Normal file
98
include/definitions.hpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#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 TypeUsage {
|
||||
interpreter::tokens::TypeExpression* node;
|
||||
};
|
||||
|
||||
struct Parameter {
|
||||
std::string type;
|
||||
std::vector<interpreter::tokens::TypeclassExpression*> 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;
|
||||
};
|
||||
|
||||
struct Type {
|
||||
std::variant<AbstractType, AliasType, AnyType> type;
|
||||
};
|
||||
|
||||
struct Constructor {
|
||||
std::string name;
|
||||
size_t order;
|
||||
utils::IdType type_id;
|
||||
};
|
||||
|
||||
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> typeclasses;
|
||||
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;
|
||||
|
||||
std::optional<Modifier> modifier; // modifier => variable namespace
|
||||
std::string type_name;
|
||||
};
|
||||
|
||||
} // namespace info::definition
|
||||
Loading…
Add table
Add a link
Reference in a new issue