part of find_symbols_visitor done

This commit is contained in:
ProgramSnail 2023-04-07 12:13:31 +03:00
parent f88a23194f
commit 18e85f794f
6 changed files with 827 additions and 57 deletions

View file

@ -1,10 +1,12 @@
#pragma once
#include "interpreter_tree.hpp"
#include <string>
#include <variant>
#include <optional>
#include <vector>
#include <optional>
#include <unordered_map>
#include <memory>
// for clangd
@ -34,63 +36,110 @@ struct Value {
};
// better variant value storage (then string) ??
struct Info {
std::string name;
};
struct VariantTypeInfo;
struct TupleTypeInfo;
struct AliasTypeInfo;
struct TypeInfo;
struct TypeclassInfo;
enum class BuiltInTypeInfo {
StringT,
IntT,
FloatT,
};
using TypeInfo = std::variant<VariantTypeInfo, TupleTypeInfo, AliasTypeInfo, BuiltInTypeInfo>;
struct TypeUsageInfo {
std::vector<std::string> param_names;
std::vector<TypeInfo*> param_types;
std::vector<std::string> arg_names; // ??, arg expr ??
};
struct VariableInfo : public Info {
Value value;
struct ParameterInfo {
std::string name;
std::vector<std::string> param_names;
std::vector<TypeclassInfo*> param_types;
std::vector<std::string> arg_names; // ??
};
struct AnyTypeInfo {
std::vector<ParameterInfo> params; // ??
std::vector<std::string> arg_names;
std::variant<std::unique_ptr<VariantTypeInfo>,
std::unique_ptr<TupleTypeInfo>,
std::unique_ptr<BuiltInTypeInfo>> info;
};
struct VariableInfo {
std::string name;
std::optional<Value> value;
TypeInfo* type = nullptr;
};
// TODO lambda functions as values
// TODO aliases ??
struct TupleTypeInfo : public Info {
std::vector<std::pair<std::optional<std::string>, TypeInfo>> fields;
struct TupleTypeInfo {
std::optional<std::string> name;
std::vector<std::pair<std::optional<std::string>, AnyTypeInfo>> fields;
};
struct VariantTypeInfo : public Info {
struct VariantTypeInfo {
std::optional<std::string> name;
std::vector<std::variant<std::string, TupleTypeInfo>> constructors;
// ?? any type instead of tuple type ??
};
struct AliasTypeInfo : public Info {
bool isAnotherType; // = true by default ??
TypeInfo* type = nullptr;
struct AliasTypeInfo {
std::vector<std::string> params;
bool isAnotherType;
TypeUsageInfo value;
};
struct TypeclassInfo : public Info {
// TODO
struct TypeInfo { std::variant<AliasTypeInfo, AnyTypeInfo> type; };
// struct PointerInfo { // ??
// VariableInfo* variable;
// };
struct FunctionDeclarationInfo {
std::vector<ParameterInfo> params;
std::vector<TypeUsageInfo> arg_types;
};
struct PointerInfo {
VariableInfo* variable;
struct FunctionDefinitionInfo {
std::vector<ParameterInfo> params; // TODO: dublicates ??
std::vector<std::string> arg_names;
interpreter::tokens::SuperExpression* expression;
};
struct FunctionInfo : public Info {
interpreter::Node* definition;
std::vector<VariableInfo> args;
struct FunctionInfo {
FunctionDeclarationInfo declaration;
FunctionDefinitionInfo definition;
// add requirements ??
};
struct NamespaceInfo : public Info {
struct TypeclassInfo {
std::vector<ParameterInfo> params;
std::vector<std::string> arg_names;
std::vector<FunctionDeclarationInfo> requirements;
};
struct ImportInfo {
std::string module_name;
std::vector<std::string> symbols;
};
struct NamespaceInfo {
std::unordered_map<std::string, TypeInfo> types;
std::unordered_map<std::string, VariableInfo> variables;
std::unordered_map<std::string, TypeclassInfo> typeclasses;
// std::unordered_map<std::string, VariableInfo> variables; // TODO
std::unordered_map<std::string, FunctionInfo> functions;
std::unordered_map<std::string, NamespaceInfo> namespaces;
std::unordered_map<std::string, std::vector<NamespaceInfo>> namespaces;
std::optional<std::string> var;
std::string type_name;
TypeInfo* type_info = nullptr;
};
} // namespace info