lang_2023/include/symbols_info.hpp

146 lines
3.4 KiB
C++

#pragma once
#include "interpreter_tree.hpp"
#include <string>
#include <variant>
#include <vector>
#include <optional>
#include <unordered_map>
#include <memory>
// for clangd
namespace interpreter {
class Node;
} // namespace interpreter
namespace info {
using NumberValue = long long;
using FloatNumberValue = float;
using StringValue = std::string;
struct SimpleValue {
std::variant<NumberValue, FloatNumberValue, StringValue> value;
};
struct Value {
enum class ValueStructure {
Simple, // one value
Variant, // one value from list, can have arguments
// MultiVariant, // constructed variant // ??
Tuple, // tuple of values
};
ValueStructure structure;
std::vector<std::variant<SimpleValue, Value>> values;
};
// better variant value storage (then string) ??
struct VariantTypeInfo;
struct TupleTypeInfo;
struct AliasTypeInfo;
struct TypeInfo;
struct TypeclassInfo;
enum class BuiltInTypeInfo {
StringT,
IntT,
FloatT,
};
struct TypeUsageInfo { // TODO: typeclass_expression
std::vector<std::string> param_names;
std::vector<TypeInfo*> params;
std::vector<std::string> arg_names; // ??, arg expr ??
};
struct ParameterInfo {
std::string name;
std::vector<std::string> param_names; // TODO: paramaters
std::vector<TypeclassInfo*> param_types;
};
struct SymbolDefinitionInfo {
std::string name;
std::vector<ParameterInfo> params;
std::vector<std::string> arg_names;
};
struct AnyTypeInfo : SymbolDefinitionInfo {
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 value
// TODO: decide=
struct TupleTypeInfo {
std::optional<std::string> name;
std::vector<std::pair<std::optional<std::string>, AnyTypeInfo>> fields;
};
struct VariantTypeInfo {
std::optional<std::string> name;
std::vector<std::variant<std::string, TupleTypeInfo>> constructors;
// ?? any type instead of tuple type ??
};
struct AliasTypeInfo {
std::vector<std::string> params;
bool isAnotherType;
TypeUsageInfo value;
};
struct TypeInfo { std::variant<AliasTypeInfo, AnyTypeInfo> type; };
// struct PointerInfo { // ??
// VariableInfo* variable;
// };
struct FunctionDeclarationInfo {
std::vector<ParameterInfo> params;
std::vector<TypeUsageInfo> arg_types;
};
struct FunctionDefinitionInfo : SymbolDefinitionInfo {
interpreter::tokens::SuperExpression* expression;
};
struct FunctionInfo {
FunctionDeclarationInfo declaration;
FunctionDefinitionInfo definition;
};
struct TypeclassInfo : SymbolDefinitionInfo {
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, TypeclassInfo> typeclasses;
// std::unordered_map<std::string, VariableInfo> variables; // TODO
std::unordered_map<std::string, FunctionInfo> functions;
std::unordered_map<std::string, std::vector<NamespaceInfo>> namespaces;
std::optional<std::string> var;
std::string type_name;
TypeInfo* type_info = nullptr;
};
using AnyTypeVariant = std::variant<VariantTypeInfo,
TupleTypeInfo,
BuiltInTypeInfo>;
} // namespace info