lang_2023/include/symbols_info.hpp

147 lines
3.4 KiB
C++
Raw Normal View History

2023-03-26 15:20:53 +03:00
#pragma once
2023-04-07 12:13:31 +03:00
#include "interpreter_tree.hpp"
2023-03-26 15:20:53 +03:00
#include <string>
#include <variant>
#include <vector>
2023-04-07 12:13:31 +03:00
#include <optional>
2023-03-26 15:20:53 +03:00
#include <unordered_map>
2023-04-07 12:13:31 +03:00
#include <memory>
2023-03-26 15:20:53 +03:00
// 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;
2023-04-07 12:13:31 +03:00
struct TypeInfo;
struct TypeclassInfo;
2023-03-26 15:20:53 +03:00
enum class BuiltInTypeInfo {
StringT,
IntT,
FloatT,
};
struct TypeUsageInfo { // TODO: typeclass_expression
2023-04-07 12:13:31 +03:00
std::vector<std::string> param_names;
std::vector<TypeInfo*> params;
2023-04-07 12:13:31 +03:00
std::vector<std::string> arg_names; // ??, arg expr ??
};
struct ParameterInfo {
std::string name;
std::vector<std::string> param_names; // TODO: paramaters
2023-04-07 12:13:31 +03:00
std::vector<TypeclassInfo*> param_types;
};
struct SymbolDefinitionInfo {
std::string name;
std::vector<ParameterInfo> params;
2023-04-07 12:13:31 +03:00
std::vector<std::string> arg_names;
};
2023-03-26 15:20:53 +03:00
struct AnyTypeInfo : SymbolDefinitionInfo {
2023-04-07 12:13:31 +03:00
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=
2023-03-26 15:20:53 +03:00
2023-04-07 12:13:31 +03:00
struct TupleTypeInfo {
std::optional<std::string> name;
std::vector<std::pair<std::optional<std::string>, AnyTypeInfo>> fields;
2023-03-26 15:20:53 +03:00
};
2023-04-07 12:13:31 +03:00
struct VariantTypeInfo {
std::optional<std::string> name;
2023-03-26 15:20:53 +03:00
std::vector<std::variant<std::string, TupleTypeInfo>> constructors;
// ?? any type instead of tuple type ??
};
2023-04-07 12:13:31 +03:00
struct AliasTypeInfo {
std::vector<std::string> params;
bool isAnotherType;
TypeUsageInfo value;
2023-03-26 15:20:53 +03:00
};
2023-04-07 12:13:31 +03:00
struct TypeInfo { std::variant<AliasTypeInfo, AnyTypeInfo> type; };
// struct PointerInfo { // ??
// VariableInfo* variable;
// };
struct FunctionDeclarationInfo {
std::vector<ParameterInfo> params;
std::vector<TypeUsageInfo> arg_types;
2023-03-26 15:20:53 +03:00
};
struct FunctionDefinitionInfo : SymbolDefinitionInfo {
2023-04-07 12:13:31 +03:00
interpreter::tokens::SuperExpression* expression;
2023-03-26 15:20:53 +03:00
};
2023-04-07 12:13:31 +03:00
struct FunctionInfo {
FunctionDeclarationInfo declaration;
FunctionDefinitionInfo definition;
2023-03-26 15:20:53 +03:00
};
struct TypeclassInfo : SymbolDefinitionInfo {
2023-04-07 12:13:31 +03:00
std::vector<FunctionDeclarationInfo> requirements;
};
struct ImportInfo {
std::string module_name;
std::vector<std::string> symbols;
};
struct NamespaceInfo {
2023-03-26 15:20:53 +03:00
std::unordered_map<std::string, TypeInfo> types;
2023-04-07 12:13:31 +03:00
std::unordered_map<std::string, TypeclassInfo> typeclasses;
// std::unordered_map<std::string, VariableInfo> variables; // TODO
2023-03-26 15:20:53 +03:00
std::unordered_map<std::string, FunctionInfo> functions;
2023-04-07 12:13:31 +03:00
std::unordered_map<std::string, std::vector<NamespaceInfo>> namespaces;
std::optional<std::string> var;
std::string type_name;
TypeInfo* type_info = nullptr;
2023-03-26 15:20:53 +03:00
};
using AnyTypeVariant = std::variant<VariantTypeInfo,
TupleTypeInfo,
BuiltInTypeInfo>;
2023-03-26 15:20:53 +03:00
} // namespace info